Skip to content

Commit

Permalink
fix(textfield): don't transition colors when disabling
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 561801775
  • Loading branch information
asyncLiz authored and Copybara-Service committed Sep 1, 2023
1 parent d6aa6b2 commit 11cc472
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions field/internal/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ $_enter-delay: $_label-duration - $_visible-duration;
transition-delay: $_enter-delay;
}

:is(.disabled, .disable-transitions) .content {
transition: none;
}

.content ::slotted(*) {
all: unset;
// Use `currentColor` to inherit the various state colors that are set
Expand Down
12 changes: 12 additions & 0 deletions field/internal/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class Field extends LitElement implements SurfacePositionTarget {
* to screen readers.
*/
@state() private refreshErrorAlert = false;
@state() private disableTransitions = false;
@query('.label.floating') private readonly floatingLabelEl!: HTMLElement|null;
@query('.label.resting') private readonly restingLabelEl!: HTMLElement|null;
@query('.container') private readonly containerEl!: HTMLElement|null;
Expand All @@ -76,6 +77,10 @@ export class Field extends LitElement implements SurfacePositionTarget {

protected override update(props: PropertyValues<Field>) {
// Client-side property updates
const isDisabledChanging = props.has('disabled') && props.get('disabled') !== undefined;
if (isDisabledChanging) {
this.disableTransitions = true;
}

// When disabling, remove focus styles if focused.
if (this.disabled && this.focused) {
Expand All @@ -98,6 +103,7 @@ export class Field extends LitElement implements SurfacePositionTarget {
const outline = this.renderOutline?.(floatingLabel);
const classes = {
'disabled': this.disabled,
'disable-transitions': this.disableTransitions,
'error': this.error && !this.disabled,
'focused': this.focused,
'with-start': this.hasStart,
Expand Down Expand Up @@ -149,6 +155,12 @@ export class Field extends LitElement implements SurfacePositionTarget {
this.refreshErrorAlert = false;
});
}

if (this.disableTransitions) {
requestAnimationFrame(() => {
this.disableTransitions = false;
});
}
}

protected renderBackground?(): TemplateResult;
Expand Down

0 comments on commit 11cc472

Please sign in to comment.