Skip to content

Commit d755d10

Browse files
asynclizcopybara-github
authored andcommitted
fix(text-field): remove indicator expansion animation
PiperOrigin-RevId: 512117352
1 parent 828d7ae commit d755d10

File tree

5 files changed

+21
-181
lines changed

5 files changed

+21
-181
lines changed

field/lib/_content.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
//
55

66
// go/keep-sorted start
7+
@use 'sass:map';
78
@use 'sass:math';
89
// go/keep-sorted end
910
// go/keep-sorted start
10-
@use '../../motion/animation';
11+
@use '../../tokens';
1112
// go/keep-sorted end
1213

14+
$_md-sys-motion: tokens.md-sys-motion-values();
1315
// Duration of the label animation.
14-
$_label-duration: 150ms;
16+
$_label-duration: map.get($_md-sys-motion, 'duration-short3');
1517
// Duration of the content's visibility animation.
1618
$_visible-duration: math.round(math.div($_label-duration * 5, 9));
1719
// Short delay when entering (focusing/populating) so that the label may move
@@ -52,7 +54,8 @@ $_enter-delay: $_label-duration - $_visible-duration;
5254
display: flex;
5355
flex: 1;
5456
opacity: 0;
55-
transition: animation.standard(opacity, $_visible-duration);
57+
transition: opacity $_visible-duration
58+
map.get($_md-sys-motion, 'easing-emphasized');
5659
// Content elements provided to the field (such as <input>) may use
5760
// `currentColor` to inherit this property.
5861
color: var(--_content-color);

field/lib/_filled-field.scss

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
@use 'sass:map';
88
// go/keep-sorted end
99
// go/keep-sorted start
10-
@use '../../motion/animation';
1110
@use '../../sass/shape';
1211
@use '../../sass/theme';
12+
@use '../../tokens';
1313
@use './md-comp-filled-field';
1414
// go/keep-sorted end
1515

16-
$_animation-duration: 150ms;
16+
$_md-sys-motion: tokens.md-sys-motion-values();
1717

1818
@mixin theme($tokens) {
1919
$reference: md-comp-filled-field.values();
@@ -82,9 +82,9 @@ $_animation-duration: 150ms;
8282
}
8383

8484
.active-indicator {
85+
inset: auto 0 0 0;
8586
// Prevent click events on the indicator element since it has no width and
8687
// causes bugs when handled by the foundation for updating transform-origin.
87-
inset: auto 0 0 0;
8888
pointer-events: none;
8989
position: absolute;
9090
width: 100%;
@@ -102,23 +102,13 @@ $_animation-duration: 150ms;
102102
// focused indicator
103103
&::after {
104104
opacity: 0;
105-
transform: scaleX(0);
106-
// The element needs to update the transform-origin style attribute in
107-
// response to click events. Psuedo elements cannot have their style
108-
// updated, but their transform-origin can be inherited.
109-
transform-origin: inherit;
110-
// Add two transitions: opacity and a delayed transform. With a non-delayed
111-
// transform transition on the focus selector without an opacity transition,
112-
// this will result in the indicator scaling on enter and fading on exit.
113-
transition: animation.standard(opacity, $_animation-duration),
114-
transform 0s ease $_animation-duration;
105+
transition: opacity map.get($_md-sys-motion, 'duration-short3')
106+
map.get($_md-sys-motion, 'easing-emphasized');
115107
}
116108
}
117109

118110
.focused .active-indicator::after {
119111
opacity: 1;
120-
transform: scaleX(1);
121-
transition: animation.standard(transform, $_animation-duration);
122112
}
123113

124114
.field:not(.with-start) .start {

field/lib/_outlined-field.scss

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
@use 'sass:map';
88
// go/keep-sorted end
99
// go/keep-sorted start
10-
@use '../../motion/animation';
1110
@use '../../sass/shape';
1211
@use '../../sass/theme';
12+
@use '../../tokens';
1313
@use './md-comp-outlined-field';
1414
// go/keep-sorted end
1515

16-
$_animation-duration: 150ms;
16+
$_md-sys-motion: tokens.md-sys-motion-values();
1717

1818
@mixin theme($tokens) {
1919
$reference: md-comp-outlined-field.values();
@@ -77,7 +77,8 @@ $_animation-duration: 150ms;
7777

7878
&::after {
7979
opacity: 0;
80-
transition: animation.standard(opacity, $_animation-duration);
80+
transition: opacity map.get($_md-sys-motion, 'duration-short3')
81+
map.get($_md-sys-motion, 'easing-emphasized');
8182
}
8283
}
8384

@@ -142,7 +143,8 @@ $_animation-duration: 150ms;
142143
border-bottom: none;
143144
bottom: auto;
144145
transform: scaleX(1);
145-
transition: animation.standard(transform, $_animation-duration);
146+
transition: transform map.get($_md-sys-motion, 'duration-short3')
147+
map.get($_md-sys-motion, 'easing-emphasized');
146148
}
147149

148150
// Note: no need to do any RTL flipping here. If RTLCSS flips this, it's also
@@ -170,7 +172,8 @@ $_animation-duration: 150ms;
170172

171173
.outline-panel-active {
172174
opacity: 0;
173-
transition: animation.standard(opacity, $_animation-duration);
175+
transition: opacity map.get($_md-sys-motion, 'duration-short3')
176+
map.get($_md-sys-motion, 'easing-emphasized');
174177
}
175178

176179
.focused .outline-panel-active {

field/lib/filled-field.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,21 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {html, PropertyValues} from 'lit';
8-
import {state} from 'lit/decorators.js';
9-
import {styleMap} from 'lit/directives/style-map.js';
7+
import {html} from 'lit';
108

119
import {Field} from './field.js';
1210

1311
/**
1412
* A filled field component.
1513
*/
1614
export class FilledField extends Field {
17-
@state() private strokeTransformOrigin = '';
18-
19-
constructor() {
20-
super();
21-
this.addEventListener('click', event => {
22-
if (!this.disabled) {
23-
this.updateStrokeTransformOrigin(event);
24-
}
25-
});
26-
}
27-
2815
protected override renderBackground() {
2916
return html`
3017
<div class="state-layer"></div>
3118
`;
3219
}
3320

3421
protected override renderIndicator() {
35-
const strokeStyle = {transformOrigin: this.strokeTransformOrigin};
36-
return html`
37-
<div class="active-indicator" style="${styleMap(strokeStyle)}"></div>
38-
`;
39-
}
40-
41-
protected override update(props: PropertyValues<FilledField>) {
42-
// Upon losing focus, the stroke resets to expanding from the center, such
43-
// as when re-focusing with a keyboard.
44-
const unfocusing = props.has('focused') && !this.focused;
45-
if (unfocusing) {
46-
this.updateStrokeTransformOrigin();
47-
}
48-
49-
super.update(props);
50-
}
51-
52-
private updateStrokeTransformOrigin(event?: MouseEvent|TouchEvent) {
53-
let transformOrigin = '';
54-
if (event) {
55-
// Can't use instanceof TouchEvent since Firefox does not provide the
56-
// constructor globally.
57-
const isTouchEvent = 'touches' in event;
58-
const eventX = isTouchEvent ? event.touches[0].clientX : event.clientX;
59-
const rootRect = this.getBoundingClientRect();
60-
transformOrigin = `${eventX - rootRect.x}px`;
61-
}
62-
63-
this.strokeTransformOrigin = transformOrigin;
22+
return html`<div class="active-indicator"></div>`;
6423
}
6524
}

field/lib/filled-field_test.ts

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)