-
Notifications
You must be signed in to change notification settings - Fork 13.4k
style(textarea): adjusting min-height of the element #30950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
4620d25
2ef9d30
fcc4bf4
4062300
228df5f
df337e8
0d7441e
f205099
631cea2
13f92b3
6398b20
44984f9
9ad8705
223ce69
d65d117
0be00d5
dd58785
791a201
bf9c315
239488f
10b94bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,6 +539,17 @@ | |
| opacity: 1; | ||
| } | ||
|
|
||
| /** | ||
| * When the rows attribute is set, the textarea should not force a min-height, | ||
| * but rather respect the natural height of the textarea, especially when | ||
| * rows is set to 1. | ||
| */ | ||
| :host(.textarea-fill-outline.sc-ion-textarea-md-h[rows]), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As Copolit mentioned, we shouldn't be targeting generated classes. This should be moved into the |
||
| :host(.textarea-label-placement-stacked[rows]), | ||
| :host(.textarea-label-placement-floating[rows]) { | ||
| min-height: auto; | ||
| } | ||
|
|
||
| // Start / End Slots | ||
| // ---------------------------------------------------------------- | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,26 +38,45 @@ | |||||||||||||||||||||||||||||||||||
| --padding-end: #{globals.$ion-space-300}; | ||||||||||||||||||||||||||||||||||||
| --padding-bottom: #{globals.$ion-space-200}; | ||||||||||||||||||||||||||||||||||||
| --padding-start: #{globals.$ion-space-300}; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| min-height: globals.$ion-scale-2800; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| :host(.textarea-size-medium) .textarea-wrapper-inner { | ||||||||||||||||||||||||||||||||||||
| --padding-top: #{globals.$ion-space-300}; | ||||||||||||||||||||||||||||||||||||
| --padding-end: #{globals.$ion-space-400}; | ||||||||||||||||||||||||||||||||||||
| --padding-bottom: #{globals.$ion-space-300}; | ||||||||||||||||||||||||||||||||||||
| --padding-start: #{globals.$ion-space-400}; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| min-height: globals.$ion-scale-3400; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| :host(.textarea-size-large) .textarea-wrapper-inner { | ||||||||||||||||||||||||||||||||||||
| --padding-top: #{globals.$ion-space-400}; | ||||||||||||||||||||||||||||||||||||
| --padding-end: #{globals.$ion-space-500}; | ||||||||||||||||||||||||||||||||||||
| --padding-bottom: #{globals.$ion-space-400}; | ||||||||||||||||||||||||||||||||||||
| --padding-start: #{globals.$ion-space-500}; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // When the rows attribute is set, the container of the textarea should | ||||||||||||||||||||||||||||||||||||
| // increase in height to accommodate the number of rows. | ||||||||||||||||||||||||||||||||||||
| :host([rows]) .textarea-wrapper-inner { | ||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
| * Clamp the minimum value to 1 to prevent 0 or negative heights. | ||||||||||||||||||||||||||||||||||||
| * Add 0.5 to show a half-line peek at the next row. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| --number-rows: calc(max(var(--host-rows, 1), 1) + 0.5); | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to accomplish the styling without creating new CSS variables? |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| min-height: globals.$ion-scale-3600; | ||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
| * Calculate the minimum height for the textarea container based on the number of rows. | ||||||||||||||||||||||||||||||||||||
| * - $textarea-row-line-height: Approximate height of a single line based on | ||||||||||||||||||||||||||||||||||||
| * the browser's default line-height: normal (~1.2 × font-size). | ||||||||||||||||||||||||||||||||||||
| * - (var(--number-rows) + 0.5): Show the requested rows plus a half-line peek | ||||||||||||||||||||||||||||||||||||
| * at the next row, hinting that the textarea is scrollable. | ||||||||||||||||||||||||||||||||||||
| * - var(--padding-top), var(--padding-bottom), var(--border-width): Account for | ||||||||||||||||||||||||||||||||||||
| * box-sizing: border-box, which includes padding and border in min-height. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| $textarea-row-line-height: 1.2em; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| min-height: calc( | ||||||||||||||||||||||||||||||||||||
| var(--number-rows) * #{$textarea-row-line-height} + var(--padding-top, 0px) + var(--padding-bottom, 0px) + var(--border-width, 0px) | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Ionic Textarea Shapes | ||||||||||||||||||||||||||||||||||||
|
|
@@ -90,13 +109,17 @@ | |||||||||||||||||||||||||||||||||||
| // ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // The height should be auto only when auto-grow is enabled. | ||||||||||||||||||||||||||||||||||||
| :host([auto-grow]) .textarea-wrapper-inner { | ||||||||||||||||||||||||||||||||||||
| // If rows is not set, the height should be auto. | ||||||||||||||||||||||||||||||||||||
| :host(:not([rows])) .textarea-wrapper-inner, | ||||||||||||||||||||||||||||||||||||
| :host([auto-grow]:not([auto-grow="false"])) .textarea-wrapper-inner { | ||||||||||||||||||||||||||||||||||||
| height: auto; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
111
to
115
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // The min and max height should be inherited if auto-grow is enabled. | ||||||||||||||||||||||||||||||||||||
| // This allows the textarea to grow and shrink as needed. | ||||||||||||||||||||||||||||||||||||
| :host([auto-grow]) .native-wrapper { | ||||||||||||||||||||||||||||||||||||
| // If rows is not set, the height should be auto. | ||||||||||||||||||||||||||||||||||||
| :host(:not([rows])) .native-wrapper, | ||||||||||||||||||||||||||||||||||||
| :host([auto-grow]:not([auto-grow="false"])) .native-wrapper { | ||||||||||||||||||||||||||||||||||||
| min-height: inherit; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
111
to
123
|
||||||||||||||||||||||||||||||||||||
| max-height: inherit; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -276,3 +299,12 @@ ion-icon { | |||||||||||||||||||||||||||||||||||
| min-width: $text-wrapper-width; | ||||||||||||||||||||||||||||||||||||
| max-width: globals.$ion-scale-5000; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||
| * As the ionic theme introduces padding in the textarea, | ||||||||||||||||||||||||||||||||||||
| * there is no need to add margin-top to the textarea. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| :host(.textarea-label-placement-stacked) textarea, | ||||||||||||||||||||||||||||||||||||
| :host(.textarea-label-placement-floating) textarea { | ||||||||||||||||||||||||||||||||||||
| margin-top: 0; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+305
to
+309
|
||||||||||||||||||||||||||||||||||||
| * there is no need to add margin-top to the textarea. | |
| */ | |
| :host(.textarea-label-placement-stacked) textarea, | |
| :host(.textarea-label-placement-floating) textarea { | |
| margin-top: 0; | |
| * there is no need to add margin-top to the textarea. | |
| * We also need to keep the auto-grow pseudo-element spacing | |
| * in sync with the textarea spacing. | |
| */ | |
| :host(.textarea-label-placement-stacked) textarea, | |
| :host(.textarea-label-placement-floating) textarea { | |
| margin-top: 0; | |
| } | |
| :host(.textarea-label-placement-stacked) .native-wrapper::after, | |
| :host(.textarea-label-placement-floating) .native-wrapper::after { | |
| margin-top: 0; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -893,6 +893,10 @@ export class Textarea implements ComponentInterface { | |
| 'textarea-disabled': disabled, | ||
| 'textarea-readonly': readonly, | ||
| })} | ||
| // For ionic theme, we need to define this css variable | ||
| style={ | ||
| theme === 'ionic' ? { '--host-rows': this.rows !== undefined ? this.rows.toString() : undefined } : undefined | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to accomplish the styling without creating new CSS variables? |
||
| } | ||
| > | ||
| {/** | ||
| * htmlFor is needed so that clicking the label always focuses | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector uses generated scope class
.sc-ion-textarea-md-h, which is brittle and atypical compared to other styles that key off the stable.md/.ioshost classes. Prefer targeting the mode via.md(or another stable mode indicator) instead of the generated scope class so the rule does not depend on Stencil scoping internals.