@@ -276,6 +276,11 @@ export class Field extends LitElement {
276276 return ;
277277 }
278278
279+ const keyframes = this . getLabelKeyframes ( ) ;
280+ if ( ! keyframes . length ) {
281+ return ;
282+ }
283+
279284 this . isAnimating = true ;
280285 this . labelAnimation ?. cancel ( ) ;
281286
@@ -291,10 +296,10 @@ export class Field extends LitElement {
291296 // Re-calculating the animation each time will prevent any visual glitches
292297 // from appearing.
293298 // TODO(b/241113345): use animation tokens
294- this . labelAnimation = this . floatingLabelEl ?. animate (
295- this . getLabelKeyframes ( ) ,
296- { duration : 150 , easing : EASING . STANDARD } ,
297- ) ;
299+ this . labelAnimation = this . floatingLabelEl ?. animate ( keyframes , {
300+ duration : 150 ,
301+ easing : EASING . STANDARD ,
302+ } ) ;
298303
299304 this . labelAnimation ?. addEventListener ( 'finish' , ( ) => {
300305 // At the end of the animation, update the visible label.
@@ -320,6 +325,10 @@ export class Field extends LitElement {
320325 } = restingLabelEl . getBoundingClientRect ( ) ;
321326 const floatingScrollWidth = floatingLabelEl . scrollWidth ;
322327 const restingScrollWidth = restingLabelEl . scrollWidth ;
328+ // If either label has no dimensions (e.g., display: none), skip animation
329+ if ( floatingScrollWidth === 0 || restingScrollWidth === 0 ) {
330+ return [ ] ;
331+ }
323332 // Scale by width ratio instead of font size since letter-spacing will scale
324333 // incorrectly. Using the width we can better approximate the adjusted
325334 // scale and compensate for tracking and overflow.
0 commit comments