From f7146b61dc35c7b5c1db5aa1ea165473e5fc3d00 Mon Sep 17 00:00:00 2001 From: metonym Date: Wed, 4 May 2022 07:40:10 -0700 Subject: [PATCH] fix: remove `translateWithIdMenu`, use `translateWithId` instead, rename `translateWithIdInput` (#1285) * fix: remove translateWithIdMenu, use translateWithId instead * chore: rename translateWithIdInput to translateWithIdSelection --- COMPONENT_INDEX.md | 128 +++++++++++----------- docs/src/COMPONENT_API.json | 28 +---- src/ComboBox/ComboBox.svelte | 13 +-- src/MultiSelect/MultiSelect.svelte | 16 +-- tests/ComboBox.test.svelte | 5 +- tests/MultiSelect.test.svelte | 5 +- types/ComboBox/ComboBox.svelte.d.ts | 11 +- types/MultiSelect/MultiSelect.svelte.d.ts | 10 +- 8 files changed, 81 insertions(+), 135 deletions(-) diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index cdbcdad0..df85b92f 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -649,33 +649,32 @@ export interface ComboBoxItem { ### Props -| Prop name | Kind | Reactive | Type | Default value | Description | -| :------------------- | :-------------------- | :------- | :---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -| listRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the list HTML element | -| 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 | ComboBoxItemId | undefined | 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 | -| size | let | No | "sm" | "xl" | undefined | Set the size of the combobox | -| disabled | let | No | boolean | false | Set to `true` to disable the combobox | -| titleText | let | No | string | "" | Specify the title text of the combobox | -| placeholder | let | No | string | "" | Specify the placeholder text | -| helperText | let | No | string | "" | Specify the helper text | -| invalidText | let | No | string | "" | Specify the invalid state text | -| invalid | let | No | boolean | false | Set to `true` to indicate an invalid state | -| warn | let | No | boolean | false | Set to `true` to indicate an warning state | -| warnText | let | No | string | "" | Specify the warning state text | -| light | let | No | boolean | false | Set to `true` to enable the light variant | -| shouldFilterItem | let | No | (item: ComboBoxItem, value: string) => boolean | () => true | Determine if an item should be filtered given the current combobox value | -| translateWithId | let | No | (id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId) => string | undefined | Override the chevron icon label based on the open state.
Defaults to "Open menu" when closed and "Close menu" when open | -| translateWithIdMenu | let | No | (id: any) => string | undefined | Override the menu label based on the open state.
Defaults to "Open menu" and "Close menu" | -| translateWithIdInput | let | No | (id: "clearSelection") => string | undefined | Override the label of the clear button when the input has a selection.
Defaults to "Clear selected item" | -| id | let | No | string | "ccs-" + Math.random().toString(36) | Set an id for the list box component | -| name | let | No | string | undefined | Specify a name attribute for the input | -| clear | function | No | (options?: { focus?: boolean; }) => void | () => { prevSelectedId = null; highlightedIndex = -1; highlightedId = undefined; selectedId = undefined; selectedItem = undefined; open = false; inputValue = ""; if (options?.focus !== false) ref?.focus(); } | Clear the combo box programmatically | +| Prop name | Kind | Reactive | Type | Default value | Description | +| :----------------------- | :-------------------- | :------- | :---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | +| listRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the list HTML element | +| 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 | ComboBoxItemId | undefined | 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 | +| size | let | No | "sm" | "xl" | undefined | Set the size of the combobox | +| disabled | let | No | boolean | false | Set to `true` to disable the combobox | +| titleText | let | No | string | "" | Specify the title text of the combobox | +| placeholder | let | No | string | "" | Specify the placeholder text | +| helperText | let | No | string | "" | Specify the helper text | +| invalidText | let | No | string | "" | Specify the invalid state text | +| invalid | let | No | boolean | false | Set to `true` to indicate an invalid state | +| warn | let | No | boolean | false | Set to `true` to indicate an warning state | +| warnText | let | No | string | "" | Specify the warning state text | +| light | let | No | boolean | false | Set to `true` to enable the light variant | +| shouldFilterItem | let | No | (item: ComboBoxItem, value: string) => boolean | () => true | Determine if an item should be filtered given the current combobox value | +| translateWithId | let | No | (id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId) => string | undefined | Override the chevron icon label based on the open state.
Defaults to "Open menu" when closed and "Close menu" when open | +| translateWithIdSelection | let | No | (id: "clearSelection") => string | undefined | Override the label of the clear button when the input has a selection.
Defaults to "Clear selected item" since a combo box can only have on selection. | +| id | let | No | string | "ccs-" + Math.random().toString(36) | Set an id for the list box component | +| name | let | No | string | undefined | Specify a name attribute for the input | +| clear | function | No | (options?: { focus?: boolean; }) => void | () => { prevSelectedId = null; highlightedIndex = -1; highlightedId = undefined; selectedId = undefined; selectedItem = undefined; open = false; inputValue = ""; if (options?.focus !== false) ref?.focus(); } | Clear the combo box programmatically | ### Slots @@ -2327,44 +2326,43 @@ export interface MultiSelectItem { ### Props -| Prop name | Kind | Reactive | Type | Default value | Description | -| :------------------- | :--------------- | :------- | :------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | -| highlightedId | let | Yes | null | MultiSelectItemId | null | Id of the highlighted ListBoxMenuItem | -| selectionRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the selection element | -| fieldRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the field box element | -| multiSelectRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the outer div element | -| inputRef | let | Yes | null | HTMLInputElement | null | Obtain a reference to the input HTML element | -| open | let | Yes | boolean | false | Set to `true` to open the dropdown | -| 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) => any | (item) => item.text || item.id | Override the display of a multiselect item | -| itemToInput | let | No | (item: MultiSelectItem) => { name?: string; labelText?: any; title?: string; } | (item) => {} | Override the item name, title, labelText passed to the checkbox input | -| size | let | No | "sm" | "lg" | "xl" | undefined | 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 | -| selectionFeedback | let | No | "top" | "fixed" | "top-after-reopen" | "top-after-reopen" | Specify the selection feedback after selecting items | -| disabled | let | No | boolean | false | Set to `true` to disable the dropdown | -| filterable | let | No | boolean | false | Set to `true` to filter items | -| filterItem | let | No | (item: MultiSelectItem, value: string) => string | (item, value) => item.text.toLowerCase().includes(value.trim().toLowerCase()) | Override the filtering logic
The default filtering is an exact string comparison | -| light | let | No | boolean | false | Set to `true` to enable the light variant | -| locale | let | No | string | "en" | Specify the locale | -| placeholder | let | No | string | "" | Specify the placeholder text | -| sortItem | let | No | ((a: MultiSelectItem, b: MultiSelectItem) => MultiSelectItem) | (() => void) | (a, b) => a.text.localeCompare(b.text, locale, { numeric: true }) | Override the sorting logic
The default sorting compare the item text value | -| translateWithId | let | No | (id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId) => string | undefined | Override the chevron icon label based on the open state.
Defaults to "Open menu" when closed and "Close menu" when open | -| translateWithIdMenu | let | No | (id: any) => string | undefined | Override the default translation ids for the menu | -| translateWithIdInput | let | No | (id: import("../ListBox/ListBoxSelection.svelte").ListBoxSelectionTranslationId) => string | undefined | Override the label of the clear button when the input has a selection.
Defaults to "Clear selected item" and "Clear all items" | -| titleText | let | No | string | "" | Specify the title text | -| useTitleInItem | let | No | boolean | false | Set to `true` to pass the item to `itemToString` in the checkbox | -| invalid | let | No | boolean | false | Set to `true` to indicate an invalid state | -| invalidText | let | No | string | "" | Specify the invalid state text | -| warn | let | No | boolean | false | Set to `true` to indicate an warning state | -| warnText | let | No | string | "" | Specify the warning state text | -| helperText | let | No | string | "" | Specify the helper text | -| label | let | No | string | "" | Specify the list box label | -| hideLabel | let | No | boolean | false | Set to `true` to visually hide the label text | -| id | let | No | string | "ccs-" + Math.random().toString(36) | Set an id for the list box component | -| name | let | No | string | undefined | Specify a name attribute for the select | +| Prop name | Kind | Reactive | Type | Default value | Description | +| :----------------------- | :--------------- | :------- | :------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| highlightedId | let | Yes | null | MultiSelectItemId | null | Id of the highlighted ListBoxMenuItem | +| selectionRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the selection element | +| fieldRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the field box element | +| multiSelectRef | let | Yes | null | HTMLDivElement | null | Obtain a reference to the outer div element | +| inputRef | let | Yes | null | HTMLInputElement | null | Obtain a reference to the input HTML element | +| open | let | Yes | boolean | false | Set to `true` to open the dropdown | +| 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) => any | (item) => item.text || item.id | Override the display of a multiselect item | +| itemToInput | let | No | (item: MultiSelectItem) => { name?: string; labelText?: any; title?: string; } | (item) => {} | Override the item name, title, labelText passed to the checkbox input | +| size | let | No | "sm" | "lg" | "xl" | undefined | 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 | +| selectionFeedback | let | No | "top" | "fixed" | "top-after-reopen" | "top-after-reopen" | Specify the selection feedback after selecting items | +| disabled | let | No | boolean | false | Set to `true` to disable the dropdown | +| filterable | let | No | boolean | false | Set to `true` to filter items | +| filterItem | let | No | (item: MultiSelectItem, value: string) => string | (item, value) => item.text.toLowerCase().includes(value.trim().toLowerCase()) | Override the filtering logic
The default filtering is an exact string comparison | +| light | let | No | boolean | false | Set to `true` to enable the light variant | +| locale | let | No | string | "en" | Specify the locale | +| placeholder | let | No | string | "" | Specify the placeholder text | +| sortItem | let | No | ((a: MultiSelectItem, b: MultiSelectItem) => MultiSelectItem) | (() => void) | (a, b) => a.text.localeCompare(b.text, locale, { numeric: true }) | Override the sorting logic
The default sorting compare the item text value | +| translateWithId | let | No | (id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId) => string | undefined | Override the chevron icon label based on the open state.
Defaults to "Open menu" when closed and "Close menu" when open | +| translateWithIdSelection | let | No | (id: import("../ListBox/ListBoxSelection.svelte").ListBoxSelectionTranslationId) => string | undefined | Override the label of the clear button when the input has a selection.
Defaults to "Clear selected item" and "Clear all items" if more than one item is selected | +| titleText | let | No | string | "" | Specify the title text | +| useTitleInItem | let | No | boolean | false | Set to `true` to pass the item to `itemToString` in the checkbox | +| invalid | let | No | boolean | false | Set to `true` to indicate an invalid state | +| invalidText | let | No | string | "" | Specify the invalid state text | +| warn | let | No | boolean | false | Set to `true` to indicate an warning state | +| warnText | let | No | string | "" | Specify the warning state text | +| helperText | let | No | string | "" | Specify the helper text | +| label | let | No | string | "" | Specify the list box label | +| hideLabel | let | No | boolean | false | Set to `true` to visually hide the label text | +| id | let | No | string | "ccs-" + Math.random().toString(36) | Set an id for the list box component | +| name | let | No | string | undefined | Specify a name attribute for the select | ### Slots diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index f4f2d149..d6c41639 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -1563,19 +1563,9 @@ "reactive": false }, { - "name": "translateWithIdMenu", + "name": "translateWithIdSelection", "kind": "let", - "description": "Override the menu label based on the open state.\nDefaults to \"Open menu\" and \"Close menu\"", - "type": "(id: any) => string", - "isFunction": false, - "isFunctionDeclaration": false, - "constant": false, - "reactive": false - }, - { - "name": "translateWithIdInput", - "kind": "let", - "description": "Override the label of the clear button when the input has a selection.\nDefaults to \"Clear selected item\"", + "description": "Override the label of the clear button when the input has a selection.\nDefaults to \"Clear selected item\" since a combo box can only have on selection.", "type": "(id: \"clearSelection\") => string", "isFunction": false, "isFunctionDeclaration": false, @@ -6611,19 +6601,9 @@ "reactive": false }, { - "name": "translateWithIdMenu", + "name": "translateWithIdSelection", "kind": "let", - "description": "Override the default translation ids for the menu", - "type": "(id: any) => string", - "isFunction": false, - "isFunctionDeclaration": false, - "constant": false, - "reactive": false - }, - { - "name": "translateWithIdInput", - "kind": "let", - "description": "Override the label of the clear button when the input has a selection.\nDefaults to \"Clear selected item\" and \"Clear all items\"", + "description": "Override the label of the clear button when the input has a selection.\nDefaults to \"Clear selected item\" and \"Clear all items\" if more than one item is selected", "type": "(id: import(\"../ListBox/ListBoxSelection.svelte\").ListBoxSelectionTranslationId) => string", "isFunction": false, "isFunctionDeclaration": false, diff --git a/src/ComboBox/ComboBox.svelte b/src/ComboBox/ComboBox.svelte index 52fbacbf..97b8ead0 100644 --- a/src/ComboBox/ComboBox.svelte +++ b/src/ComboBox/ComboBox.svelte @@ -82,19 +82,12 @@ */ export let translateWithId = undefined; - /** - * Override the menu label based on the open state. - * Defaults to "Open menu" and "Close menu" - * @type {(id: any) => string} - */ - export let translateWithIdMenu = undefined; - /** * Override the label of the clear button when the input has a selection. * Defaults to "Clear selected item" since a combo box can only have on selection. * @type {(id: "clearSelection") => string} */ - export let translateWithIdInput = undefined; + export let translateWithIdSelection = undefined; /** Set an id for the list box component */ export let id = "ccs-" + Math.random().toString(36); @@ -246,7 +239,7 @@ }}" id="{id}" disabled="{disabled}" - translateWithId="{translateWithIdMenu}" + translateWithId="{translateWithId}" > diff --git a/src/MultiSelect/MultiSelect.svelte b/src/MultiSelect/MultiSelect.svelte index b9ce6d57..f72b6d99 100644 --- a/src/MultiSelect/MultiSelect.svelte +++ b/src/MultiSelect/MultiSelect.svelte @@ -101,18 +101,12 @@ */ export let translateWithId = undefined; - /** - * Override the default translation ids for the menu - * @type {(id: any) => string} - */ - export let translateWithIdMenu = undefined; - /** * Override the label of the clear button when the input has a selection. - * Defaults to "Clear selected item" and "Clear all items" + * Defaults to "Clear selected item" and "Clear all items" if more than one item is selected * @type {(id: import("../ListBox/ListBoxSelection.svelte").ListBoxSelectionTranslationId) => string} */ - export let translateWithIdInput = undefined; + export let translateWithIdSelection = undefined; /** Specify the title text */ export let titleText = ""; @@ -375,7 +369,7 @@ }}" id="{id}" disabled="{disabled}" - translateWithId="{translateWithIdMenu}" + translateWithId="{translateWithId}" > {#if checked.length > 0} {/if} @@ -453,7 +447,7 @@ inputValue = ''; open = false; }}" - translateWithId="{translateWithIdInput}" + translateWithId="{translateWithIdSelection}" disabled="{disabled}" open="{open}" /> diff --git a/tests/ComboBox.test.svelte b/tests/ComboBox.test.svelte index 337a3f82..bff0227a 100644 --- a/tests/ComboBox.test.svelte +++ b/tests/ComboBox.test.svelte @@ -27,10 +27,7 @@ console.log(id); // "open" | "close" return id; }}" - translateWithIdMenu="{(id) => { - return id; - }}" - translateWithIdInput="{(id) => { + translateWithIdSelection="{(id) => { console.log(id); // "clearSelection" return id; }}" diff --git a/tests/MultiSelect.test.svelte b/tests/MultiSelect.test.svelte index d5faf0fa..df539f2a 100644 --- a/tests/MultiSelect.test.svelte +++ b/tests/MultiSelect.test.svelte @@ -24,10 +24,7 @@ console.log(id); // "open" | "close" return id; }}" - translateWithIdMenu="{(id) => { - return id; - }}" - translateWithIdInput="{(id) => { + translateWithIdSelection="{(id) => { console.log(id); // "clearAll" | "clearSelection" return id; }}" diff --git a/types/ComboBox/ComboBox.svelte.d.ts b/types/ComboBox/ComboBox.svelte.d.ts index c0e87c63..2dc3163a 100644 --- a/types/ComboBox/ComboBox.svelte.d.ts +++ b/types/ComboBox/ComboBox.svelte.d.ts @@ -121,19 +121,12 @@ export interface ComboBoxProps id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId ) => string; - /** - * Override the menu label based on the open state. - * Defaults to "Open menu" and "Close menu" - * @default undefined - */ - translateWithIdMenu?: (id: any) => string; - /** * Override the label of the clear button when the input has a selection. - * Defaults to "Clear selected item" + * Defaults to "Clear selected item" since a combo box can only have on selection. * @default undefined */ - translateWithIdInput?: (id: "clearSelection") => string; + translateWithIdSelection?: (id: "clearSelection") => string; /** * Set an id for the list box component diff --git a/types/MultiSelect/MultiSelect.svelte.d.ts b/types/MultiSelect/MultiSelect.svelte.d.ts index 46eef893..b56e330e 100644 --- a/types/MultiSelect/MultiSelect.svelte.d.ts +++ b/types/MultiSelect/MultiSelect.svelte.d.ts @@ -131,18 +131,12 @@ export interface MultiSelectProps id: import("../ListBox/ListBoxMenuIcon.svelte").ListBoxMenuIconTranslationId ) => string; - /** - * Override the default translation ids for the menu - * @default undefined - */ - translateWithIdMenu?: (id: any) => string; - /** * Override the label of the clear button when the input has a selection. - * Defaults to "Clear selected item" and "Clear all items" + * Defaults to "Clear selected item" and "Clear all items" if more than one item is selected * @default undefined */ - translateWithIdInput?: ( + translateWithIdSelection?: ( id: import("../ListBox/ListBoxSelection.svelte").ListBoxSelectionTranslationId ) => string;