Skip to content

Commit

Permalink
[TextField] Support passing slots prop as override for $$slots. Worka…
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Oct 6, 2021
1 parent 08b473f commit 8af7746
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/lib/components/SelectField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
on:keypress={onKeyPress}
actions={(node) => [selectOnFocus(node)]}
class="h-full"
slots={$$slots}
{...$$restProps}
>
<slot slot="prepend" name="prepend" />
Expand Down
17 changes: 12 additions & 5 deletions src/lib/components/TextField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@
$: hasInputValue = inputValue != null && inputValue !== '';
$: hasLabel = label !== '';
$: hasPrepend = $$slots.prepend || icon != null;
$: hasAppend = $$slots.append || clearable || error || operators;
$: hasPrefix = $$slots.prefix || type === 'currency';
$: hasSuffix = $$slots.suffix || type === 'percent';
/**
* Support overriding $$slots (workaround for https://github.com/sveltejs/svelte/issues/6059)
*/
export let slots: typeof $$slots;
$: hasPrepend = (slots ? slots.prepend : $$slots.prepend) || icon != null;
$: hasAppend = (slots ? slots.append : $$slots.append) || clearable || error || operators;
$: hasPrefix = (slots ? slots.prefix : $$slots.prefix) || type === 'currency';
$: hasSuffix = (slots ? slots.suffix : $$slots.suffix) || type === 'percent';
$: hStackTemplate = `${hasPrepend ? 'auto' : ''} 1fr ${hasAppend ? ' auto' : ''}`;
Expand Down Expand Up @@ -133,7 +138,9 @@
<slot name="prepend" />

{#if icon}
<span class={clsx('mr-3', rounded && !$$slots.prepend && 'ml-3')}>
<span
class={clsx('mr-3', rounded && !(slots ? slots.prepend : $$slots.prepend) && 'ml-3')}
>
<Icon path={icon} class="text-black/50" />
</span>
{/if}
Expand Down
6 changes: 6 additions & 0 deletions src/routes/docs/components/SelectField.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
<SelectField {items} icon={mdiMagnify} />
</Preview>

## Rounded w/ icon

<Preview>
<SelectField {items} icon={mdiMagnify} rounded />
</Preview>

## Search

<Preview>
Expand Down

0 comments on commit 8af7746

Please sign in to comment.