@@ -114,12 +114,6 @@ const DEFAULT_SUBSCRIPT_SIZING: SubscriptSizing = 'fixed';
114
114
*/
115
115
const FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM = `translateY(-50%)` ;
116
116
117
- /**
118
- * Horizontal padding in pixels used by the MDC for the wrapper containing infix.
119
- * This value is extracted from MDC's Sass variables. See `$padding-horizontal`.
120
- */
121
- const WRAPPER_HORIZONTAL_PADDING = 16 ;
122
-
123
117
/** Container for form controls that applies Material Design styling and behavior. */
124
118
@Component ( {
125
119
selector : 'mat-form-field' ,
@@ -669,19 +663,17 @@ export class MatFormField
669
663
const textPrefixContainerWidth = textPrefixContainer ?. getBoundingClientRect ( ) . width ?? 0 ;
670
664
// If the directionality is RTL, the x-axis transform needs to be inverted. This
671
665
// is because `transformX` does not change based on the page directionality.
672
- const labelHorizontalOffset =
673
- ( this . _dir . value === 'rtl' ? - 1 : 1 ) *
674
- // If there's an icon prefix, we subtract the default horizontal padding as we
675
- // reset the horizontal padding in CSS too.
676
- ( ( iconPrefixContainer ? iconPrefixContainerWidth - WRAPPER_HORIZONTAL_PADDING : 0 ) +
677
- textPrefixContainerWidth ) ;
666
+ const negate = this . _dir . value === 'rtl' ? '-1' : '1' ;
667
+ const prefixWidth = `${ iconPrefixContainerWidth + textPrefixContainerWidth } px` ;
668
+ const labelOffset = `var(--mat-mdc-form-field-label-offset-x, 0px)` ;
669
+ const labelHorizontalOffset = `calc(${ negate } * (${ prefixWidth } + ${ labelOffset } ))` ;
678
670
679
671
// Update the translateX of the floating label to account for the prefix container,
680
672
// but allow the CSS to override this setting via a CSS variable when the label is
681
673
// floating.
682
674
floatingLabel . style . transform = `var(
683
675
--mat-mdc-form-field-label-transform,
684
- ${ FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM } translateX(${ labelHorizontalOffset } px
676
+ ${ FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM } translateX(${ labelHorizontalOffset } )
685
677
)` ;
686
678
}
687
679
0 commit comments