mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +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
|
@ -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;
|
||||
}}"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue