feat: support item.disabled key for Dropdown, MultiSelect, ComboBox (#1328)

Closes #1326

* feat: support item.disabled key for `Dropdown`, `MultiSelect`, `ComboBox`

* Run "yarn build:docs"

* test: assert disabled property

* docs: add "Disabled items" examples
This commit is contained in:
metonym 2022-06-02 17:56:30 -07:00 committed by GitHub
commit f25a10c9c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 150 additions and 19 deletions

View file

@ -2,7 +2,7 @@
/**
* @typedef {any} DropdownItemId
* @typedef {string} DropdownItemText
* @typedef {{ id: DropdownItemId; text: DropdownItemText; }} DropdownItem
* @typedef {{ id: DropdownItemId; text: DropdownItemText; disabled?: boolean; }} DropdownItem
* @event {{ selectedId: DropdownItemId, selectedItem: DropdownItem }} select
* @slot {{ item: DropdownItem; index: number; }}
*/
@ -121,6 +121,20 @@
index = 0;
}
let disabled = items[index].disabled;
while (disabled) {
index = index + dir;
if (index < 0) {
index = items.length - 1;
} else if (index >= items.length) {
index = 0;
}
disabled = items[index].disabled;
}
highlightedIndex = index;
}
@ -248,11 +262,17 @@
id="{item.id}"
active="{selectedId === item.id}"
highlighted="{highlightedIndex === i || selectedId === item.id}"
on:click="{() => {
disabled="{item.disabled}"
on:click="{(e) => {
if (item.disabled) {
e.stopPropagation();
return;
}
selectedId = item.id;
ref.focus();
}}"
on:mouseenter="{() => {
if (item.disabled) return;
highlightedIndex = i;
}}"
>