@@ -101,6 +101,13 @@ const DEFAULT_FLOAT_LABEL: FloatLabelType = 'auto';
101101/** Default way that the subscript element height is set. */
102102const DEFAULT_SUBSCRIPT_SIZING : SubscriptSizing = 'fixed' ;
103103
104+ /**
105+ * Default transform for docked floating labels in a MDC text-field. This value has been
106+ * extracted from the MDC text-field styles because we programmatically modify the docked
107+ * label transform, but do not want to accidentally discard the default label transform.
108+ */
109+ const FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM = `translateY(-50%)` ;
110+
104111/**
105112 * Horizontal padding in pixels used by the MDC for the wrapper containing infix.
106113 * This value is extracted from MDC's Sass variables. See `$padding-horizontal`.
@@ -669,8 +676,13 @@ export class MatFormField
669676 ( ( iconPrefixContainer ? iconPrefixContainerWidth - WRAPPER_HORIZONTAL_PADDING : 0 ) +
670677 textPrefixContainerWidth ) ;
671678
672- // Update the transform x of the floating label to account for the prefix container.
673- floatingLabel . style . transform = `var(--mat-mdc-form-field-label-transform, translateX(${ labelHorizontalOffset } px)` ;
679+ // Update the translateX of the floating label to account for the prefix container,
680+ // but allow the CSS to override this setting via a CSS variable when the label is
681+ // docked.
682+ floatingLabel . style . transform = `var(
683+ --mat-mdc-form-field-label-transform,
684+ ${ FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM } translateX(${ labelHorizontalOffset } px
685+ )` ;
674686 }
675687
676688 /** Checks whether the form field is attached to the DOM. */
0 commit comments