From d52828a25cec8cf6f12d128304326426f6fad296 Mon Sep 17 00:00:00 2001 From: "K.Kiyokawa" Date: Mon, 17 Jan 2022 12:09:19 +0900 Subject: [PATCH] feat: omit `selectedIndex` from the `select` event --- COMPONENT_INDEX.md | 6 +++--- docs/src/COMPONENT_API.json | 2 +- src/Dropdown/Dropdown.svelte | 7 +++---- types/Dropdown/Dropdown.svelte.d.ts | 1 - 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 2b716690..b42dc5df 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -1192,9 +1192,9 @@ None. ### Events -| Event name | Type | Detail | -| :--------- | :--------- | :--------------------------------------------------------------------------------------------- | -| select | dispatched | { selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem } | +| Event name | Type | Detail | +| :--------- | :--------- | :---------------------------------------------------------------------- | +| select | dispatched | { selectedId: DropdownItemId, selectedItem: DropdownItem } | ## `DropdownSkeleton` diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index 4b3dd7b8..844694c5 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -3228,7 +3228,7 @@ { "type": "dispatched", "name": "select", - "detail": "{ selectedId: DropdownItemId, selectedIndex: number, selectedItem: DropdownItem }" + "detail": "{ selectedId: DropdownItemId, selectedItem: DropdownItem }" } ], "typedefs": [ diff --git a/src/Dropdown/Dropdown.svelte b/src/Dropdown/Dropdown.svelte index 18baba6e..30c67898 100644 --- a/src/Dropdown/Dropdown.svelte +++ b/src/Dropdown/Dropdown.svelte @@ -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; } diff --git a/types/Dropdown/Dropdown.svelte.d.ts b/types/Dropdown/Dropdown.svelte.d.ts index a1acc537..bf66c6e4 100644 --- a/types/Dropdown/Dropdown.svelte.d.ts +++ b/types/Dropdown/Dropdown.svelte.d.ts @@ -145,7 +145,6 @@ export default class Dropdown extends SvelteComponentTyped< { select: CustomEvent<{ selectedId: DropdownItemId; - selectedIndex: number; selectedItem: DropdownItem; }>; },