Skip to content

Commit ff4fe33

Browse files
authored
Fix: Clear button causes crash in Singleselect (#8035)
2 parents 6886a83 + ffd2be4 commit ff4fe33

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { tryToDispatchKoliBriEvent } from '../../utils/events';
2929
import { getRenderStates } from '../input/controller';
3030
import { InternalUnderlinedBadgeText } from '../span/InternalUnderlinedBadgeText';
3131
import { SingleSelectController } from './controller';
32+
import { EventDetail } from '../../schema/interfaces/EventDetail';
3233

3334
/**
3435
* @slot - The input field label.
@@ -104,13 +105,21 @@ export class KolSingleSelect implements SingleSelectAPI {
104105
if (this.state._disabled) {
105106
return;
106107
} else {
107-
const emptyValue = '';
108+
const emptyValue = null;
108109
this._focusedOptionIndex = -1;
109110
this._value = emptyValue;
110-
this._inputValue = emptyValue;
111+
this._inputValue = '';
111112
this._filteredOptions = [...this.state._options];
112-
this.controller.onFacade.onInput(new CustomEvent('input', { bubbles: true, detail: { name: this.state._name, value: emptyValue } }), true, emptyValue);
113-
this.controller.onFacade.onChange(new CustomEvent('change', { bubbles: true, detail: { name: this.state._name, value: emptyValue } }), emptyValue);
113+
114+
this.controller.onFacade.onInput(
115+
new CustomEvent<EventDetail>('input', { bubbles: true, detail: { name: this.state._name as string, value: emptyValue } }),
116+
true,
117+
{ value: emptyValue },
118+
);
119+
this.controller.onFacade.onChange(
120+
new CustomEvent<EventDetail>('change', { bubbles: true, detail: { name: this.state._name as string, value: emptyValue } }),
121+
{ value: emptyValue },
122+
);
114123
}
115124
}
116125

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { StencilUnknown } from '../types';
2+
3+
export interface EventDetail {
4+
name: string;
5+
value: StencilUnknown;
6+
}

0 commit comments

Comments
 (0)