Repository navigation
feat(label): convert to shadow DOM #31657
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
Changes from all commits
ffee954
00969f3
9ac628e
07bba3b
3741fd2
5df89f0
35f938d
fe4922c
1717400
2cad03b
302fca2
405eb54
5bdb7c0
6429219
e38fa96
96d7743
de28ed4
ac8c94a
f5a1e37
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver | |||||||||||||||||||||
| - [Datetime](#version-10x-datetime) | ||||||||||||||||||||||
| - [Grid](#version-10x-grid) | ||||||||||||||||||||||
| - [Input Otp](#version-10x-input-otp) | ||||||||||||||||||||||
| - [Label](#version-10x-label) | ||||||||||||||||||||||
| - [Radio Group](#version-10x-radio-group) | ||||||||||||||||||||||
| - [Textarea](#version-10x-textarea) | ||||||||||||||||||||||
| - [Framework Specific](#version-10x-framework-specific) | ||||||||||||||||||||||
|
|
@@ -223,6 +224,69 @@ Converted `ion-input-otp` to use [Shadow DOM](https://developer.mozilla.org/en-U | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| If you were targeting the internals of `ion-input-otp` in your CSS, you will need to target the `group`, `container`, `native`, `separator` or `description` [Shadow Parts](https://ionicframework.com/docs/theming/css-shadow-parts) instead, or use the provided CSS Variables. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <h4 id="version-10x-label">Label</h4> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Converted `ion-label` to use [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM). | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| `ion-label` does not render any internal elements, so there are no Shadow Parts to target. However, the following changes may affect existing styles: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - The default heading (`h1` - `h6`) and paragraph (`p`) styles now only apply to elements that are direct children of `ion-label`. Headings and paragraphs nested inside another element, such as `ion-text`, no longer receive the label styles, and nested headings receive the global typography styles instead. To color the label text and headings, set the `color` property on `ion-label`. To color a paragraph or only part of the label, move `ion-text` inside the heading or paragraph: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```diff | ||||||||||||||||||||||
| <ion-label> | ||||||||||||||||||||||
| - <ion-text color="primary"> | ||||||||||||||||||||||
| - <h3>Title</h3> | ||||||||||||||||||||||
| - </ion-text> | ||||||||||||||||||||||
| + <h3><ion-text color="primary">Title</ion-text></h3> | ||||||||||||||||||||||
| <p>Description</p> | ||||||||||||||||||||||
| </ion-label> | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| - Global element styles for headings and paragraphs, such as `h2 { font-size: 20px; }`, now take precedence over the default label styles for those elements. Previously, the label styles took precedence. To keep the label styles, scope the global styles so they do not match elements inside `ion-label`. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```diff | ||||||||||||||||||||||
| - h2 { | ||||||||||||||||||||||
| + h2:not(ion-label > h2) { | ||||||||||||||||||||||
| font-size: 20px; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The `:not()` selector increases the specificity of the global style. To keep the original specificity, wrap the exclusion in `:where()`: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```css | ||||||||||||||||||||||
| h2:where(:not(ion-label > h2)) { | ||||||||||||||||||||||
| font-size: 20px; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 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 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`. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| A reset from a third-party stylesheet cannot be scoped, so restore the label styles with app styles that target the headings and paragraphs inside `ion-label`. These take precedence over the reset: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```css | ||||||||||||||||||||||
| ion-label > h2 { | ||||||||||||||||||||||
| margin: 2px 0; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| font-size: 1rem; | ||||||||||||||||||||||
| font-weight: normal; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| line-height: 1.2; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The default values for each heading, paragraph and mode 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. | ||||||||||||||||||||||
|
Member
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.
Suggested change
The invalid label color rule was removed too. Nothing changes by default since Ionic never sets
Member
Author
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. |
||||||||||||||||||||||
| - 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 `md` mode. 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.md.ion-invalid.ion-touched ion-label.label-stacked:not(.ion-color), | ||||||||||||||||||||||
| ion-item.md.ion-invalid.ion-touched ion-label.label-floating:not(.ion-color) { | ||||||||||||||||||||||
| color: var(--highlight-color-invalid); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <h4 id="version-10x-radio-group">Radio Group</h4> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Converted `ion-radio-group` to use [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM). | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -77,6 +77,19 @@ slot[name="end"]::slotted(*) { | |||||||||||||||||||||||||||
| content: ""; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Ionic Stacked & Floating Labels | ||||||||||||||||||||||||||||
| // -------------------------------------------------- | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| :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)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+86
Member
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.
Suggested change
The ionic theme lost the focused label color too. On
Member
Author
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. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| :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); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Ionic Item Lines | ||||||||||||||||||||||||||||
| // -------------------------------------------------- | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,16 @@ | |
| // Material Design Floating/Stacked Label | ||
| // -------------------------------------------------- | ||
|
|
||
| ::slotted(ion-label.label-stacked), | ||
| ::slotted(ion-label.label-floating) { | ||
| @include margin(0, 0, 0, 0); | ||
| } | ||
|
ShaneK marked this conversation as resolved.
Resolved
|
||
|
|
||
| :host(.ion-focused) ::slotted(ion-label.label-floating), | ||
| :host(.item-has-value) ::slotted(ion-label.label-floating) { | ||
| @include transform(translateY(50%), scale(0.75)); | ||
| } | ||
|
|
||
| :host(.item-label-stacked) ::slotted([slot="end"]), | ||
| :host(.item-label-floating) ::slotted([slot="end"]) { | ||
| @include margin( | ||
|
|
@@ -253,9 +263,7 @@ | |
| --min-height: 55px; | ||
| } | ||
|
|
||
| :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) { | ||
|
Member
Author
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. |
||
| :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: $label-md-text-color-focused; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,13 +74,9 @@ <h2>H2 Title Text</h2> | |
|
|
||
| <ion-item> | ||
| <ion-label> | ||
| <ion-text color="primary"> | ||
| <h3>H3 Title Text</h3> | ||
| </ion-text> | ||
| <h3><ion-text color="primary">H3 Title Text</ion-text></h3> | ||
|
Member
Author
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. In shadow DOM, label's |
||
| <p>Paragraph line 1</p> | ||
| <ion-text color="secondary"> | ||
| <p>Paragraph line 2 secondary</p> | ||
| </ion-text> | ||
| <p><ion-text color="secondary">Paragraph line 2 secondary</ion-text></p> | ||
| </ion-label> | ||
| </ion-item> | ||
|
|
||
|
|
||
|
Member
Author
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. The 3px comes from the markup change, not the shadow conversion. The |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,85 +22,52 @@ | |
| :host(.label-floating) { | ||
| @include margin(null, null, 0, null); | ||
| @include transform(translate(0, 29px)); | ||
| @include transform-origin(start, top); | ||
|
Member
Author
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. This was moved to |
||
|
|
||
| transition: transform 150ms ease-in-out; | ||
| } | ||
|
|
||
| :host-context(.item-textarea).label-floating { | ||
| @include transform(translate(0, 28px)); | ||
| } | ||
|
|
||
| :host-context(.item-has-focus).label-stacked, | ||
| :host-context(.item-has-focus).label-floating { | ||
| color: $label-ios-text-color-focused; | ||
| } | ||
|
|
||
| :host-context(.item-has-focus).label-floating, | ||
| :host-context(.item-has-placeholder:not(.item-input)).label-floating, | ||
| :host-context(.item-has-value).label-floating { | ||
| @include transform(scale(0.82)); | ||
| } | ||
|
|
||
| // iOS Typography | ||
| // -------------------------------------------------- | ||
|
|
||
| ::slotted(*) h1 { | ||
| ::slotted(h1) { | ||
| @include margin(3px, 0, 2px); | ||
|
|
||
| font-size: dynamic-font(22px); | ||
| font-weight: normal; | ||
| } | ||
|
|
||
| ::slotted(*) h2 { | ||
| ::slotted(h2) { | ||
| @include margin(0, 0, 2px); | ||
|
|
||
| font-size: dynamic-font(17px); | ||
| font-weight: normal; | ||
| } | ||
|
|
||
| ::slotted(*) h3, | ||
| ::slotted(*) h4, | ||
| ::slotted(*) h5, | ||
| ::slotted(*) h6 { | ||
| ::slotted(h3), | ||
| ::slotted(h4), | ||
| ::slotted(h5), | ||
| ::slotted(h6) { | ||
| @include margin(0, 0, 3px); | ||
|
|
||
| font-size: dynamic-font(14px); | ||
| font-weight: normal; | ||
|
|
||
| line-height: normal; | ||
| } | ||
|
|
||
| ::slotted(*) p { | ||
| ::slotted(p) { | ||
| @include margin( | ||
| $item-ios-paragraph-margin-top, | ||
| $item-ios-paragraph-margin-end, | ||
| $item-ios-paragraph-margin-bottom, | ||
| $item-ios-paragraph-margin-start | ||
| ); | ||
|
|
||
| color: #{$item-ios-paragraph-text-color}; | ||
|
|
||
| font-size: $item-ios-paragraph-font-size; | ||
|
|
||
| line-height: normal; | ||
|
|
||
| text-overflow: inherit; | ||
|
|
||
| overflow: inherit; | ||
| } | ||
|
|
||
| ::slotted(p) { | ||
| color: #{$item-ios-paragraph-text-color}; | ||
| } | ||
|
|
||
| :host(.in-item-color)::slotted(p) { | ||
| color: inherit; | ||
| } | ||
|
|
||
| ::slotted(*) h2:last-child, | ||
| ::slotted(*) h3:last-child, | ||
| ::slotted(*) h4:last-child, | ||
| ::slotted(*) h5:last-child, | ||
| ::slotted(*) h6:last-child, | ||
| ::slotted(*) p:last-child { | ||
| ::slotted(h2:last-child), | ||
| ::slotted(h3:last-child), | ||
| ::slotted(h4:last-child), | ||
| ::slotted(h5:last-child), | ||
| ::slotted(h6:last-child), | ||
| ::slotted(p:last-child) { | ||
| @include margin(null, null, 0, null); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.