fix clear button clicks

This commit is contained in:
Cory LaViska
2024-03-06 08:30:25 -05:00
parent 7f87887477
commit 25b00281f4
3 changed files with 12 additions and 19 deletions

View File

@@ -24,6 +24,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
- Fixed a bug in `<sl-select>` where the tag size wouldn't update with the control's size [#1886]
- Fixed a bug in `<sl-checkbox>` and `<sl-switch>` where the color of the required content wasn't applying correctly
- Fixed a bug in `<sl-checkbox>` where help text was incorrectly styled [#1897]
- Fixed a bug in `<sl-input>` that prevented the control from receiving focus when clicking over the clear button
## 2.14.0

View File

@@ -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`
<button
part="clear-button"
class=${classMap({
input__clear: true,
'input__clear--visible': isClearIconVisible
})}
class="input__clear"
type="button"
aria-label=${this.localize.term('clearEntry')}
@click=${this.handleClearClick}

View File

@@ -247,10 +247,6 @@ export default css`
* Clearable + Password Toggle
*/
.input__clear:not(.input__clear--visible) {
visibility: hidden;
}
.input__clear,
.input__password-toggle {
display: inline-flex;
@@ -275,10 +271,6 @@ export default css`
outline: none;
}
.input--empty .input__clear {
visibility: hidden;
}
/* Don't show the browser's password toggle in Edge */
::-ms-reveal {
display: none;