|
| 1 | +@import '@material/notched-outline/variables.import'; |
| 2 | +@import '@material/textfield/variables.import'; |
1 | 3 | @import 'form-field-sizing'; |
2 | 4 |
|
3 | 5 | // Mixin that can be included to override the default MDC text-field |
|
29 | 31 | // spacing as we support arbitrary form-field controls which aren't necessarily matching |
30 | 32 | // the "mdc-text-field__input" class. Note: We need the first selector to overwrite the |
31 | 33 | // default no-label MDC padding styles which are set with a very high specificity. |
32 | | - .mdc-text-field--no-label:not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) |
| 34 | + .mdc-text-field--no-label:not(.mdc-text-field--textarea) |
33 | 35 | .mat-mdc-input-element.mdc-text-field__input, |
34 | | - .mat-mdc-input-element { |
| 36 | + .mat-mdc-text-field-wrapper .mat-mdc-input-element { |
35 | 37 | padding: 0; |
36 | 38 | } |
37 | 39 |
|
38 | | - // MDC changes the vertical spacing of the input if there is no label. Since we moved |
39 | | - // the spacing of the input to the parent infix container (to support custom controls), |
40 | | - // we need to replicate these styles for the infix container. The goal is that the input |
41 | | - // placeholder vertically aligns with floating labels of other filled inputs. Note that |
42 | | - // outline appearance currently still relies on the input spacing due to a notched-outline |
43 | | - // limitation. TODO: https://github.com/material-components/material-components-web/issues/5326 |
44 | | - .mdc-text-field--no-label:not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) |
45 | | - .mat-mdc-form-field-infix { |
46 | | - padding-top: $mat-form-field-no-label-padding-top; |
47 | | - padding-bottom: $mat-form-field-no-label-padding-bottom; |
48 | | - } |
49 | | - |
50 | 40 | // MDC adds vertical spacing to inputs. We removed this spacing and intend to add it |
51 | 41 | // to the infix container. This is necessary to ensure that custom form-field controls |
52 | | - // also have the proper Material Design spacing to the label and bottom-line. Note that |
53 | | - // outline appearance currently still relies on the input spacing due to a notched-outline |
54 | | - // limitation. TODO: https://github.com/material-components/material-components-web/issues/5326 |
55 | | - .mat-mdc-text-field-wrapper:not(.mdc-text-field--outlined) .mat-mdc-form-field-infix { |
| 42 | + // also have the proper Material Design spacing to the label and bottom-line. |
| 43 | + .mat-mdc-text-field-wrapper .mat-mdc-form-field-infix { |
56 | 44 | // Apply the default text-field input padding to the infix container. We removed the |
57 | 45 | // padding from the input elements in order to support arbitrary form-field controls. |
58 | 46 | padding-top: $mat-form-field-with-label-input-padding-top; |
59 | 47 | padding-bottom: $mat-form-field-with-label-input-padding-bottom; |
60 | 48 | } |
61 | 49 |
|
| 50 | + // MDC changes the vertical spacing of the input if there is no label, or in the outline |
| 51 | + // appearance. This is because the input should vertically align with other inputs which use |
| 52 | + // a floating label. To achieve this, we add custom vertical spacing to the infix container |
| 53 | + // that differs from the vertical spacing for text-field's with a floating label. |
| 54 | + .mdc-text-field--no-label:not(.mdc-text-field--textarea) .mat-mdc-form-field-infix, |
| 55 | + .mat-mdc-text-field-wrapper.mdc-text-field--outlined .mat-mdc-form-field-infix { |
| 56 | + padding-top: $mat-form-field-no-label-padding-top; |
| 57 | + padding-bottom: $mat-form-field-no-label-padding-bottom; |
| 58 | + } |
| 59 | + |
62 | 60 | // Root element of the mdc-text-field. As explained in the height overwrites above, MDC |
63 | 61 | // sets a default height on the text-field root element. This is not desired since we |
64 | 62 | // want the element to be able to expand as needed. |
|
79 | 77 | opacity: 1; |
80 | 78 | } |
81 | 79 |
|
82 | | - // The additional nesting is a temporary until the notched-outline is decoupled from the |
83 | | - // floating label. See https://github.com/material-components/material-components-web/issues/5326 |
84 | | - // TODO(devversion): Remove this workaround/nesting once the feature is available. |
85 | | - .mat-mdc-text-field-wrapper:not(.mdc-text-field--outlined) { |
86 | | - // We removed the horizontal inset on input elements, but need to re-add the spacing to |
87 | | - // the actual form-field flex container that contains the prefixes, suffixes and infix. |
88 | | - .mat-mdc-form-field-flex { |
89 | | - padding: 0 $mdc-text-field-input-padding; |
90 | | - } |
| 80 | + // We removed the horizontal inset on input elements, but need to re-add the spacing to |
| 81 | + // the actual form-field flex container that contains the prefixes, suffixes and infix. |
| 82 | + .mat-mdc-text-field-wrapper .mat-mdc-form-field-flex { |
| 83 | + padding: 0 $mdc-text-field-input-padding; |
| 84 | + } |
| 85 | + |
| 86 | + // Since we moved the horizontal spacing from the input to the form-field flex container |
| 87 | + // and the MDC floating label tries to account for the horizontal spacing, we need to reset |
| 88 | + // the shifting since there is no padding the label needs to account for. Note that we do not |
| 89 | + // want do this for labels in the notched-outline since MDC keeps those labels relative to |
| 90 | + // the notched outline container, and already applies a specific horizontal spacing which |
| 91 | + // we do not want to overwrite. |
| 92 | + .mat-mdc-form-field-infix .mdc-floating-label { |
| 93 | + left: 0; |
| 94 | + right: 0; |
| 95 | + } |
91 | 96 |
|
92 | | - // Since we moved the horizontal spacing from the input to the form-field flex container |
93 | | - // and the MDC floating label tries to account for the horizontal spacing, we need to reset |
94 | | - // the shifting since there is no padding the label needs to account for. |
95 | | - .mdc-floating-label { |
96 | | - left: 0; |
97 | | - } |
| 97 | + // For the outline appearance, we re-create the active floating label transform. This is |
| 98 | + // necessary because the transform for docked floating labels can be updated to account for |
| 99 | + // the width of prefix container. We need to re-create these styles with `!important` because |
| 100 | + // the horizontal adjustment for the label is applied through inline styles, and we want to |
| 101 | + // make sure that the label can still float as expected. It should be okay using `!important` |
| 102 | + // because it's unlikely that developers commonly overwrite the floating label transform. |
| 103 | + .mat-mdc-text-field-wrapper.mdc-text-field--outlined .mdc-floating-label--float-above { |
| 104 | + // This transform has been extracted from the MDC text-field styles. We can't access it |
| 105 | + // through a variable because MDC generates this label transform through a mixin. |
| 106 | + transform: translateY(-$mdc-text-field-outlined-label-position-y) scale(0.75) !important; |
98 | 107 | } |
99 | 108 |
|
100 | 109 | // MDC sets the input elements in outline appearance to "display: flex". There seems to |
|
0 commit comments