diff --git a/docs/pages/resources/changelog.md b/docs/pages/resources/changelog.md index c735fc5a7e..9964dcab77 100644 --- a/docs/pages/resources/changelog.md +++ b/docs/pages/resources/changelog.md @@ -27,6 +27,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti - Fixed a bug in `` where the tag size wouldn't update with the control's size [#1886] - Fixed a bug in `` and `` where the color of the required content wasn't applying correctly - Fixed a bug in `` where help text was incorrectly styled [#1897] +- Fixed a bug in `` that prevented the control from receiving focus when clicking over the clear button ## 2.14.0 diff --git a/src/components/input/input.component.ts b/src/components/input/input.component.ts index 8408396979..a672a8e06c 100644 --- a/src/components/input/input.component.ts +++ b/src/components/input/input.component.ts @@ -251,13 +251,16 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont } private handleClearClick(event: MouseEvent) { - this.value = ''; - this.emit('sl-clear'); - this.emit('sl-input'); - this.emit('sl-change'); - this.input.focus(); + event.preventDefault(); - event.stopPropagation(); + if (this.value !== '') { + this.value = ''; + this.emit('sl-clear'); + this.emit('sl-input'); + this.emit('sl-change'); + } + + this.input.focus(); } private handleFocus() { @@ -493,14 +496,11 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont @blur=${this.handleBlur} /> - ${hasClearIcon + ${isClearIconVisible ? html`