Skip to content

Commit b5b8047

Browse files
committed
refactor(select): rename the checked attribute to selected on option
BREAKING CHANGES: The Option component’s `checked` attribute has been renamed to `selected` in order to select an option. This is to the follow the MDN spec for a select option: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option If a `ngModel` is added to the Select component the value of the `ngModel` will take precedence over the `selected` attribute. references ionic-team#7334
1 parent ccf6ae5 commit b5b8047

File tree

10 files changed

+37
-34
lines changed

10 files changed

+37
-34
lines changed

demos/local-storage/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<ion-item>
4646
<ion-label>Key</ion-label>
4747
<ion-select [(ngModel)]="delKey">
48-
<ion-option checked>Select a Key</ion-option>
48+
<ion-option selected>Select a Key</ion-option>
4949
<ion-option *ngFor="let key of addedKeys" [value]="key">
5050
{{ key }}
5151
</ion-option>

demos/select/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ion-select (ionChange)="monthChange($event)">
3838
<ion-option value="01">January</ion-option>
3939
<ion-option value="02">February</ion-option>
40-
<ion-option value="03" checked="true">March</ion-option>
40+
<ion-option value="03" selected="true">March</ion-option>
4141
<ion-option value="04">April</ion-option>
4242
<ion-option value="05">May</ion-option>
4343
<ion-option value="06">June</ion-option>
@@ -54,7 +54,7 @@
5454
<ion-option>1991</ion-option>
5555
<ion-option>1992</ion-option>
5656
<ion-option>1993</ion-option>
57-
<ion-option checked="true">1994</ion-option>
57+
<ion-option selected="true">1994</ion-option>
5858
<ion-option>1995</ion-option>
5959
<ion-option>1996</ion-option>
6060
<ion-option>1997</ion-option>

src/components/input/test/fixed-inline-labels/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ion-item>
2424
<ion-label fixed>CC</ion-label>
2525
<ion-select>
26-
<ion-option checked>Admin</ion-option>
26+
<ion-option selected>Admin</ion-option>
2727
</ion-select>
2828
</ion-item>
2929

src/components/input/test/stacked-labels/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<ion-item>
4848
<ion-label stacked>Label 6</ion-label>
4949
<ion-select [(ngModel)]="gender">
50-
<ion-option value="f" checked="true">Female</ion-option>
50+
<ion-option value="f" selected="true">Female</ion-option>
5151
<ion-option value="m">Male</ion-option>
5252
</ion-select>
5353
</ion-item>

