Skip to content

Commit 9555a2a

Browse files
feat(radio-group): remove radio-group-wrapper and convert to shadow DOM (#30835)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> The radio-group's wrapper div is responsible for several issues that have been reported, specially due to making it so that radio elements are not direct children of radio-groups. Now it is also causing problems on the OutSystems side. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> The solution involved: - Removing the radio-group-wrapper div, which was first added as a workaround to a Stencil issue where radio children would incorrectly fire blur events on focus; - Converting the radio-group into a shadow component as another workaround to the Stencil issue; - Adjusting the radio-group's styling to the new changes. ## Does this introduce a breaking change? - [x] Yes - [ ] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: Brandy Smith <[email protected]> Co-authored-by: Brandy Smith <[email protected]>
1 parent e8d52ae commit 9555a2a

File tree

32 files changed

+33
-34
lines changed

32 files changed

+33
-34
lines changed

BREAKING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ This is a comprehensive list of the breaking changes introduced in the major ver
3838

3939
- The properties `pull` and `push` have been deprecated and no longer work. A similar look can be achieved with the newly added property `order`.
4040

41+
<h4 id="version-9x-radio-group">Radio Group</h4>
42+
43+
- Converted `ion-radio-group` to use [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM).<br/>
44+
If you were targeting the internals of `ion-radio-group` in your CSS, you will need to target the `supporting-text`, `helper-text` or `error-text` [Shadow Parts](https://ionicframework.com/docs/theming/css-shadow-parts) instead, or use the provided CSS Variables.<br/>
45+
Additionally, the `radio-group-wrapper` div element has been removed, causing slotted elements to be direct children of the `ion-radio-group`.
46+
4147
<h5>Example 1: Swap two columns</h5>
4248

4349
**Version up to 8.x**

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,supporting-text
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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Radio Group: Common
22
// --------------------------------------------------
33

4-
ion-radio-group {
5-
// Prevents additional pixels from being rendered on top
6-
vertical-align: top;
4+
:host {
5+
display: block;
76
}
87

98
// Radio Group: Top
@@ -21,10 +20,10 @@ ion-radio-group {
2120
display: block;
2221
}
2322

24-
.ion-touched.ion-invalid .radio-group-top .error-text {
23+
:host(.ion-touched.ion-invalid) .radio-group-top .error-text {
2524
display: block;
2625
}
2726

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

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
.radio-group-top {
88
@include globals.typography(globals.$ion-body-sm-medium);
9-
10-
margin-bottom: globals.$ion-space-400;
119
}
1210

1311
.radio-group-top .error-text {
@@ -23,7 +21,7 @@
2321

2422
// Add padding to the error and helper text when used in a
2523
// list to align them with the list header and item text.
26-
ion-list .radio-group-top {
24+
:host(.in-list) .radio-group-top {
2725
/* stylelint-disable */
2826
@include globals.ltr() {
2927
padding-right: globals.$ion-space-400;

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(.in-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(.in-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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Build, Component, Element, Event, Host, Listen, Method, Prop, State, Watch, h } from '@stencil/core';
33
import { checkInvalidState } from '@utils/forms';
44
import { renderHiddenInput } from '@utils/helpers';
5+
import { hostContext } from '@utils/theme';
56

67
import { getIonTheme } from '../../global/ionic-global';
78

@@ -10,6 +11,10 @@ import type { RadioGroupChangeEventDetail, RadioGroupCompareFn } from './radio-g
1011
/**
1112
* @virtualProp {"ios" | "md"} mode - The mode determines the platform behaviors of the component.
1213
* @virtualProp {"ios" | "md" | "ionic"} theme - The theme determines the visual appearance of the component.
14+
*
15+
* @part supporting-text - Supporting text displayed above the radios.
16+
* @part helper-text - Supporting text displayed above the radios when the radio group is valid.
17+
* @part error-text - Supporting text displayed above the radios when the radio group is invalid and touched.
1318
*/
1419
@Component({
1520
tag: 'ion-radio-group',
@@ -18,6 +23,7 @@ import type { RadioGroupChangeEventDetail, RadioGroupCompareFn } from './radio-g
1823
md: 'radio-group.md.scss',
1924
ionic: 'radio-group.ionic.scss',
2025
},
26+
shadow: true,
2127
})
2228
export class RadioGroup implements ComponentInterface {
2329
private inputId = `ion-rg-${radioGroupIds++}`;
@@ -318,10 +324,10 @@ export class RadioGroup implements ComponentInterface {
318324

319325
return (
320326
<div class="radio-group-top">
321-
<div id={helperTextId} class="helper-text" aria-live="polite">
327+
<div id={helperTextId} class="helper-text" part="supporting-text helper-text" aria-live="polite">
322328
{!isInvalid ? helperText : null}
323329
</div>
324-
<div id={errorTextId} class="error-text" role="alert">
330+
<div id={errorTextId} class="error-text" part="supporting-text error-text" role="alert">
325331
{isInvalid ? errorText : null}
326332
</div>
327333
</div>
@@ -352,6 +358,7 @@ export class RadioGroup implements ComponentInterface {
352358
<Host
353359
class={{
354360
[theme]: true,
361+
'in-list': hostContext('ion-list', el),
355362
}}
356363
role="radiogroup"
357364
aria-labelledby={label ? labelId : null}
@@ -360,14 +367,7 @@ export class RadioGroup implements ComponentInterface {
360367
onClick={this.onClick}
361368
>
362369
{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>
370+
<slot></slot>
371371
</Host>
372372
);
373373
}

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(supporting-text) {
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(supporting-text) {
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)