Skip to content

Commit 677d5be

Browse files
authored
refactor(ui5-radiobutton): API enhancements (#3362)
Part of #3107 BREAKING_CHANGE: Changed "selected" property to "checked". Changed "select" event to "change"
1 parent ad365f4 commit 677d5be

19 files changed

+144
-144
lines changed

packages/main/src/ListItem.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
tabindex="-1"
6565
id="{{_id}}-singleSelectionElement"
6666
class="ui5-li-singlesel-radiobtn"
67-
?selected="{{selected}}"
67+
?checked="{{selected}}"
6868
@click="{{onSingleSelectionComponentPress}}">
6969
</ui5-radiobutton>
7070
{{/if}}

packages/main/src/RadioButton.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="ui5-radio-root {{classes.main}}"
22
role="radio"
3-
aria-checked="{{selected}}"
3+
aria-checked="{{checked}}"
44
aria-readonly="{{ariaReadonly}}"
55
aria-disabled="{{ariaDisabled}}"
66
aria-labelledby="{{ariaLabelledBy}}"
@@ -17,7 +17,7 @@
1717
<circle class="ui5-radio-svg-outer" cx="50%" cy="50%" r="50%" />
1818
<circle class="ui5-radio-svg-inner" cx="50%" cy="50%" r="22%" />
1919
</svg>
20-
<input type='radio' ?checked="{{selected}}" ?readonly="{{readonly}}" ?disabled="{{disabled}}" name="{{name}}" data-sap-no-tab-ref/>
20+
<input type='radio' ?checked="{{checked}}" ?readonly="{{readonly}}" ?disabled="{{disabled}}" name="{{name}}" data-sap-no-tab-ref/>
2121
</div>
2222

2323
{{#if text}}

packages/main/src/RadioButton.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const metadata = {
3434
properties: /** @lends sap.ui.webcomponents.main.RadioButton.prototype */ {
3535

3636
/**
37-
* Determines whether the component is disabled.
37+
* Defines whether the component is disabled.
3838
* <br><br>
3939
* <b>Note:</b> A disabled component is completely noninteractive.
4040
*
@@ -47,7 +47,7 @@ const metadata = {
4747
},
4848

4949
/**
50-
* Determines whether the component is read-only.
50+
* Defines whether the component is read-only.
5151
* <br><br>
5252
* <b>Note:</b> A read-only component is not editable,
5353
* but still provides visual feedback upon user interaction.
@@ -61,17 +61,17 @@ const metadata = {
6161
},
6262

6363
/**
64-
* Determines whether the component is selected or not.
64+
* Defines whether the component is checked or not.
6565
* <br><br>
6666
* <b>Note:</b> The property value can be changed with user interaction,
67-
* either by cliking/tapping on the component,
67+
* either by clicking/tapping on the component,
6868
* or by using the Space or Enter key.
6969
*
7070
* @type {boolean}
7171
* @defaultvalue false
7272
* @public
7373
*/
74-
selected: {
74+
checked: {
7575
type: Boolean,
7676
},
7777

@@ -184,12 +184,12 @@ const metadata = {
184184
events: /** @lends sap.ui.webcomponents.main.RadioButton.prototype */ {
185185

186186
/**
187-
* Fired when the component selected state changes.
187+
* Fired when the component checked state changes.
188188
*
189189
* @event
190190
* @public
191191
*/
192-
select: {},
192+
change: {},
193193
},
194194
};
195195

@@ -200,7 +200,7 @@ const metadata = {
200200
*
201201
* The <code>ui5-radiobutton</code> component enables users to select a single option from a set of options.
202202
* When a <code>ui5-radiobutton</code> is selected by the user, the
203-
* <code>select</code> event is fired.
203+
* <code>change</code> event is fired.
204204
* When a <code>ui5-radiobutton</code> that is within a group is selected, the one
205205
* that was previously selected gets automatically deselected. You can group radio buttons by using the <code>name</code> property.
206206
* <br>
@@ -270,8 +270,8 @@ class RadioButton extends UI5Element {
270270
syncGroup() {
271271
const oldGroup = this._name;
272272
const currentGroup = this.name;
273-
const oldSelected = this._selected;
274-
const currentSelected = this.selected;
273+
const oldChecked = this._checked;
274+
const currentChecked = this.checked;
275275

276276
if (currentGroup !== oldGroup) {
277277
if (oldGroup) {
@@ -287,20 +287,20 @@ class RadioButton extends UI5Element {
287287
RadioButtonGroup.enforceSingleSelection(this, currentGroup);
288288
}
289289

290-
if (this.name && currentSelected !== oldSelected) {
290+
if (this.name && currentChecked !== oldChecked) {
291291
RadioButtonGroup.updateTabOrder(this.name);
292292
}
293293

294294
this._name = this.name;
295-
this._selected = this.selected;
295+
this._checked = this.checked;
296296
}
297297

298298
_enableFormSupport() {
299299
const FormSupport = getFeature("FormSupport");
300300
if (FormSupport) {
301301
FormSupport.syncNativeHiddenInput(this, (element, nativeInput) => {
302-
nativeInput.disabled = element.disabled || !element.selected;
303-
nativeInput.value = element.selected ? element.value : "";
302+
nativeInput.disabled = element.disabled || !element.checked;
303+
nativeInput.value = element.checked ? element.value : "";
304304
});
305305
} else if (this.value) {
306306
console.warn(`In order for the "value" property to have effect, you should also: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";`); // eslint-disable-line
@@ -363,8 +363,8 @@ class RadioButton extends UI5Element {
363363
}
364364

365365
if (!this.name) {
366-
this.selected = !this.selected;
367-
this.fireEvent("select");
366+
this.checked = !this.checked;
367+
this.fireEvent("change");
368368
return this;
369369
}
370370

@@ -373,7 +373,7 @@ class RadioButton extends UI5Element {
373373
}
374374

375375
canToggle() {
376-
return !(this.disabled || this.readonly || this.selected);
376+
return !(this.disabled || this.readonly || this.checked);
377377
}
378378

379379
valueStateTextMappings() {

packages/main/src/RadioButtonGroup.js

+32-32
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class RadioButtonGroup {
77
return this.groups.get(groupName);
88
}
99

10-
static getSelectedRadioFromGroup(groupName) {
11-
return this.selectedRadios.get(groupName);
10+
static getCheckedRadioFromGroup(groupName) {
11+
return this.checkedRadios.get(groupName);
1212
}
1313

1414
static removeGroup(groupName) {
15-
this.selectedRadios.delete(groupName);
15+
this.checkedRadios.delete(groupName);
1616
return this.groups.delete(groupName);
1717
}
1818

@@ -33,7 +33,7 @@ class RadioButtonGroup {
3333
}
3434

3535
const group = this.getGroup(groupName);
36-
const selectedRadio = this.getSelectedRadioFromGroup(groupName);
36+
const checkedRadio = this.getCheckedRadioFromGroup(groupName);
3737

3838
// Remove the radio button from the given group
3939
group.forEach((_radioBtn, idx, arr) => {
@@ -42,8 +42,8 @@ class RadioButtonGroup {
4242
}
4343
});
4444

45-
if (selectedRadio === radioBtn) {
46-
this.selectedRadios.set(groupName, null);
45+
if (checkedRadio === radioBtn) {
46+
this.checkedRadios.set(groupName, null);
4747
}
4848

4949
// Remove the group if it is empty
@@ -55,8 +55,8 @@ class RadioButtonGroup {
5555
}
5656

5757
static createGroup(radioBtn, groupName) {
58-
if (radioBtn.selected) {
59-
this.selectedRadios.set(groupName, radioBtn);
58+
if (radioBtn.checked) {
59+
this.checkedRadios.set(groupName, radioBtn);
6060
}
6161

6262
this.groups.set(groupName, [radioBtn]);
@@ -82,11 +82,11 @@ class RadioButtonGroup {
8282
}
8383

8484
const group = this.getGroup(groupName);
85-
const hasSelectedRadio = group.some(radioBtn => radioBtn.selected);
85+
const hasCheckedRadio = group.some(radioBtn => radioBtn.checked);
8686

8787
group.filter(radioBtn => !radioBtn.disabled).forEach((radioBtn, idx) => {
88-
if (hasSelectedRadio) {
89-
radioBtn._tabIndex = radioBtn.selected ? "0" : "-1";
88+
if (hasCheckedRadio) {
89+
radioBtn._tabIndex = radioBtn.checked ? "0" : "-1";
9090
} else {
9191
radioBtn._tabIndex = idx === 0 ? "0" : "-1";
9292
}
@@ -113,25 +113,25 @@ class RadioButtonGroup {
113113
}
114114

115115
static updateSelectionInGroup(radioBtnToSelect, groupName) {
116-
const selectedRadio = this.getSelectedRadioFromGroup(groupName);
116+
const checkedRadio = this.getCheckedRadioFromGroup(groupName);
117117

118-
this._deselectRadio(selectedRadio);
118+
this._deselectRadio(checkedRadio);
119119
this._selectRadio(radioBtnToSelect);
120-
this.selectedRadios.set(groupName, radioBtnToSelect);
120+
this.checkedRadios.set(groupName, radioBtnToSelect);
121121
}
122122

123123
static _deselectRadio(radioBtn) {
124124
if (radioBtn) {
125-
radioBtn.selected = false;
125+
radioBtn.checked = false;
126126
}
127127
}
128128

129129
static _selectRadio(radioBtn) {
130130
if (radioBtn) {
131131
radioBtn.focus();
132-
radioBtn.selected = true;
133-
radioBtn._selected = true;
134-
radioBtn.fireEvent("select");
132+
radioBtn.checked = true;
133+
radioBtn._checked = true;
134+
radioBtn.fireEvent("change");
135135
}
136136
}
137137

@@ -171,17 +171,17 @@ class RadioButtonGroup {
171171
}
172172

173173
static enforceSingleSelection(radioBtn, groupName) {
174-
const selectedRadio = this.getSelectedRadioFromGroup(groupName);
175-
176-
if (radioBtn.selected) {
177-
if (!selectedRadio) {
178-
this.selectedRadios.set(groupName, radioBtn);
179-
} else if (radioBtn !== selectedRadio) {
180-
this._deselectRadio(selectedRadio);
181-
this.selectedRadios.set(groupName, radioBtn);
174+
const checkedRadio = this.getCheckedRadioFromGroup(groupName);
175+
176+
if (radioBtn.checked) {
177+
if (!checkedRadio) {
178+
this.checkedRadios.set(groupName, radioBtn);
179+
} else if (radioBtn !== checkedRadio) {
180+
this._deselectRadio(checkedRadio);
181+
this.checkedRadios.set(groupName, radioBtn);
182182
}
183-
} else if (radioBtn === selectedRadio) {
184-
this.selectedRadios.set(groupName, null);
183+
} else if (radioBtn === checkedRadio) {
184+
this.checkedRadios.set(groupName, null);
185185
}
186186

187187
this.updateTabOrder(groupName);
@@ -194,11 +194,11 @@ class RadioButtonGroup {
194194
return this._groups;
195195
}
196196

197-
static get selectedRadios() {
198-
if (!this._selectedRadios) {
199-
this._selectedRadios = new Map();
197+
static get checkedRadios() {
198+
if (!this._checkedRadios) {
199+
this._checkedRadios = new Map();
200200
}
201-
return this._selectedRadios;
201+
return this._checkedRadios;
202202
}
203203
}
204204

packages/main/src/themes/RadioButton.css

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
color: var(--sapField_BorderColor);
1313
}
1414

15-
/* Selected */
16-
:host([selected]) {
17-
color: var(--_ui5_radiobutton_selected_fill);
15+
/* Checked */
16+
:host([checked]) {
17+
color: var(--_ui5_radiobutton_checked_fill);
1818
}
1919

20-
:host([selected]) .ui5-radio-svg-inner {
20+
:host([checked]) .ui5-radio-svg-inner {
2121
fill: currentColor;
2222
}
2323

24-
:host([selected]) .ui5-radio-svg-outer {
24+
:host([checked]) .ui5-radio-svg-outer {
2525
stroke: var(--sapField_BorderColor);
2626
}
2727

@@ -55,7 +55,7 @@
5555
}
5656

5757
/* Read only */
58-
:host([selected][readonly]) .ui5-radio-svg-inner {
58+
:host([checked][readonly]) .ui5-radio-svg-inner {
5959
fill: var(--sapContent_NonInteractiveIconColor);
6060
}
6161

@@ -70,8 +70,8 @@
7070
}
7171

7272
/* Error state */
73-
:host([value-state="Error"][selected]) .ui5-radio-svg-inner {
74-
fill: var(--_ui5_radiobutton_selected_error_fill);
73+
:host([value-state="Error"][checked]) .ui5-radio-svg-inner {
74+
fill: var(--_ui5_radiobutton_checked_error_fill);
7575
}
7676
:host([value-state="Error"]) .ui5-radio-svg-outer,
7777
:host([value-state="Error"]) .ui5-radio-root:hover .ui5-radio-inner.ui5-radio-inner--hoverable:hover .ui5-radio-svg-outer {
@@ -80,8 +80,8 @@
8080
}
8181

8282
/* Warning state */
83-
:host([value-state="Warning"][selected]) .ui5-radio-svg-inner {
84-
fill: var(--_ui5_radiobutton_selected_warning_fill);
83+
:host([value-state="Warning"][checked]) .ui5-radio-svg-inner {
84+
fill: var(--_ui5_radiobutton_checked_warning_fill);
8585
}
8686
:host([value-state="Warning"]) .ui5-radio-svg-outer,
8787
:host([value-state="Warning"]) .ui5-radio-root:hover .ui5-radio-inner.ui5-radio-inner--hoverable:hover .ui5-radio-svg-outer {

packages/main/src/themes/base/RadioButton-parameters.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
--_ui5_radiobutton_min_width_compact: 2rem;
44
--_ui5_radiobutton_hover_fill: var(--sapField_Hover_Background);
55
--_ui5_radiobutton_border_width: 1px;
6-
--_ui5_radiobutton_selected_fill: var(--sapSelectedColor);
7-
--_ui5_radiobutton_selected_error_fill: var(--sapField_InvalidColor);
8-
--_ui5_radiobutton_selected_warning_fill: var(--sapField_TextColor);
6+
--_ui5_radiobutton_checked_fill: var(--sapSelectedColor);
7+
--_ui5_radiobutton_checked_error_fill: var(--sapField_InvalidColor);
8+
--_ui5_radiobutton_checked_warning_fill: var(--sapField_TextColor);
99
--_ui5_radiobutton_warning_error_border_dash: 0;
1010
}

packages/main/src/themes/sap_belize_hcb/RadioButton-parameters.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@import "../base/RadioButton-parameters.css";
22

33
:root {
4-
--_ui5_radiobutton_selected_fill: var(--sapContent_IconColor);
5-
--_ui5_radiobutton_selected_warning_fill: var(--sapContent_IconColor);
6-
--_ui5_radiobutton_selected_error_fill: var(--sapContent_IconColor);
4+
--_ui5_radiobutton_checked_fill: var(--sapContent_IconColor);
5+
--_ui5_radiobutton_checked_warning_fill: var(--sapContent_IconColor);
6+
--_ui5_radiobutton_checked_error_fill: var(--sapContent_IconColor);
77
--_ui5_radiobutton_hover_fill: var(--sapSelectedColor);
88
--_ui5_radiobutton_border_width: 0.125rem;
99
--_ui5_radiobutton_warning_error_border_dash: 5;

packages/main/src/themes/sap_belize_hcw/RadioButton-parameters.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@import "../base/RadioButton-parameters.css";
22

33
:root {
4-
--_ui5_radiobutton_selected_fill: var(--sapContent_IconColor);
5-
--_ui5_radiobutton_selected_warning_fill: var(--sapContent_IconColor);
6-
--_ui5_radiobutton_selected_error_fill: var(--sapContent_IconColor);
4+
--_ui5_radiobutton_checked_fill: var(--sapContent_IconColor);
5+
--_ui5_radiobutton_checked_warning_fill: var(--sapContent_IconColor);
6+
--_ui5_radiobutton_checked_error_fill: var(--sapContent_IconColor);
77
--_ui5_radiobutton_hover_fill: var(--sapSelectedColor);
88
--_ui5_radiobutton_border_width: 0.125rem;
99
--_ui5_radiobutton_warning_error_border_dash: 5;

packages/main/src/themes/sap_fiori_3_hcb/RadioButton-parameters.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@import "../base/RadioButton-parameters.css";
22

33
:root {
4-
--_ui5_radiobutton_selected_fill: var(--sapContent_IconColor);
5-
--_ui5_radiobutton_selected_warning_fill: var(--sapContent_IconColor);
6-
--_ui5_radiobutton_selected_error_fill: var(--sapContent_IconColor);
4+
--_ui5_radiobutton_checked_fill: var(--sapContent_IconColor);
5+
--_ui5_radiobutton_checked_warning_fill: var(--sapContent_IconColor);
6+
--_ui5_radiobutton_checked_error_fill: var(--sapContent_IconColor);
77
--_ui5_radiobutton_hover_fill: var(--sapSelectedColor);
88
--_ui5_radiobutton_border_width: 0.125rem;
99
--_ui5_radiobutton_warning_error_border_dash: 5;

0 commit comments

Comments
 (0)