src/components/option/option.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { isPresent, isTrueProperty } from '../../util/util';
55
/**
66
* @name Option
77
* @description
8-
* `ion-option` is a child component of `ion-select`. Similar to the native option element, `ion-option` can take a value and a checked property.
8+
* `ion-option` is a child component of `ion-select`. Similar to the native option element, `ion-option` can take a value and a selected property.
99
*
1010
* @demo /docs/v2/demos/item-sliding/
1111
*/
1212
@Directive({
1313
selector: 'ion-option'
1414
})
1515
export class Option {
16-
private _checked: any = false;
16+
private _selected: any = false;
1717
private _disabled: any = false;
1818
private _value: any;
1919

@@ -25,15 +25,15 @@ export class Option {
2525
constructor(private _elementRef: ElementRef) {}
2626

2727
/**
28-
* @input {boolean} Whether or not the option is already checked and selected
28+
* @input {boolean} Whether or not the option is already selected
2929
*/
3030
@Input()
31-
get checked() {
32-
return this._checked;
31+
get selected() {
32+
return this._selected;
3333
}
3434

35-
set checked(val) {
36-
this._checked = isTrueProperty(val);
35+
set selected(val) {
36+
this._selected = isTrueProperty(val);
3737
}
3838

3939
/**

src/components/select/select.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const SELECT_VALUE_ACCESSOR = new Provider(
4848
* <ion-item>
4949
* <ion-label>Gender</ion-label>
5050
* <ion-select [(ngModel)]="gender">
51-
* <ion-option value="f" checked="true">Female</ion-option>
51+
* <ion-option value="f" selected="true">Female</ion-option>
5252
* <ion-option value="m">Male</ion-option>
5353
* </ion-select>
5454
* </ion-item>
@@ -175,11 +175,6 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
175175
*/
176176
@Input() alertOptions: any = {};
177177

178-
/**
179-
* @private
180-
*/
181-
@Input() checked: any = false;
182-
183178
/**
184179
* @input {string} The interface the select should use: `action-sheet` or `alert`. Default: `alert`.
185180
*/
@@ -273,7 +268,7 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
273268
if (this.interface === 'action-sheet') {
274269
alertOptions.buttons = alertOptions.buttons.concat(options.map(input => {
275270
return {
276-
role: (input.checked ? 'selected' : ''),
271+
role: (input.selected ? 'selected' : ''),
277272
text: input.text,
278273
handler: () => {
279274
this.onChange(input.value);
@@ -296,7 +291,7 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
296291
type: (this._multi ? 'checkbox' : 'radio'),
297292
label: input.text,
298293
value: input.value,
299-
checked: input.checked,
294+
checked: input.selected,
300295
disabled: input.disabled
301296
};
302297
});
@@ -366,8 +361,8 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
366361

367362
if (!this._values.length) {
368363
// there are no values set at this point
369-
// so check to see who should be checked
370-
this._values = val.filter(o => o.checked).map(o => o.value);
364+
// so check to see who should be selected
365+
this._values = val.filter(o => o.selected).map(o => o.value);
371366
}
372367

373368
this._updOpts();
@@ -382,11 +377,11 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
382377
if (this._options) {
383378
this._options.forEach(option => {
384379
// check this option if the option's value is in the values array
385-
option.checked = this._values.some(selectValue => {
380+
option.selected = this._values.some(selectValue => {
386381
return isCheckedProperty(selectValue, option.value);
387382
});
388383

389-
if (option.checked) {
384+
if (option.selected) {
390385
this._texts.push(option.text);
391386
}
392387
});

src/components/select/test/multiple-value/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class E2EPage {
2525
{ text: 'Honey Badger', value: 'honeybadger' },
2626
{ text: 'Pig', value: 'pig' },
2727
];
28-
this.status = 'checked';
28+
this.status = 'selected';
2929

3030
this.authForm = new FormGroup({
3131
name: new FormControl(''),

src/components/select/test/multiple-value/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@
4747
<ion-item>
4848
<ion-label>Disabled</ion-label>
4949
<ion-select multiple disabled>
50-
<ion-option checked="true">Selected Text</ion-option>
50+
<ion-option selected="true">Selected Text</ion-option>
5151
</ion-select>
5252
</ion-item>
5353

5454
<ion-item>
5555
<ion-label>Statuses</ion-label>
5656
<ion-select multiple [(ngModel)]="status">
57-
<ion-option value="checked" checked="true">Checked</ion-option>
57+
<ion-option value="selected" selected="true">Selected</ion-option>
5858
<ion-option value="default">Default</ion-option>
5959
<ion-option value="disabled" disabled="true">Disabled</ion-option>
6060
</ion-select>

src/components/select/test/single-value/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class E2EPage {
1414
month: string;
1515
year: string;
1616
years: Array<number>;
17-
notification: string;
17+
notifications: string;
1818
status: string;
1919

2020
constructor() {
@@ -23,8 +23,8 @@ class E2EPage {
2323
this.music = null;
2424
this.month = '12';
2525
this.year = '1994';
26-
this.notification = 'enable';
27-
this.status = 'checked';
26+
this.notifications = 'enable';
27+
this.gender = 'f';
2828

2929
this.years = [1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999];
3030

@@ -47,6 +47,10 @@ class E2EPage {
4747
console.log('STP selected');
4848
}
4949

50+
statusChange(ev: string) {
51+
this.status = ev;
52+
}
53+
5054
resetGender() {
5155
this.gender = null;
5256
}

src/components/select/test/single-value/main.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ion-item>
1313
<ion-label>Gender</ion-label>
1414
<ion-select [(ngModel)]="gender" class="e2eSelectGender">
15-
<ion-option value="f" checked="true">Female</ion-option>
15+
<ion-option value="f">Female</ion-option>
1616
<ion-option value="m">Male</ion-option>
1717
</ion-select>
1818
</ion-item>
@@ -44,7 +44,7 @@
4444

4545
<ion-item>
4646
<ion-label>Notifications</ion-label>
47-
<ion-select [(ngModel)]="notification" interface="action-sheet" cancelText="Cancel!">
47+
<ion-select [(ngModel)]="notifications" interface="action-sheet" cancelText="Cancel!">
4848
<ion-option value="enable">Enable</ion-option>
4949
<ion-option value="mute">Mute</ion-option>
5050
<ion-option value="mute_week">Mute for a week</ion-option>
@@ -88,8 +88,8 @@
8888

8989
<ion-item>
9090
<ion-label>Statuses</ion-label>
91-
<ion-select [(ngModel)]="status">
92-
<ion-option value="checked" checked="true">Checked</ion-option>
91+
<ion-select (ionChange)="statusChange($event)">
92+
<ion-option value="selected" selected>Selected</ion-option>
9393
<ion-option value="default">Default</ion-option>
9494
<ion-option value="disabled" disabled="true">Disabled</ion-option>
9595
</ion-select>
@@ -104,10 +104,14 @@
104104
<br>
105105
<code>os: {{os}}</code>
106106
<br>
107+
<code>notifications: {{notifications}}</code>
108+
<br>
107109
<code>music: {{music}}</code>
108110
<br>
109111
<code>date: {{month}}/{{year}}</code>
110112
<br>
113+
<code>status: {{status}}</code>
114+
<br>
111115
</p>
112116

113117
</ion-content>

0 commit comments

Comments
 (0)