From 1f7b5560a866cd4042e5ce1e914cbdff2b265a70 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Thu, 20 Jan 2022 18:50:36 -0800 Subject: [PATCH] Type `id` as any in `ComboBox`, `Dropdown`, `MultiSelect` (#1019) Loosen the prop type for `id`, `selectedId` to be `any` instead of a `string`. --- COMPONENT_INDEX.md | 46 ++++++++++++----------- docs/src/COMPONENT_API.json | 25 +++++++----- src/ComboBox/ComboBox.svelte | 7 ++-- src/Dropdown/Dropdown.svelte | 2 +- src/MultiSelect/MultiSelect.svelte | 6 +-- tests/ComboBox.test.svelte | 5 ++- tests/Dropdown.test.svelte | 5 ++- tests/MultiSelect.test.svelte | 2 +- types/ComboBox/ComboBox.svelte.d.ts | 11 ++++-- types/Dropdown/Dropdown.svelte.d.ts | 2 +- types/MultiSelect/MultiSelect.svelte.d.ts | 6 +-- 11 files changed, 68 insertions(+), 49 deletions(-) diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 31f94601..8a6286e9 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -648,8 +648,10 @@ None. ### Types ```ts +export type ComboBoxItemId = any; + export interface ComboBoxItem { - id: string; + id: ComboBoxItemId; text: string; } ``` @@ -662,7 +664,7 @@ export interface ComboBoxItem { | ref | let | Yes | null | HTMLInputElement | null | Obtain a reference to the input HTML element | | open | let | Yes | boolean | false | Set to `true` to open the combobox menu dropdown | | value | let | Yes | string | "" | Specify the selected combobox value | -| selectedId | let | Yes | string | -- | Set the selected item by value id | +| selectedId | let | Yes | ComboBoxItemId | -- | Set the selected item by value id | | items | let | No | ComboBoxItem[] | [] | Set the combobox items | | itemToString | let | No | (item: ComboBoxItem) => string | (item) => item.text || item.id | Override the display of a combobox item | | direction | let | No | "bottom" | "top" | "bottom" | Specify the direction of the combobox dropdown menu | @@ -688,15 +690,15 @@ None. ### Events -| Event name | Type | Detail | -| :--------- | :--------- | :-------------------------------------------------------------- | -| select | dispatched | { selectedId: string; selectedItem: ComboBoxItem } | -| keydown | forwarded | -- | -| keyup | forwarded | -- | -| focus | forwarded | -- | -| blur | forwarded | -- | -| clear | forwarded | -- | -| scroll | forwarded | -- | +| Event name | Type | Detail | +| :--------- | :--------- | :---------------------------------------------------------------------- | +| select | dispatched | { selectedId: ComboBoxItemId; selectedItem: ComboBoxItem } | +| keydown | forwarded | -- | +| keyup | forwarded | -- | +| focus | forwarded | -- | +| blur | forwarded | -- | +| clear | forwarded | -- | +| scroll | forwarded | -- | ## `ComposedModal` @@ -1151,7 +1153,7 @@ None. ### Types ```ts -export type DropdownItemId = string; +export type DropdownItemId = any; export type DropdownItemText = string; @@ -2401,7 +2403,7 @@ None. ### Types ```ts -export type MultiSelectItemId = string; +export type MultiSelectItemId = any; export type MultiSelectItemText = string; @@ -2423,7 +2425,7 @@ export interface MultiSelectItem { | value | let | Yes | string | "" | Specify the multiselect value | | selectedIds | let | Yes | MultiSelectItemId[] | [] | Set the selected ids | | items | let | Yes | MultiSelectItem[] | [] | Set the multiselect items | -| itemToString | let | No | (item: MultiSelectItem) => string | (item) => item.text || item.id | Override the display of a multiselect item | +| itemToString | let | No | (item: MultiSelectItem) => any | (item) => item.text || item.id | Override the display of a multiselect item | | size | let | No | "sm" | "lg" | "xl" | -- | Set the size of the combobox | | type | let | No | "default" | "inline" | "default" | Specify the type of multiselect | | direction | let | No | "bottom" | "top" | "bottom" | Specify the direction of the multiselect dropdown menu | @@ -2454,14 +2456,14 @@ None. ### Events -| Event name | Type | Detail | -| :--------- | :--------- | :-------------------------------------------------------------------------------------------------- | -| select | dispatched | { selectedIds: string[]; selected: MultiSelectItem[]; unselected: MultiSelectItem[]; } | -| clear | dispatched | any | -| keydown | forwarded | -- | -| keyup | forwarded | -- | -| focus | forwarded | -- | -| blur | forwarded | -- | +| Event name | Type | Detail | +| :--------- | :--------- | :------------------------------------------------------------------------------------------------------------- | +| select | dispatched | { selectedIds: MultiSelectItemId[]; selected: MultiSelectItem[]; unselected: MultiSelectItem[]; } | +| clear | dispatched | any | +| keydown | forwarded | -- | +| keyup | forwarded | -- | +| focus | forwarded | -- | +| blur | forwarded | -- | ## `NotificationActionButton` diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index d76f65f4..bdc49565 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -1398,7 +1398,7 @@ "name": "selectedId", "kind": "let", "description": "Set the selected item by value id", - "type": "string", + "type": "ComboBoxItemId", "isFunction": false, "isFunctionDeclaration": false, "constant": false, @@ -1627,7 +1627,7 @@ { "type": "dispatched", "name": "select", - "detail": "{ selectedId: string; selectedItem: ComboBoxItem }" + "detail": "{ selectedId: ComboBoxItemId; selectedItem: ComboBoxItem }" }, { "type": "forwarded", "name": "keydown", "element": "input" }, { "type": "forwarded", "name": "keyup", "element": "input" }, @@ -1638,9 +1638,14 @@ ], "typedefs": [ { - "type": "{ id: string; text: string; }", + "type": "any", + "name": "ComboBoxItemId", + "ts": "type ComboBoxItemId = any" + }, + { + "type": "{ id: ComboBoxItemId; text: string; }", "name": "ComboBoxItem", - "ts": "interface ComboBoxItem { id: string; text: string; }" + "ts": "interface ComboBoxItem { id: ComboBoxItemId; text: string; }" } ], "rest_props": { "type": "Element", "name": "input" } @@ -3254,9 +3259,9 @@ ], "typedefs": [ { - "type": "string", + "type": "any", "name": "DropdownItemId", - "ts": "type DropdownItemId = string" + "ts": "type DropdownItemId = any" }, { "type": "string", @@ -6404,7 +6409,7 @@ "name": "itemToString", "kind": "let", "description": "Override the display of a multiselect item", - "type": "(item: MultiSelectItem) => string", + "type": "(item: MultiSelectItem) => any", "value": "(item) => item.text || item.id", "isFunction": true, "isFunctionDeclaration": false, @@ -6744,7 +6749,7 @@ { "type": "dispatched", "name": "select", - "detail": "{ selectedIds: string[]; selected: MultiSelectItem[]; unselected: MultiSelectItem[]; }" + "detail": "{ selectedIds: MultiSelectItemId[]; selected: MultiSelectItem[]; unselected: MultiSelectItem[]; }" }, { "type": "dispatched", "name": "clear", "detail": "any" }, { "type": "forwarded", "name": "keydown", "element": "input" }, @@ -6754,9 +6759,9 @@ ], "typedefs": [ { - "type": "string", + "type": "any", "name": "MultiSelectItemId", - "ts": "type MultiSelectItemId = string" + "ts": "type MultiSelectItemId = any" }, { "type": "string", diff --git a/src/ComboBox/ComboBox.svelte b/src/ComboBox/ComboBox.svelte index 38ff2ff5..be693f34 100644 --- a/src/ComboBox/ComboBox.svelte +++ b/src/ComboBox/ComboBox.svelte @@ -1,7 +1,8 @@