profile
viewpoint

Ask questionsA way to see if slot prop is present

v3.0.0-beta.5

Before #2083 it was possible to check if slot prop is present

<svelte:options bind:props/>
<div>
	{#if props.$$slot_icon}
		<div class="Input-Icon">
			<slot name="icon"></slot>
		</div>
	{/if}
</div>

An option to see if a slot prop is preset would be nice to have.

sveltejs/svelte

Answer questions evanleck

Maybe $$slots like $$props? My use case is that I'd like to wrap a slot's content in an element that applies styling that I'd like absent without the slotted content. Something like this:

{#if $$slots.description}
  <div class="description">
    <slot name="description"></slot>
  </div>
{/if}
useful!

Related questions

Javascript Interpolation in Styles via CSS Variables? hot 2
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Uncaught TypeError: y.fragment.l is not a function hot 1
Increase elements when using a combination of await block and transition hot 1
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Change body class via &lt;svelte:body /&gt; hot 1
Site: Svelte Cookbook/ Examples hot 1
Missing dependencies in svelte/compiler type definitions hot 1
Multiple components in one file - svelte hot 1
onMount Error: Function called outside component initialization hot 1
slot inside #if inside #each : TypeError cannot read property 'd' of null hot 1
unclear / difficult to import uuidv4 hot 1
Use <script type="application/ld+json"> in <svelte:head> hot 1
Error: 'default' is not exported when using babel + moment hot 1
Outros undefined when transitioning to another page hot 1
Github User Rank List