Skip to content

Commit

Permalink
Add option to hide clear button in single-select
Browse files Browse the repository at this point in the history
Refs: #7405
  • Loading branch information
anicyne committed Feb 28, 2025
1 parent 14d988f commit 8faa887
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ export class SingleSelectController extends InputIconController implements Singl
public validatePlaceholder(value?: string): void {
watchString(this.component, '_placeholder', value);
}

public validateHideClearButton(value?: boolean): void {
watchBoolean(this.component, '_hideClearButton', value);
}
public componentWillLoad(): void {
super.componentWillLoad();
this.validateOptions(this.component._options);
this.validateRequired(this.component._required);
this.validateValue(this.component._value);
this.validatePlaceholder(this.component._placeholder);
this.validateHideClearButton(this.component._hideClearButton);
}
}
13 changes: 12 additions & 1 deletion packages/components/src/components/single-select/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class KolSingleSelect implements SingleSelectAPI {
}}
placeholder={this.state._placeholder}
/>
{this._inputValue && (
{this._inputValue && !this._hideClearButton && (
<KolIconTag
_icons="codicon codicon-close"
_label={translate('kol-delete-selection')}
Expand Down Expand Up @@ -552,12 +552,18 @@ export class KolSingleSelect implements SingleSelectAPI {
*/
@Prop({ mutable: true }) public _value?: string;

/**
* Defines the value of the input.
*/
@Prop() public _hideClearButton?: boolean = false;

@State() public state: SingleSelectStates = {
_hideError: false,
_id: `id-${nonce()}`,
_label: '', // ⚠ required
_options: [],
_value: '',
_hideClearButton: false,
};

@State() private inputHasFocus = false;
Expand Down Expand Up @@ -677,6 +683,11 @@ export class KolSingleSelect implements SingleSelectAPI {
this.updateInputValue(value);
}

@Watch('_hideClearButton ')
public validateHideClearButton(value?: boolean): void {
this.controller.validateHideClearButton(value);
}

@Listen('mousemove')
public handleMouseEvent() {
this.blockSuggestionMouseOver = false;
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/schema/components/single-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type OptionalProps = {
placeholder: string;
tabIndex: number;
value: string;
hideClearButton: boolean;
} & PropAccessKey &
PropDisabled &
PropHideError &
Expand All @@ -50,6 +51,7 @@ type OptionalStates = {
on: InputTypeOnDefault;
tabIndex: number;
placeholder: string;
hideClearButton: boolean;
} & PropAccessKey &
PropDisabled &
PropHideLabel &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const SingleSelectCases = forwardRef<HTMLKolSingleSelectElement, Componen
/>
<KolSingleSelect {...props} _label="With access key" _options={COUNTRY_OPTIONS as Option<StencilUnknown>[]} _value={'de'} _accessKey="c" />
<KolSingleSelect {...props} _label="With short key" _options={COUNTRY_OPTIONS as Option<StencilUnknown>[]} _value={'de'} _shortKey="s" />
<KolSingleSelect {...props} _label="With hidden clear button" _options={COUNTRY_OPTIONS as Option<StencilUnknown>[]} _value={'de'} _hideClearButton />
</div>
);
});

0 comments on commit 8faa887

Please sign in to comment.