Skip to content

Commit

Permalink
Add option to hide clear button in single-select (#7434)
Browse files Browse the repository at this point in the history
  • Loading branch information
laske185 authored Mar 4, 2025
2 parents ffc0243 + 8299064 commit f762450
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ export class SingleSelectController extends InputIconController implements Singl
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 @@ -232,7 +232,7 @@ export class KolSingleSelect implements SingleSelectAPI {
<div class="kol-single-select__group">
<KolInputStateWrapperFc {...this.getInputProps()} />

{this._inputValue && (
{this._inputValue && !this.state._hideClearButton && (
<KolIconTag
_icons="codicon codicon-close"
_label={translate('kol-delete-selection')}
Expand Down Expand Up @@ -504,11 +504,17 @@ export class KolSingleSelect implements SingleSelectAPI {
*/
@Prop({ mutable: true, reflect: true }) public _value?: string;

/**
* Defines the whether the clear button should be hidden.
*/
@Prop() public _hideClearButton?: boolean = false;

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

@State() private inputHasFocus = false;
Expand Down Expand Up @@ -615,6 +621,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 @@ -26,6 +26,7 @@ type OptionalProps = {
on: InputTypeOnDefault;
placeholder: string;
value: string;
hideClearButton: boolean;
} & PropAccessKey &
PropDisabled &
PropHideMsg &
Expand All @@ -46,6 +47,7 @@ type OptionalStates = {
icons: KoliBriHorizontalIcons;
on: InputTypeOnDefault;
placeholder: string;
hideClearButton: boolean;
} & PropAccessKey &
PropDisabled &
PropHideLabel &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const SingleSelectCases = (props: Components.KolSingleSelect) => {
<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 long labels" _options={LONG_OPTIONS as Option<StencilUnknown>[]} _placeholder="Placeholder" />
<KolSingleSelect {...props} _label="With hidden clear button" _options={COUNTRY_OPTIONS as Option<StencilUnknown>[]} _value={'de'} _hideClearButton />
</div>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f762450

Please sign in to comment.