Skip to content

[MultiSelect] Add autoFocusSearch to opt into functionality, which MultiSelectMenu maintains #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-beers-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-ux": patch
---

[MultiSelect] Add `autoFocusSearch` to opt into functionality, which `MultiSelectMenu` maintains
13 changes: 9 additions & 4 deletions packages/svelte-ux/src/lib/actions/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import type { Action } from 'svelte/action';
/**
* Auto focus node when rendered. Useful for inputs
*/
export function autoFocus(node: HTMLElement | SVGElement, options?: { delay?: number }) {
export function autoFocus(
node: HTMLElement | SVGElement,
options?: { delay?: number; disabled?: boolean }
) {
// TODO: Add options to "restoreFocus" on destroy()
// const elementFocused = document.activeElement as HTMLElement;
setTimeout(() => {
node.focus();
}, options?.delay ?? 0);
if (options?.disabled !== true) {
setTimeout(() => {
node.focus();
}, options?.delay ?? 0);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte-ux/src/lib/components/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
export let indeterminateSelected: string[] = [];
export let duration = 200;
export let inlineSearch = false;
export let autoFocusSearch = false;
export let placeholder = 'Search items';

/** Wrap options in `InfiniteScroll` to amortize rendering of a large number of options */
Expand Down Expand Up @@ -116,7 +117,7 @@
{placeholder}
iconRight={mdiMagnify}
bind:value={searchText}
autofocus={{ delay: 100 }}
autofocus={{ delay: 100, disabled: !autoFocusSearch }}
/>
</div>
{/if}
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte-ux/src/lib/components/MultiSelectMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
export let placement: Placement = 'bottom-start';
export let autoPlacement = true;
export let inlineSearch = false;
export let autoFocusSearch = inlineSearch;
export let placeholder: string | undefined = undefined;
export let infiniteScroll = false;
export let searchText = '';
Expand Down Expand Up @@ -59,6 +60,7 @@
{open}
{duration}
{inlineSearch}
{autoFocusSearch}
{placeholder}
{infiniteScroll}
{labelProp}
Expand Down