Skip to content

Commit

Permalink
[SelectField] Rename clearSearchOnFocus to clearSearchOnOpen to o…
Browse files Browse the repository at this point in the history
…pen on up/down key input, and default to `true`
  • Loading branch information
techniq committed Aug 16, 2023
1 parent cd53e86 commit 7b364ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-plants-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': minor
---

[SelectField] Rename `clearSearchOnFocus` to `clearSearchOnOpen` to open on up/down key input, and default to `true`
11 changes: 4 additions & 7 deletions src/lib/components/SelectField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
export let base = false;
export let rounded = false;
export let dense = false;
export let clearSearchOnFocus = false;
export let clearSearchOnOpen = true;
export let classes: {
root?: string;
Expand Down Expand Up @@ -184,9 +184,6 @@
function onFocus() {
logger.debug('onFocus');
if (clearSearchOnFocus) {
searchText = ''; // Show all options on focus
}
show();
}
Expand Down Expand Up @@ -257,16 +254,16 @@
function onClick() {
logger.debug('onClick');
if (clearSearchOnFocus) {
searchText = ''; // Show all options on focus
}
show();
}
function show() {
logger.debug('show');
if (!disabled && !readonly) {
if (open === false && clearSearchOnOpen) {
searchText = ''; // Show all options on open
}
open = true;
inputEl?.focus();
}
Expand Down
14 changes: 7 additions & 7 deletions src/routes/docs/components/SelectField/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@
<Button on:click={() => (value = 4)}>Pick 4</Button>
</Preview>

<h2>clearSearchOnFocus</h2>
<h2>clearable=false</h2>

<Preview>
<SelectField {options} bind:value clearSearchOnFocus />
<SelectField {options} bind:value clearable={false} />
</Preview>

<h2>clearable=false</h2>
<h2>clearSearchOnFocus=false</h2>

<Preview>
<SelectField {options} bind:value clearSearchOnFocus clearable={false} />
<SelectField {options} bind:value clearSearchOnOpen={false} />
</Preview>

<h2>Grouped options</h2>
Expand All @@ -82,14 +82,14 @@
<h2>Many options</h2>

<Preview>
<SelectField options={manyOptions} clearSearchOnFocus />
<SelectField options={manyOptions} clearSearchOnOpen />
</Preview>

<h2>Update options</h2>

<Preview>
<Toggle let:on let:toggle>
<SelectField options={on ? newOptions : options} bind:value clearSearchOnFocus />
<SelectField options={on ? newOptions : options} bind:value clearSearchOnOpen />
<Button on:click={toggle}>Toggle Options</Button>
</Toggle>
</Preview>
Expand Down Expand Up @@ -293,7 +293,7 @@
<SelectField
{options}
bind:value
clearSearchOnFocus
clearSearchOnOpen
classes={{ selected: 'bg-accent-500 text-white' }}
/>
</Preview>
Expand Down

1 comment on commit 7b364ea

@vercel
Copy link

@vercel vercel bot commented on 7b364ea Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.