-
Notifications
You must be signed in to change notification settings - Fork 46
fix: single-select validation and improve test coverage #10055
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
base: codex/fix-issue-with-component-das
Are you sure you want to change the base?
Changes from 2 commits
48f337c
12c7b2b
1da7d97
523a266
65c6610
8d18730
58c7a4d
6ca1e00
877ed03
02c3143
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -349,6 +349,7 @@ export class KolSingleSelect implements SingleSelectAPI, FocusableElement { | |||||||||
| _variant="ghost" | ||||||||||
| _disabled={isDisabled} | ||||||||||
| class="kol-single-select__delete" | ||||||||||
| data-testid="single-select-delete" | ||||||||||
| hidden={isDisabled} | ||||||||||
| _on={{ | ||||||||||
| onClick: (event: MouseEvent) => { | ||||||||||
|
|
@@ -440,8 +441,6 @@ export class KolSingleSelect implements SingleSelectAPI, FocusableElement { | |||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| @Listen('keydown') | ||||||||||
| public handleKeyDown(event: KeyboardEvent) { | ||||||||||
| const handleEvent = (isOpen?: boolean, callback?: () => void): void => { | ||||||||||
|
|
@@ -712,6 +711,15 @@ export class KolSingleSelect implements SingleSelectAPI, FocusableElement { | |||||||||
| public validateOptions(value?: OptionsPropType): void { | ||||||||||
| this.controller.validateOptions(value); | ||||||||||
| this._filteredOptions = value; | ||||||||||
| // Check if current value is still valid in the new options | ||||||||||
| if (this._value !== null && Array.isArray(value)) { | ||||||||||
| const valueExists = value.some((option) => option.value === this._value); | ||||||||||
| if (!valueExists) { | ||||||||||
| this._value = null; | ||||||||||
| this._inputValue = ''; | ||||||||||
| this.controller.setFormAssociatedValue(null); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if (this._isOpen) { | ||||||||||
| this.setFilteredOptionsByQuery(this._inputValue); | ||||||||||
| } else { | ||||||||||
|
|
@@ -794,6 +802,13 @@ export class KolSingleSelect implements SingleSelectAPI, FocusableElement { | |||||||||
| if (!Array.isArray(this._options)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Normalize undefined to null | ||||||||||
| if (value === undefined) { | ||||||||||
| value = null; | ||||||||||
| this._value = null; | ||||||||||
|
Comment on lines
+809
to
+810
Contributor
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. The normalization of To make the flow clearer and avoid redundant execution, you can simply set
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| if (this.isSelectionCleared && value === null) { | ||||||||||
| this._inputValue = ''; | ||||||||||
| this._filteredOptions = [...this.state._options]; | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.