diff --git a/docs/src/lib/components/demos/combobox-demo.svelte b/docs/src/lib/components/demos/combobox-demo.svelte index 1284b442f..4a6abe538 100644 --- a/docs/src/lib/components/demos/combobox-demo.svelte +++ b/docs/src/lib/components/demos/combobox-demo.svelte @@ -61,16 +61,16 @@ - + {#each filteredFruits as fruit, i (i + fruit.value)} @@ -89,7 +89,7 @@ {/each} - + diff --git a/docs/src/lib/components/demos/select-demo-custom.svelte b/docs/src/lib/components/demos/select-demo-custom.svelte index 6d8b96a2e..ff8ecbf67 100644 --- a/docs/src/lib/components/demos/select-demo-custom.svelte +++ b/docs/src/lib/components/demos/select-demo-custom.svelte @@ -51,14 +51,14 @@ - + {#each themes as theme, i (i + theme.value)} @@ -51,13 +51,13 @@ - + {#each themes as theme, i (i + theme.value)} @@ -58,7 +58,7 @@ - + {#each themes as theme, i (i + theme.value)} (value = v)}> @@ -46,13 +46,13 @@ - + {#each themes as theme, i (i + theme.value)} { - // const activeItem = this.root.highlightedNode; - // console.log("scrolling into view"); - // activeItem?.scrollIntoView({ block: "nearest" }); - // }); }); $effect(() => { @@ -1195,6 +1190,7 @@ class SelectScrollDownButtonState { content: SelectContentState; root: SelectBaseRootState; canScrollDown = $state(false); + scrollIntoViewTimer: ReturnType | null = null; constructor(readonly state: SelectScrollButtonImplState) { this.content = state.content; @@ -1210,6 +1206,20 @@ class SelectScrollDownButtonState { return on(this.content.viewportNode, "scroll", () => this.handleScroll()); }); + + watch( + () => this.state.mounted, + () => { + if (!this.state.mounted) return; + if (this.scrollIntoViewTimer) { + clearTimeout(this.scrollIntoViewTimer); + } + this.scrollIntoViewTimer = afterSleep(5, () => { + const activeItem = this.root.highlightedNode; + activeItem?.scrollIntoView({ block: "nearest" }); + }); + } + ); } /** * @param manual - if true, it means the function was invoked manually outside of an event