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

@ -1,7 +1,7 @@
<script>
/**
* @typedef {any} ComboBoxItemId
* @typedef {{ id: ComboBoxItemId; text: string; }} ComboBoxItem
* @typedef {{ id: ComboBoxItemId; text: string; disabled?: boolean; }} ComboBoxItem
* @event {{ selectedId: ComboBoxItemId; selectedItem: ComboBoxItem }} select
* @slot {{ item: ComboBoxItem; index: number }}
*/
@ -133,6 +133,20 @@
} else if (index >= _items.length) {
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;
}
@ -360,7 +374,12 @@
id="{item.id}"
active="{selectedId === item.id}"
highlighted="{highlightedIndex === i}"
on:click="{() => {
disabled="{item.disabled}"
on:click="{(e) => {
if (item.disabled) {
e.stopPropagation();
return;
}
selectedId = item.id;
open = false;
@ -369,6 +388,7 @@
}
}}"
on:mouseenter="{() => {
if (item.disabled) return;
highlightedIndex = i;
}}"
>