@@ -61,6 +61,9 @@ export type FloatLabelType = 'always' | 'auto';
61
61
/** Possible appearance styles for the form field. */
62
62
export type MatFormFieldAppearance = 'fill' | 'outline' ;
63
63
64
+ /** Behaviors for how the suffix height is set. */
65
+ export type SuffixSizingBehavior = 'fixed' | 'dynamic' ;
66
+
64
67
/**
65
68
* Represents the default options for the form field that can be configured
66
69
* using the `MAT_FORM_FIELD_DEFAULT_OPTIONS` injection token.
@@ -69,6 +72,7 @@ export interface MatFormFieldDefaultOptions {
69
72
appearance ?: MatFormFieldAppearance ;
70
73
hideRequiredMarker ?: boolean ;
71
74
floatLabel ?: FloatLabelType ;
75
+ suffixSizing ?: SuffixSizingBehavior ;
72
76
}
73
77
74
78
/**
@@ -87,6 +91,9 @@ const DEFAULT_APPEARANCE: MatFormFieldAppearance = 'fill';
87
91
/** Default appearance used by the form-field. */
88
92
const DEFAULT_FLOAT_LABEL : FloatLabelType = 'auto' ;
89
93
94
+ /** Default way that the suffix element height is set. */
95
+ const DEFAULT_SUFFIX_SIZING : SuffixSizingBehavior = 'fixed' ;
96
+
90
97
/**
91
98
* Default transform for docked floating labels in a MDC text-field. This value has been
92
99
* 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%)`;
100
107
*/
101
108
const WRAPPER_HORIZONTAL_PADDING = 16 ;
102
109
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
+
103
115
/** Container for form controls that applies Material Design styling and behavior. */
104
116
@Component ( {
105
117
selector : 'mat-form-field' ,
@@ -206,6 +218,15 @@ export class MatFormField
206
218
}
207
219
private _appearance : MatFormFieldAppearance = DEFAULT_APPEARANCE ;
208
220
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
+
209
230
/** Text for the form field hint. */
210
231
@Input ( )
211
232
get hintLabel ( ) : string {
@@ -604,6 +625,18 @@ export class MatFormField
604
625
: 'hint' ;
605
626
}
606
627
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
+
607
640
/** Refreshes the width of the outline-notch, if present. */
608
641
_refreshOutlineNotchWidth ( ) {
609
642
if ( ! this . _hasOutline ( ) || ! this . _floatingLabel ) {
0 commit comments