Repository navigation
feat(label): convert to shadow DOM - #31657
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
The 3px comes from the markup change, not the shadow conversion. The h3 used to be the only child of ion-text, so iOS's h3:last-child { margin-bottom: 0 } applied. Shadow DOM can only style direct children, so it's now <h3><ion-text>…</ion-text></h3>. It's no longer a last child, so it keeps its 3px bottom margin. The scoped label renders this markup identically.
| <ion-text color="primary"> | ||
| <h3>H3 Title Text</h3> | ||
| </ion-text> | ||
| <h3><ion-text color="primary">H3 Title Text</ion-text></h3> |
There was a problem hiding this comment.
In shadow DOM, label's ::slotted() styles only reach its direct children, so a heading nested inside ion-text loses label's heading styles and gets the global typography instead. Moving ion-text inside the heading keeps the h3 a direct child, so it still gets label's styles. This is documented in BREAKING.md.
53e3491 to
9056bf4
Compare
| :host(.ion-focused:not(.ion-color)) ::slotted(.label-stacked), | ||
| :host(.ion-focused:not(.ion-color)) ::slotted(.label-floating), | ||
| :host(.item-has-focus:not(.ion-color)) ::slotted(.label-stacked), | ||
| :host(.item-has-focus:not(.ion-color)) ::slotted(.label-floating) { |
| :host(.label-floating) { | ||
| @include margin(null, null, 0, null); | ||
| @include transform(translate(0, 29px)); | ||
| @include transform-origin(start, top); |
There was a problem hiding this comment.
This was moved to label.scss.
| :host(.label-floating) { | ||
| @include margin(0, 0, 0, 0); | ||
| /* stylelint-disable property-disallowed-list */ | ||
| transform-origin: top left; |
There was a problem hiding this comment.
This was moved to label.scss.
ShaneK
left a comment
There was a problem hiding this comment.
Generally looks good, the conversion is really careful! The focused label color is the main one I'd like to see fixed, and I'm curious what you think about the CSS reset question. The rest are docs and nits.
thetaPC
left a comment
There was a problem hiding this comment.
I agree with Shane's comments, especially the focused color on colored labels and the floating labels with item-has-value.
3e46cf4 to
a8f0607
Compare
ShaneK
left a comment
There was a problem hiding this comment.
Thanks for the updates, everything from my last review looks good! I left a few more comments, and the ionic focused color and the LTR-in-RTL label origin are the main ones.
| :host(.ion-focused) ::slotted(ion-label.label-floating), | ||
| :host(.item-has-value) ::slotted(ion-label.label-floating) { | ||
| @include globals.transform(translateY(50%), scale(0.75)); | ||
| } |
There was a problem hiding this comment.
| :host(.ion-focused) ::slotted(ion-label.label-floating), | |
| :host(.item-has-value) ::slotted(ion-label.label-floating) { | |
| @include globals.transform(translateY(50%), scale(0.75)); | |
| } | |
| :host(.ion-focused) ::slotted(ion-label.label-floating), | |
| :host(.item-has-value) ::slotted(ion-label.label-floating) { | |
| @include globals.transform(translateY(50%), scale(0.75)); | |
| } | |
| :host(.ion-focused:not(.ion-color)) ::slotted(.label-stacked:not(.ion-color)), | |
| :host(.ion-focused:not(.ion-color)) ::slotted(.label-floating:not(.ion-color)) { | |
| color: globals.ion-color(primary, base); | |
| } |
The ionic theme lost the focused label color too. On next it shared the md label stylesheet, so a focused stacked or floating label turned primary (rgb(16, 92, 239)), and here it stays the default rgb(36, 37, 40). The md fix only went into item.md.scss, so I think it just needs the same rule here. With this the ionic labels match next in light and dark, and colored labels keep their color. The new focused label test says only md changes the color, so it could run ionic-md too.
| :host(.label-stacked), | ||
| :host(.label-floating) { | ||
| @include margin(null, null, 0, null); | ||
| @include transform-origin(start, top); |
There was a problem hiding this comment.
This one is separate from the Safari case Maria raised. In Chromium, :host-context([dir=rtl]) matches any RTL ancestor, so an LTR section inside an RTL app (a <div dir="ltr"> in an <html dir="rtl"> page) now gets transform-origin: right top on md and ionic stacked and floating labels. At a 400px viewport that puts the label 92px to the right of where it sits on next, where isRTL() picked up the nearest dir="ltr" instead. The removed spec test covered exactly this case.
Could we bring back the label-rtl class from isRTL(this.el) for the origin? Or if we're fine with the new behavior, I think we should add an e2e for an LTR subtree in an RTL document so it's pinned either way.
There was a problem hiding this comment.
I updated the mixin instead: a0a9f42
Here is a before & after of the label:
| Before | After |
|---|---|
![]() |
![]() |
It also fixes popover's arrow so I can PR it into main.
|
|
||
| The default values for each heading, paragraph and theme are in [`label.scss`](https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/label/label.scss), [`label.ios.scss`](https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/label/label.ios.scss) and [`label.md.scss`](https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/label/label.md.scss). | ||
| - The global typography styles in `typography.css` no longer apply to headings that are direct children of `ion-label`. These headings are styled by `ion-label` instead. | ||
| - App styles that target `ion-label` directly now take precedence over the default `ion-label` styles. For example, a class that sets `color` on an `ion-label` inside of an `ion-item` previously had no effect because the label applied `var(--color)`, and it now changes the label color. Remove these styles if they are no longer wanted, or use the `--color` CSS variable to set the color of a label inside of an item. |
There was a problem hiding this comment.
| - App styles that target `ion-label` directly now take precedence over the default `ion-label` styles. For example, a class that sets `color` on an `ion-label` inside of an `ion-item` previously had no effect because the label applied `var(--color)`, and it now changes the label color. Remove these styles if they are no longer wanted, or use the `--color` CSS variable to set the color of a label inside of an item. | |
| - App styles that target `ion-label` directly now take precedence over the default `ion-label` styles. For example, a class that sets `color` on an `ion-label` inside of an `ion-item` previously had no effect because the label applied `var(--color)`, and it now changes the label color. Remove these styles if they are no longer wanted, or use the `--color` CSS variable to set the color of a label inside of an item. | |
| - Stacked and floating labels in an item with the `ion-invalid` and `ion-touched` classes no longer use the `--highlight-color-invalid` CSS variable in the `md` and `ionic` themes. This only changes apps that set `--highlight-color-invalid` on `ion-item` or one of its ancestors. To keep the invalid color, add the following styles: | |
| ```css | |
| ion-item:is(.md, .ionic).ion-invalid.ion-touched ion-label.label-stacked:not(.ion-color), | |
| ion-item:is(.md, .ionic).ion-invalid.ion-touched ion-label.label-floating:not(.ion-color) { | |
| color: var(--highlight-color-invalid); | |
| } | |
| ``` |
The invalid label color rule was removed too. Nothing changes by default since Ionic never sets --highlight-color-invalid on the item, but apps that still set it on ion-item or :root will see touched invalid stacked and floating labels stop turning that color in md and ionic. Could we add a bullet for it? Up to you!
|
|
||
| Complex selectors inside `:not()` require Chrome 88+, Firefox 84+ and Safari 9+, and `:where()` requires Chrome 88+, Firefox 78+ and Safari 14+. | ||
|
|
||
| This includes CSS resets such as Tailwind's Preflight and Bootstrap's Reboot. In v8, these resets did not change the headings and paragraphs inside `ion-label`, because the label styles took precedence. In v10, the reset takes precedence, so label headings and paragraphs lose their margins and use the reset's font size and weight. For example, with Tailwind's Preflight, `md` label headings render at `16px` with no margins instead of `24px`, `16px` and `14px`, and with Bootstrap's Reboot they render at `40px`, `32px` and `28px`. |
There was a problem hiding this comment.
| This includes CSS resets such as Tailwind's Preflight and Bootstrap's Reboot. In v8, these resets did not change the headings and paragraphs inside `ion-label`, because the label styles took precedence. In v10, the reset takes precedence, so label headings and paragraphs lose their margins and use the reset's font size and weight. For example, with Tailwind's Preflight, `md` label headings render at `16px` with no margins instead of `24px`, `16px` and `14px`, and with Bootstrap's Reboot they render at `40px`, `32px` and `28px`. | |
| This includes CSS resets such as Tailwind's Preflight and Bootstrap's Reboot. In v9, these resets did not change the headings and paragraphs inside `ion-label`, because the label styles took precedence. In v10, the reset takes precedence, so label headings and paragraphs lose their margins and use the reset's font size and weight. For example, with Tailwind's Preflight, `md` label headings render at `16px` with no margins instead of `24px`, `16px` and `14px`, and with Bootstrap's Reboot they render at `40px`, `32px` and `28px`. |
This should be v9, since label is still scoped there. That one's on me, my comment said v8 too.
| }); | ||
| }); | ||
|
|
||
| configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
There was a problem hiding this comment.
| configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { | |
| /** | |
| * The ios, md, and ionic themes each float the label | |
| * with their own item styles, so this runs in all three. | |
| */ | |
| configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
Nit: the other two restricted blocks in this file explain their matrix, so this one could use a comment too. Up to you!
Removes the label-rtl host class and its spec. The transform-origin mixin in label.scss handles RTL, so nothing reads the class.
83a01d7 to
f5a1e37
Compare


Issue number: internal
What is the current behavior?
ion-labelusesscopedencapsulation.What is the new behavior?
ion-labelto Shadow DOM.::slotted(), so heading and paragraph styles now apply toh1-h6andpelements that are direct children ofion-label.typography.cssandtypography.ionic.cssnow skip headings that are direct children ofion-label, using selectors likeh1:where(:not(ion-label > h1))for each heading level, so the label's heading styles apply to them. The:where()keeps the original specificity.::slotted(ion-label)styles take precedence over label's own styles in shadow DOM.:host-context, which only Chromium supports in shadow DOM.transform-originmixin instead of a render-timelabel-rtlclass.:host-contextrules for item classes that are no longer set (item-input,item-textarea,item-has-focus,item-has-value,item-has-placeholder), along with the focused and invalid color rules for stacked and floating labels.isRTL()checked when needed, instead of render-time classes.Does this introduce a breaking change?
BREAKING CHANGE:
ion-labelhas been converted to use Shadow DOM.h1-h6andpelements that are direct children ofion-label. Nested headings, such as<ion-label><ion-text><h3>, no longer get label styles and get the global typography instead. Moveion-textinside the heading or paragraph, or setcoloronion-label.h2 { font-size: 20px; }now take precedence over label's heading and paragraph styles. Scope them withh2:not(ion-label > h2)to keep the label styles.ion-labeldirectly, such as a class that setscolor, now take precedence over the default label styles.Other information
:not()and:where()selectors in the global typography need Firefox 84+ and 78+, and docs(breaking): add minimum browser versions for v10 #31605 raises the documented minimum to Firefox 89.