Skip to content

Commit 02c3143

Browse files
committed
Fix single-select options validation and toolbar focus delegation
single-select: Use state._options (parsed by controller) for validation and restore original else-branch for updateInputValue to avoid erasing user input when _value is null. toolbar: Call firstEnabledItem.focus() (the Stencil @method) instead of setFocus() which calls the native HTMLElement focus and doesn't delegate to the inner button. Both HTMLKolButtonWcElement and HTMLKolLinkWcElement expose focus(): Promise<void> so no any-cast is needed. https://claude.ai/code/session_01BRnViGPGv2XXH7kaE3EDCZ
1 parent 877ed03 commit 02c3143

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

packages/components/src/components/single-select/shadow.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,20 @@ export class KolSingleSelect implements SingleSelectAPI, FocusableElement {
711711
public validateOptions(value?: OptionsPropType): void {
712712
this.controller.validateOptions(value);
713713
this._filteredOptions = value;
714-
this.updateInputValue(this._value);
714+
// When a selected value is no longer in the updated options, clear it.
715+
// Use state._options which is guaranteed to be a parsed array after the controller call.
716+
if (this._value !== null && Array.isArray(this.state._options)) {
717+
const valueStillValid = this.state._options.some((option) => option.value === this._value && !option.disabled);
718+
if (!valueStillValid) {
719+
this._value = null;
720+
this._inputValue = '';
721+
this.controller.setFormAssociatedValue(null);
722+
}
723+
}
715724
if (this._isOpen) {
716725
this.setFilteredOptionsByQuery(this._inputValue);
726+
} else {
727+
this.updateInputValue(this._value);
717728
}
718729
}
719730

packages/components/src/components/toolbar/shadow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { KeyboardKey } from '../../schema/enums';
88
import type { OrientationPropType } from '../../schema/props/orientation';
99
import { validateOrientation } from '../../schema/props/orientation';
1010
import { delegateClick, setClick } from '../../utils/element-click';
11-
import { delegateFocus, setFocus } from '../../utils/element-focus';
11+
import { delegateFocus } from '../../utils/element-focus';
1212

1313
@Component({
1414
tag: 'kol-toolbar',
@@ -36,7 +36,7 @@ export class KolToolbar implements ToolbarAPI, FocusableElement {
3636
public async focus(): Promise<void> {
3737
const firstEnabledItem = this.indexToElement.get(this.currentIndex);
3838
if (firstEnabledItem) {
39-
return delegateFocus(this.host!, () => setFocus(firstEnabledItem));
39+
return delegateFocus(this.host!, () => firstEnabledItem.focus());
4040
}
4141
}
4242

0 commit comments

Comments
 (0)