mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-16 02:41:05 +00:00
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:
parent
22f93ee675
commit
f25a10c9c4
16 changed files with 150 additions and 19 deletions
|
@ -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;
|
||||
}}"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue