Skip to content

Commit

Permalink
fix(core/select): non string values for the "value" prop of select-it…
Browse files Browse the repository at this point in the history
…ems are not working (#1159)

Co-authored-by: Lukas Maurer <[email protected]>
  • Loading branch information
jul-lam and nuke-ellington authored Mar 27, 2024
1 parent c87a28e commit f5e4c83
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-fireants-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siemens/ix": patch
---

fix(core/select): non string values for the "value" prop of select-items are not working
12 changes: 9 additions & 3 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13156,7 +13156,7 @@
"mutable": false,
"attr": "selected",
"reflectToAttr": false,
"docs": "Whether the item is selected.",
"docs": "Flag indicating whether the item is selected",
"docsTags": [],
"default": "false",
"values": [
Expand All @@ -13178,8 +13178,14 @@
"mutable": false,
"attr": "value",
"reflectToAttr": true,
"docs": "Item value",
"docsTags": [],
"docs": "The value of the item.\nImportant: The select component uses string values to handle selection and will call toString() on this value.\nTherefor a string should be passed to value to prevent unexpected behavior.",
"docsTags": [
{
"name": "deprecated",
"text": "will be changed to type string with next major release (3.0.0)"
}
],
"deprecation": "will be changed to type string with next major release (3.0.0)",
"values": [
{
"type": "any"
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1875,11 +1875,12 @@ export namespace Components {
*/
"onItemClick": (event?: CustomEvent<HTMLIxDropdownItemElement>) => Promise<void>;
/**
* Whether the item is selected.
* Flag indicating whether the item is selected
*/
"selected": boolean;
/**
* Item value
* The value of the item. Important: The select component uses string values to handle selection and will call toString() on this value. Therefor a string should be passed to value to prevent unexpected behavior.
* @deprecated will be changed to type string with next major release (3.0.0)
*/
"value": any;
}
Expand Down Expand Up @@ -6014,11 +6015,12 @@ declare namespace LocalJSX {
*/
"onItemClick"?: (event: IxSelectItemCustomEvent<string>) => void;
/**
* Whether the item is selected.
* Flag indicating whether the item is selected
*/
"selected"?: boolean;
/**
* Item value
* The value of the item. Important: The select component uses string values to handle selection and will call toString() on this value. Therefor a string should be passed to value to prevent unexpected behavior.
* @deprecated will be changed to type string with next major release (3.0.0)
*/
"value": any;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/components/select-item/select-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ export class SelectItem {
@Prop({ reflect: true }) label: string;

/**
* Item value
* The value of the item.
* Important: The select component uses string values to handle selection and will call toString() on this value.
* Therefor a string should be passed to value to prevent unexpected behavior.
* @deprecated will be changed to type string with next major release (3.0.0)
*/
@Prop({ reflect: true }) value!: any;

/**
* Whether the item is selected.
* Flag indicating whether the item is selected
*/
@Prop() selected = false;

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ export class Select {
}

this.items.forEach((item) => {
item.selected = ids.some((i) => i === item.value);
item.selected = ids.some(
// Check can be removed if value is type of string in future releases
(i) => i === (item.value ? item.value.toString() : '')
);
});

this.selectedLabels = this.selectedItems.map((item) => item.label);
Expand Down

0 comments on commit f5e4c83

Please sign in to comment.