Repository navigation
fix(core/select): prevent input clearing on slotchange race condition #2509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
773b013
0e9f755
b30c39b
88a5376
e80eaa3
52c47f1
bd60622
733b85c
d62e42b
b0ae67c
639ce1c
629b762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@siemens/ix": patch | ||
| --- | ||
|
|
||
| Prevent input getting cleared if slot changes in __ix-select__. This fix is especially relevant if select items are being rendered in a virtual scrolling container. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,6 +259,14 @@ export class Select | |
| */ | ||
| @Event() inputChange!: EventEmitter<string>; | ||
|
|
||
| /** | ||
| * Event dispatched whenever the dropdown opens or closes. | ||
| * Emits `true` when the dropdown opens and `false` when it closes. | ||
| * | ||
| * @since 5.1.0 | ||
| */ | ||
| @Event() dropdownOpenChange!: EventEmitter<boolean>; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does the requirement for this new event come from? It is not consumed internally. Do we really need to add it?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the reason why I made this change : The filter will not reset when the dropdown closes and gets opened again. (virtual scroll and filtering case) Emitting inputChange('') on close worked, but it mixed text-input behavior with dropdown state. So I have added dropdownOpenChange instead. It is not consumed internally, but it gives consumers a clear event to reset their filtered data when the dropdown closes or opens. That makes the intent explicit and works better for the virtual scroll or any dynamic rendering case. |
||
|
|
||
| /** | ||
| * Item added to selection | ||
| */ | ||
|
|
@@ -486,13 +494,16 @@ export class Select | |
|
|
||
| this.pruneChipWidthCache(); | ||
|
|
||
| if (this.dropdownShow && this.inputFilterText) { | ||
| if ( | ||
| this.dropdownShow && | ||
| (this.inputFilterText || this.inputElement?.value) | ||
| ) { | ||
| return; | ||
| } | ||
|
nuke-ellington marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (this.selectedLabels?.length && this.isSingleMode) { | ||
| this.inputValue = this.selectedLabels[0] ?? ''; | ||
| } else { | ||
| } else if (!this.hasValue()) { | ||
|
Comment on lines
+497
to
+506
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ฏ Functional Correctness | ๐ก Minor | โก Quick win ๐ Supported by static analysis๐ Script executed: sed -n '360,535p' packages/core/src/components/select/select.tsx
sed -n '560,645p' packages/core/src/components/select/select.tsx
rg -n 'updateSelection|inputFilterText|onValueChange|handle.*Select|valueChange' packages/core/src/components/select/select.tsxRepository: siemens/ix Length of output: 7785 ๐ Script executed: #!/bin/bash
git diff --stat b7fa46ffa6d485cd0c00fb853b282e8c4eb272a9 629b762306699fb1fe7983bee1866cd70b1c82d1 -- packages/core/src/components/select
sed -n '220,330p' packages/core/src/components/select/select.tsx
sed -n '680,790p' packages/core/src/components/select/select.tsx
sed -n '1560,1660p' packages/core/src/components/select/select.tsx
rg -n -C 5 'itemClick|dropdownVisibilityChanged|valueChange|dropdownOpenChange|updateSelection|inputElement' packages/core/src/components/select/test packages/core/src/components/select --glob '*.{ts,tsx}'Repository: siemens/ix Length of output: 41326 ๐ Script executed: #!/bin/bash
git diff b7fa46ffa6d485cd0c00fb853b282e8c4eb272a9 629b762306699fb1fe7983bee1866cd70b1c82d1 -- packages/core/src/components/select/select.tsx packages/core/src/components/select/test/select.ct.ts
rg -n -C 8 'showChanged|showChange|`@Watch`.*show|`@Prop`.*show|show =' packages/core/src/components/dropdown packages/core/src/components --glob '*.{ts,tsx}'
sed -n '1320,1395p' packages/core/src/components/select/test/select.ct.ts
sed -n '1660,1785p' packages/core/src/components/select/test/select.ct.tsRepository: siemens/ix Length of output: 41136 ๐ Script executed: #!/bin/bash
sed -n '1495,1570p' packages/core/src/components/select/select.tsx
sed -n '610,692p' packages/core/src/components/dropdown/dropdown.tsx
rg -n -C 6 'value\s*=|inputFilterText|toHaveValue' packages/core/src/components/select/test/select.ct.ts | tail -n 120Repository: siemens/ix Length of output: 9609 Synchronize externally assigned single-select values while the dropdown is open. An external Suggested fix `@Watch`('value')
watchValue(value: string | string[]) {
this.value = value;
- this.updateSelection();
+ this.updateSelection(!this.inputFilterText);
}
-private updateSelection() {
+private updateSelection(forceInputSync = false) {
let ids: string[] = [];
if (this.value) {
ids = Array.isArray(this.value) ? [...this.value] : [this.value];
}
this.items.forEach((item) => {
item.selected = ids.some((i) => {
if (typeof i !== typeof item.value) {
return i.toString() === item.value.toString();
} else {
return i === item.value;
}
});
});
this.selectedLabels = this.selectedItems.map(
(item) => item.label ?? item.value
);
this.pruneChipWidthCache();
if (
+ !forceInputSync &&
this.dropdownShow &&
(this.inputFilterText || this.inputElement?.value)
) {
return;
}๐ค Prompt for AI Agents |
||
| this.inputValue = ''; | ||
| } | ||
|
|
||
|
|
@@ -603,6 +614,7 @@ export class Select | |
|
|
||
| private dropdownVisibilityChanged(event: CustomEvent<boolean>) { | ||
| this.dropdownShow = event.detail; | ||
| this.dropdownOpenChange.emit(event.detail); | ||
|
|
||
| if (event.detail) { | ||
| this.inputElement?.focus(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ Maintainability & Code Quality | ๐ก Minor | โก Quick win
๐ Supported by static analysis
๐ Script executed:
Repository: siemens/ix
Length of output: 4821
๐ค get_repo_knowledge executed:
get_repo_knowledge siemens/ix /tmp/coderabbit-repo-knowledge/siemens-ix-50f9eed0/conventions /tmp/coderabbit-repo-knowledge/siemens-ix-50f9eed0/learningsLength of output: 17534
๐ Script executed:
Repository: siemens/ix
Length of output: 41479
๐ Script executed:
Repository: siemens/ix
Length of output: 10574
Set
@sinceto 5.2.2.The changeset declares a patch release from 5.2.1, so this newly added event first ships in 5.2.2. Update the annotation in the core source, then regenerate the affected declarations.
Suggested fix
๐ Committable suggestion
๐ค Prompt for AI Agents