Toggle visibility of the clear button (#1496)

This commit is contained in:
Tomas Drencak
2023-08-09 21:28:30 +02:00
committed by GitHub
parent 31ef2f7929
commit bf15f2fb8a

View File

@@ -407,7 +407,9 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont
const hasLabel = this.label ? true : !!hasLabelSlot;
const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
const hasClearIcon =
this.clearable && !this.disabled && !this.readonly && (typeof this.value === 'number' || this.value.length > 0);
this.clearable && !this.disabled && !this.readonly;
const hasClearIconVisible =
hasClearIcon && (typeof this.value === 'number' || this.value.length > 0);
return html`
<div
@@ -497,6 +499,7 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont
type="button"
aria-label=${this.localize.term('clearEntry')}
@click=${this.handleClearClick}
style="visibility: ${hasClearIconVisible?'visible':'hidden'}"
tabindex="-1"
>
<slot name="clear-icon">