combobox: refactor w/ snippet rendering overrides & better lazy loading

This commit is contained in:
Elijah Duffy
2026-03-10 12:50:25 -07:00
parent f06867ad75
commit c4f973f1c2
2 changed files with 303 additions and 223 deletions

View File

@@ -164,16 +164,6 @@
</div>
</div>
{#snippet comboRender(item: ComboboxOption)}
Opt 1
{/snippet}
{#snippet comboInfotext(item: ComboboxOption)}
User
{/snippet}
{#snippet comboPreview(item: ComboboxOption)}
Preview {item.label}
{/snippet}
<div class="component">
<p class="title">Combobox</p>
@@ -187,17 +177,21 @@
value: 'option1',
label: 'Option 1',
preview: 'Prvw',
infotext: 'Info',
render: comboRender,
infotextRender: comboInfotext,
previewRender: comboPreview
infotext: 'Info'
},
{ value: 'option2', label: 'Option 2' },
{ value: 'option3', label: 'Option 3', disabled: true }
]}
onchange={(e) => console.log('Selected:', e.value)}
onvalidate={(e) => console.log('Validation:', e.detail)}
/>
>
{#snippet labelRender(opt: ComboboxOption)}
Processed {opt.label}
{/snippet}
{#snippet infotextRender(opt: ComboboxOption)}
Processed {opt.infotext}
{/snippet}
</Combobox>
<Combobox
loading
@@ -223,15 +217,17 @@
label="Lazy combobox"
placeholder="Choose..."
options={lazyOptions}
lazy
onlazy={() => {
setTimeout(() => {
lazyOptions = [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' },
{ value: 'option3', label: 'Option 3' }
];
}, 2500);
lazy={'always'}
onlazy={async () => {
await new Promise((resolve) => setTimeout(resolve, 2500));
lazyOptions = [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' },
{ value: 'option3', label: 'Option 3' }
];
}}
onopenchange={(open) => {
if (!open) lazyOptions = [];
}}
/>
<Combobox