Skip to content

Commit

Permalink
fix(input): clear button display on focus (without hovering)
Browse files Browse the repository at this point in the history
Make sure to emit bqInput on clear action too.
  • Loading branch information
dgonzalezr committed Jul 19, 2023
1 parent 10fcdfa commit 3ebaf26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/bee-q/src/components/input/bq-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export class BqInput {
this.value = this.inputElem.value;

this.bqClear.emit(this.el);
this.bqInput.emit({ value: this.value, el: this.el });
this.bqChange.emit({ value: this.value, el: this.el });
this.inputElem.focus();

Expand Down Expand Up @@ -311,7 +312,7 @@ export class BqInput {
{/* Input control group */}
<div
class={{
'bq-input--control group': true,
'bq-input--control': true,
[`validation-${this.validationStatus}`]: true,
disabled: this.disabled,
}}
Expand Down Expand Up @@ -362,7 +363,7 @@ export class BqInput {
// The clear button will be visible as long as the input has a value
// and the parent group is hovered or has focus-within
<bq-button
class="bq-input--control__clear ms-[--bq-input--gap] hidden group-hover:inline-block group-[&:has(:focus-within)]:inline-block"
class="bq-input--control__clear ms-[--bq-input--gap] hidden"
appearance="text"
aria-label={this.clearButtonLabel}
size="small"
Expand Down
8 changes: 8 additions & 0 deletions packages/bee-q/src/components/input/scss/bq-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@

@apply focus border-[color:--bq-input--border-color-focus];
}

// Enable clear button whenever the input group control is hovered or has focus
&:not(.disabled):hover,
&:not(.disabled):focus-within {
.bq-input--control__clear {
@apply inline-block;
}
}
}

.bq-input--control.disabled {
Expand Down

0 comments on commit 3ebaf26

Please sign in to comment.