feat: omit selectedIndex from the select event

This commit is contained in:
K.Kiyokawa 2022-01-17 12:09:19 +09:00
commit d52828a25c
4 changed files with 7 additions and 9 deletions

View file

@ -1193,8 +1193,8 @@ None.
### Events
| Event name | Type | Detail |
| :--------- | :--------- | :--------------------------------------------------------------------------------------------- |
| select | dispatched | <code>{ selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem }</code> |
| :--------- | :--------- | :---------------------------------------------------------------------- |
| select | dispatched | <code>{ selectedId: DropdownItemId, selectedItem: DropdownItem }</code> |
## `DropdownSkeleton`

View file

@ -3228,7 +3228,7 @@
{
"type": "dispatched",
"name": "select",
"detail": "{ selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem }"
"detail": "{ selectedId: DropdownItemId, selectedItem: DropdownItem }"
}
],
"typedefs": [

View file

@ -3,7 +3,7 @@
* @typedef {string} DropdownItemId
* @typedef {string} DropdownItemText
* @typedef {{ id: DropdownItemId; text: DropdownItemText; }} DropdownItem
* @event {{ selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem }} select
* @event {{ selectedId: DropdownItemId, selectedItem: DropdownItem }} select
*/
/**
@ -126,11 +126,10 @@
}
$: if (selectedId !== undefined) {
dispatch("select", { selectedId, selectedIndex, selectedItem });
dispatch("select", { selectedId, selectedItem });
}
$: inline = type === "inline";
$: selectedIndex = items.findIndex((item) => item.id === selectedId);
$: selectedItem = items[selectedIndex];
$: selectedItem = items.find((item) => item.id === selectedId);
$: if (!open) {
highlightedIndex = -1;
}

View file

@ -145,7 +145,6 @@ export default class Dropdown extends SvelteComponentTyped<
{
select: CustomEvent<{
selectedId: DropdownItemId;
selectedIndex: number;
selectedItem: DropdownItem;
}>;
},