Skip to content

Commit

Permalink
Support setting disabled for MenuOption (MenuButton, MenuField, Sel…
Browse files Browse the repository at this point in the history
…ectField)
  • Loading branch information
techniq committed Jul 15, 2024
1 parent 3f502f1 commit 19ca5a6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-houses-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

Support setting `disabled` for MenuOption (MenuButton, MenuField, SelectField)
1 change: 1 addition & 0 deletions packages/svelte-ux/src/lib/components/MenuButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
value = option.value;
dispatch('change', { option, value });
}}
disabled={option.disabled}
>
{option.label}
</MenuItem>
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-ux/src/lib/components/MenuField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
selected={option.value === value}
class={cls(option.group ? 'px-4' : 'px-2', settingsClasses.option, classes.option)}
classes={classes.menuItem}
disabled={option.disabled}
on:click={() => (value = option.value)}
>
{option.label}
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte-ux/src/lib/components/SelectField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@
}}
role="option"
aria-selected={option === selected ? 'true' : 'false'}
aria-disabled={option?.disabled ? 'true' : 'false'}
disabled={option.disabled}
>
{option.label}
</MenuItem>
Expand Down Expand Up @@ -613,7 +613,7 @@
}}
role="option"
aria-selected={option === selected ? 'true' : 'false'}
aria-disabled={option?.disabled ? 'true' : 'false'}
disabled={option.disabled}
>
{option.label}
</MenuItem>
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-ux/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type MenuOption<T = any> = {
value: T;
icon?: string;
group?: string;
disabled?: boolean;
} & Record<string, any>;

export type LabelPlacement = 'inset' | 'float' | 'top' | 'left';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
{ label: 'Four', value: 4, icon: mdiAccount },
];
let optionsWithDisabled: MenuOption[] = [
{ label: 'One', value: 1 },
{ label: 'Two', value: 2 },
{ label: 'Three', value: 3, disabled: true },
{ label: 'Four', value: 4 },
];
const optionsWithGroup: MenuOption[] = [
{ label: 'One', value: 1, group: 'First' },
{ label: 'Two', value: 2, group: 'First' },
Expand Down Expand Up @@ -105,6 +112,15 @@
<SelectField {options} bind:value clearSearchOnOpen={false} />
</Preview>

<h2>Disabled options</h2>

<Preview>
<SelectField
options={optionsWithDisabled}
on:change={(e) => console.log('on:change', e.detail)}
/>
</Preview>

<h2>Grouped options</h2>

<Preview>
Expand Down

0 comments on commit 19ca5a6

Please sign in to comment.