Skip to content

Commit fd6066c

Browse files
Make radio-group use the Shadow DOM
1 parent 16cbe63 commit fd6066c

File tree

9 files changed

+36
-42
lines changed

9 files changed

+36
-42
lines changed

core/api.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ ion-radio,part,container
18451845
ion-radio,part,label
18461846
ion-radio,part,mark
18471847

1848-
ion-radio-group,none
1848+
ion-radio-group,shadow
18491849
ion-radio-group,prop,allowEmptySelection,boolean,false,false,false
18501850
ion-radio-group,prop,compareWith,((currentValue: any, compareValue: any) => boolean) | null | string | undefined,undefined,false,false
18511851
ion-radio-group,prop,errorText,string | undefined,undefined,false,false
@@ -1855,6 +1855,9 @@ ion-radio-group,prop,name,string,this.inputId,false,false
18551855
ion-radio-group,prop,theme,"ios" | "md" | "ionic",undefined,false,false
18561856
ion-radio-group,prop,value,any,undefined,false,false
18571857
ion-radio-group,event,ionChange,RadioGroupChangeEventDetail<any>,true
1858+
ion-radio-group,part,error-text
1859+
ion-radio-group,part,helper-text
1860+
ion-radio-group,part,top
18581861

18591862
ion-range,shadow
18601863
ion-range,prop,activeBarStart,number | undefined,undefined,false,false

core/src/components/radio-group/radio-group.common.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Radio Group: Common
22
// --------------------------------------------------
33

4-
ion-radio-group {
4+
:host {
55
// Prevents additional pixels from being rendered on top
66
vertical-align: top;
77
}
@@ -21,10 +21,10 @@ ion-radio-group {
2121
display: block;
2222
}
2323

24-
.ion-touched.ion-invalid .radio-group-top .error-text {
24+
:host(.ion-touched.ion-invalid) .radio-group-top .error-text {
2525
display: block;
2626
}
2727

28-
.ion-touched.ion-invalid .radio-group-top .helper-text {
28+
:host(.ion-touched.ion-invalid) .radio-group-top .helper-text {
2929
display: none;
3030
}

core/src/components/radio-group/radio-group.ionic.scss

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323

2424
// Add padding to the error and helper text when used in a
2525
// list to align them with the list header and item text.
26-
ion-list .radio-group-top {
27-
/* stylelint-disable */
28-
@include globals.ltr() {
29-
padding-right: globals.$ion-space-400;
30-
padding-left: calc(globals.$ion-space-400 + var(--ion-safe-area-left, 0px));
31-
}
32-
33-
@include globals.rtl() {
34-
padding-right: calc(globals.$ion-space-400 + var(--ion-safe-area-right, 0px));
35-
padding-left: globals.$ion-space-400;
36-
}
37-
/* stylelint-enable */
26+
// Note: :host-context() cannot be nested inside ltr()/rtl() mixins
27+
// because the mixin tries to transform the selector, creating invalid CSS.
28+
// We work around this by using separate rules outside the mixins.
29+
/* stylelint-disable */
30+
:host-context(ion-list) .radio-group-top {
31+
// Default to LTR - padding-left includes safe area
32+
padding-right: globals.$ion-space-400;
33+
padding-left: calc(globals.$ion-space-400 + var(--ion-safe-area-left, 0px));
3834
}
35+
36+
// RTL support - match when document or ancestor has dir="rtl"
37+
:host-context([dir="rtl"] ion-list) .radio-group-top,
38+
:host-context(ion-list) .radio-group-top:dir(rtl) {
39+
padding-right: calc(globals.$ion-space-400 + var(--ion-safe-area-right, 0px));
40+
padding-left: globals.$ion-space-400;
41+
}
42+
/* stylelint-enable */

core/src/components/radio-group/radio-group.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
// Add padding to the error and helper text when used in a
99
// list to align them with the list header and item text.
10-
ion-list .radio-group-top {
10+
:host-context(ion-list) .radio-group-top {
1111
@include padding-horizontal($item-ios-padding-start, $item-ios-padding-end);
1212
}

core/src/components/radio-group/radio-group.md.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
// Add padding to the error and helper text when used in a
99
// list to align them with the list header and item text.
10-
ion-list .radio-group-top {
10+
:host-context(ion-list) .radio-group-top {
1111
@include padding-horizontal($item-md-padding-start, $item-md-padding-end);
1212
}

core/src/components/radio-group/radio-group.native.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
@import "./radio-group.common";
22
@import "../../themes/native/native.globals";
33

4-
// Radio Group: Native
5-
// --------------------------------------------------
6-
7-
.radio-group-wrapper {
8-
display: inline;
9-
}
10-
114
// Radio Group: Top
125
// --------------------------------------------------
136

core/src/components/radio-group/radio-group.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { RadioGroupChangeEventDetail, RadioGroupCompareFn } from './radio-g
1818
md: 'radio-group.md.scss',
1919
ionic: 'radio-group.ionic.scss',
2020
},
21+
shadow: true,
2122
})
2223
export class RadioGroup implements ComponentInterface {
2324
private inputId = `ion-rg-${radioGroupIds++}`;
@@ -317,11 +318,11 @@ export class RadioGroup implements ComponentInterface {
317318
}
318319

319320
return (
320-
<div class="radio-group-top">
321-
<div id={helperTextId} class="helper-text" aria-live="polite">
321+
<div class="radio-group-top" part="top">
322+
<div id={helperTextId} class="helper-text" part="helper-text" aria-live="polite">
322323
{!isInvalid ? helperText : null}
323324
</div>
324-
<div id={errorTextId} class="error-text" role="alert">
325+
<div id={errorTextId} class="error-text" part="error-text" role="alert">
325326
{isInvalid ? errorText : null}
326327
</div>
327328
</div>
@@ -360,14 +361,7 @@ export class RadioGroup implements ComponentInterface {
360361
onClick={this.onClick}
361362
>
362363
{this.renderHintText()}
363-
{/*
364-
TODO(FW-6279): Wrapping the slot in a div is a workaround due to a
365-
Stencil issue. Without the wrapper, the children radio will fire the
366-
blur event on focus, instead of waiting for them to be blurred.
367-
*/}
368-
<div class="radio-group-wrapper">
369-
<slot></slot>
370-
</div>
364+
<slot></slot>
371365
</Host>
372366
);
373367
}

core/src/components/radio-group/test/supporting-text/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
ion-radio {
3131
width: 100%;
3232
}
33-
.custom .helper-text {
33+
.custom::part(helper-text) {
3434
color: green;
3535
}
36-
.custom .error-text {
36+
.custom::part(error-text) {
3737
color: purple;
3838
}
3939
</style>

core/src/components/radio-group/test/supporting-text/radio-group.e2e.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
197197
await page.setContent(
198198
`
199199
<style>
200-
.radio-group-top {
200+
ion-radio-group::part(top) {
201201
font-size: 20px;
202202
}
203203
204-
.radio-group-top .helper-text {
204+
ion-radio-group::part(helper-text) {
205205
color: green;
206206
}
207207
</style>
@@ -222,11 +222,11 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
222222
await page.setContent(
223223
`
224224
<style>
225-
.radio-group-top {
225+
ion-radio-group::part(top) {
226226
font-size: 20px;
227227
}
228228
229-
.radio-group-top .error-text {
229+
ion-radio-group::part(error-text) {
230230
color: purple;
231231
}
232232
</style>

0 commit comments

Comments
 (0)