|
56 | 56 |
|
57 | 57 | // When the rows attribute is set, the container of the textarea should |
58 | 58 | // increase in height to accommodate the number of rows. |
59 | | -// The min-height should accommodate the number of rows, plus a little extra |
60 | | -// so that the next line is partially visible. To that we add the amount of |
61 | | -// the bottom padding and the border width outside the textarea. |
62 | | -// If --host-rows is set, then it will be used, otherwise the data-attr-rows |
63 | | -// attribute will be used. |
64 | | -.textarea-wrapper-inner[data-attr-rows] { |
65 | | - --number-rows: var(--host-rows, attr(data-attr-rows number)); |
66 | | - min-height: calc(var(--number-rows) * 1.2em + 1.5em + var(--padding-bottom, 0px) + var(--border-width, 0px)); |
| 59 | +:host([rows]) .textarea-wrapper-inner { |
| 60 | + /** |
| 61 | + * Clamp the minimum value to 1 to prevent 0 or negative heights. |
| 62 | + * Add 0.5 to show a half-line peek at the next row. |
| 63 | + */ |
| 64 | + --number-rows: calc(max(var(--host-rows, 1), 1) + 0.5); |
| 65 | + |
| 66 | + /** |
| 67 | + * Calculate the minimum height for the textarea container based on the number of rows. |
| 68 | + * - $textarea-row-line-height: Approximate height of a single line based on |
| 69 | + * the browser's default line-height: normal (~1.2 × font-size). |
| 70 | + * - (var(--number-rows) + 0.5): Show the requested rows plus a half-line peek |
| 71 | + * at the next row, hinting that the textarea is scrollable. |
| 72 | + * - var(--padding-top), var(--padding-bottom), var(--border-width): Account for |
| 73 | + * box-sizing: border-box, which includes padding and border in min-height. |
| 74 | + */ |
| 75 | + $textarea-row-line-height: 1.2em; |
| 76 | + |
| 77 | + min-height: calc( |
| 78 | + var(--number-rows) * #{$textarea-row-line-height} + var(--padding-top, 0px) + var(--padding-bottom, 0px) + var(--border-width, 0px) |
| 79 | + ); |
67 | 80 | } |
68 | 81 |
|
69 | 82 | // Ionic Textarea Shapes |
|
0 commit comments