@@ -61,6 +61,9 @@ export type FloatLabelType = 'always' | 'auto';
6161/** Possible appearance styles for the form field. */
6262export type MatFormFieldAppearance = 'fill' | 'outline' ;
6363
64+ /** Behaviors for how the suffix height is set. */
65+ export type SuffixSizingBehavior = 'fixed' | 'dynamic' ;
66+
6467/**
6568 * Represents the default options for the form field that can be configured
6669 * using the `MAT_FORM_FIELD_DEFAULT_OPTIONS` injection token.
@@ -69,6 +72,7 @@ export interface MatFormFieldDefaultOptions {
6972 appearance ?: MatFormFieldAppearance ;
7073 hideRequiredMarker ?: boolean ;
7174 floatLabel ?: FloatLabelType ;
75+ suffixSizing ?: SuffixSizingBehavior ;
7276}
7377
7478/**
@@ -87,6 +91,9 @@ const DEFAULT_APPEARANCE: MatFormFieldAppearance = 'fill';
8791/** Default appearance used by the form-field. */
8892const DEFAULT_FLOAT_LABEL : FloatLabelType = 'auto' ;
8993
94+ /** Default way that the suffix element height is set. */
95+ const DEFAULT_SUFFIX_SIZING : SuffixSizingBehavior = 'fixed' ;
96+
9097/**
9198 * Default transform for docked floating labels in a MDC text-field. This value has been
9299 * extracted from the MDC text-field styles because we programmatically modify the docked
@@ -100,6 +107,11 @@ const FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM = `translateY(-50%)`;
100107 */
101108const WRAPPER_HORIZONTAL_PADDING = 16 ;
102109
110+ /** Height provided for each row of text when using dynamic suffix sizing. */
111+ const SUFFIX_ROW_HEIGHT = 16 ;
112+ /** Space added to dynamic suffix height if rows of text are present. */
113+ const SUFFIX_ROW_SPACER = 4 ;
114+
103115/** Container for form controls that applies Material Design styling and behavior. */
104116@Component ( {
105117 selector : 'mat-form-field' ,
@@ -206,6 +218,15 @@ export class MatFormField
206218 }
207219 private _appearance : MatFormFieldAppearance = DEFAULT_APPEARANCE ;
208220
221+ @Input ( )
222+ get suffixSizing ( ) : SuffixSizingBehavior {
223+ return this . _suffixSizing || this . _defaults ?. suffixSizing || DEFAULT_SUFFIX_SIZING ;
224+ }
225+ set suffixSizing ( value : SuffixSizingBehavior ) {
226+ this . _suffixSizing = value || this . _defaults ?. suffixSizing || DEFAULT_SUFFIX_SIZING ;
227+ }
228+ private _suffixSizing : SuffixSizingBehavior = DEFAULT_SUFFIX_SIZING ;
229+
209230 /** Text for the form field hint. */
210231 @Input ( )
211232 get hintLabel ( ) : string {
@@ -604,6 +625,18 @@ export class MatFormField
604625 : 'hint' ;
605626 }
606627
628+ /** Determines height of suffix when in dynamic suffix sizing mode. */
629+ _getDynamicSuffixHeight ( ) : number | null {
630+ if ( this . suffixSizing !== 'dynamic' ) return null ;
631+
632+ const numSuffixRows =
633+ this . _getDisplayedMessages ( ) === 'error'
634+ ? this . _errorChildren . length
635+ : Math . min ( this . _hintChildren . length , 1 ) ;
636+
637+ return numSuffixRows && numSuffixRows * SUFFIX_ROW_HEIGHT + SUFFIX_ROW_SPACER ;
638+ }
639+
607640 /** Refreshes the width of the outline-notch, if present. */
608641 _refreshOutlineNotchWidth ( ) {
609642 if ( ! this . _hasOutline ( ) || ! this . _floatingLabel ) {
0 commit comments