Skip to content

Commit b8285b7

Browse files
committed
refactor(select): rename alertOptions to selectOptions, add ability to pass them for action-sheet
BREAKING CHANGES: Select’s `alertOptions` input has been renamed to `selectOptions`. It now allows you to pass options for either the alert or action-sheet interface. Refer to their documentation for the options each of them accept. http://ionicframework.com/docs/v2/api/components/action-sheet/ActionShee tController/#create http://ionicframework.com/docs/v2/api/components/alert/AlertController/# create fixes #7764
1 parent 8c1662d commit b8285b7

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/components/select/select.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ export const SELECT_VALUE_ACCESSOR = new Provider(
9696
* ### Alert Options
9797
*
9898
* Since `ion-select` is a wrapper to `Alert`, by default, it can be
99-
* passed options in the `alertOptions` property. This can be used to
99+
* passed options in the `selectOptions` property. This can be used to
100100
* pass a custom alert title, subtitle or message. See the {@link ../../alert/Alert Alert API docs}
101101
* for more properties.
102102
*
103103
* ```html
104-
* <ion-select [alertOptions]="alertOptions">
104+
* <ion-select [selectOptions]="selectOptions">
105105
* ...
106106
* </ion-select>
107107
* ```
108108
*
109109
* ```ts
110-
* this.alertOptions = {
110+
* this.selectOptions = {
111111
* title: 'Pizza Toppings',
112112
* subTitle: 'Select your toppings'
113113
* };
@@ -169,10 +169,12 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
169169
@Input() placeholder: string;
170170

171171
/**
172-
* @input {any} Any addition options that the alert interface can take.
173-
* See the [Alert API docs](../../alert/Alert) for the create options.
172+
* @input {any} Any additional options that the `alert` or `action-sheet` interface can take.
173+
* See the [Alert API docs](../../alert/AlertController/#create) and the
174+
* [ActionSheetController API docs](../../action-sheet/ActionSheetController/#create) for the
175+
* create options for each interface.
174176
*/
175-
@Input() alertOptions: any = {};
177+
@Input() selectOptions: any = {};
176178

177179
/**
178180
* @input {string} The interface the select should use: `action-sheet` or `alert`. Default: `alert`.
@@ -240,21 +242,21 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
240242
console.debug('select, open alert');
241243

242244
// the user may have assigned some options specifically for the alert
243-
let alertOptions = merge({}, this.alertOptions);
245+
let selectOptions = merge({}, this.selectOptions);
244246

245247
// make sure their buttons array is removed from the options
246248
// and we create a new array for the alert's two buttons
247-
alertOptions.buttons = [{
249+
selectOptions.buttons = [{
248250
text: this.cancelText,
249251
role: 'cancel',
250252
handler: () => {
251253
this.ionCancel.emit(null);
252254
}
253255
}];
254256

255-
// if the alertOptions didn't provide an title then use the label's text
256-
if (!alertOptions.title && this._item) {
257-
alertOptions.title = this._item.getLabelText();
257+
// if the selectOptions didn't provide a title then use the label's text
258+
if (!selectOptions.title && this._item) {
259+
selectOptions.title = this._item.getLabelText();
258260
}
259261

260262
let options = this._options.toArray();
@@ -270,7 +272,7 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
270272

271273
let overlay: any;
272274
if (this.interface === 'action-sheet') {
273-
alertOptions.buttons = alertOptions.buttons.concat(options.map(input => {
275+
selectOptions.buttons = selectOptions.buttons.concat(options.map(input => {
274276
return {
275277
role: (input.selected ? 'selected' : ''),
276278
text: input.text,
@@ -280,17 +282,21 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
280282
}
281283
};
282284
}));
283-
alertOptions.cssClass = 'select-action-sheet';
285+
var selectCssClass = 'select-action-sheet';
284286

285-
overlay = new ActionSheet(this._app, alertOptions);
287+
// If the user passed a cssClass for the select, add it
288+
selectCssClass += selectOptions.cssClass ? ' ' + selectOptions.cssClass : '';
289+
290+
selectOptions.cssClass = selectCssClass;
291+
overlay = new ActionSheet(this._app, selectOptions);
286292

287293
} else {
288294
// default to use the alert interface
289295
this.interface = 'alert';
290296

291-
// user cannot provide inputs from alertOptions
297+
// user cannot provide inputs from selectOptions
292298
// alert inputs must be created by ionic from ion-options
293-
alertOptions.inputs = this._options.map(input => {
299+
selectOptions.inputs = this._options.map(input => {
294300
return {
295301
type: (this._multi ? 'checkbox' : 'radio'),
296302
label: input.text,
@@ -302,8 +308,8 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
302308

303309
var selectCssClass = 'select-alert';
304310

305-
// create the alert instance from our built up alertOptions
306-
overlay = new Alert(this._app, alertOptions);
311+
// create the alert instance from our built up selectOptions
312+
overlay = new Alert(this._app, selectOptions);
307313

308314
if (this._multi) {
309315
// use checkboxes
@@ -314,7 +320,7 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
314320
}
315321

316322
// If the user passed a cssClass for the select, add it
317-
selectCssClass += alertOptions.cssClass ? ' ' + alertOptions.cssClass : '';
323+
selectCssClass += selectOptions.cssClass ? ' ' + selectOptions.cssClass : '';
318324
overlay.setCssClass(selectCssClass);
319325

320326
overlay.addButton({
@@ -327,7 +333,7 @@ export class Select implements AfterContentInit, ControlValueAccessor, OnDestroy
327333

328334
}
329335

330-
overlay.present(alertOptions);
336+
overlay.present(selectOptions);
331337

332338
this._isOpen = true;
333339
overlay.onDidDismiss(() => {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export interface Currency {
1111
templateUrl: 'main.html'
1212
})
1313
class E2EPage {
14-
musicAlertOpts: any = {
14+
musicSelectOpts: any = {
1515
title: '1994 Music',
1616
subTitle: 'Select your favorite',
1717
cssClass: 'music-select'
1818
};
19+
notificationSelectOpts: any = {
20+
title: 'Mute notifications',
21+
cssClass: 'notification-select'
22+
};
1923
gender: string;
2024
gaming: string = '';
2125
os: string = 'win3.1';
@@ -24,7 +28,7 @@ class E2EPage {
2428
month: string = '12';
2529
year: string = '1994';
2630
notification: string = 'enable';
27-
status: string = "checked";
31+
status: string = 'checked';
2832

2933
currencies: Currency[] = [
3034
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<ion-item>
4646
<ion-label>Notifications</ion-label>
47-
<ion-select [(ngModel)]="notifications" interface="action-sheet" cancelText="Cancel!">
47+
<ion-select [(ngModel)]="notifications" [selectOptions]="notificationSelectOpts" 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>
@@ -54,7 +54,7 @@
5454

5555
<ion-item>
5656
<ion-label>Music</ion-label>
57-
<ion-select [(ngModel)]="music" [alertOptions]="musicAlertOpts" placeholder="Select Music">
57+
<ion-select [(ngModel)]="music" [selectOptions]="musicSelectOpts" placeholder="Select Music">
5858
<ion-option>Alice in Chains</ion-option>
5959
<ion-option>Green Day</ion-option>
6060
<ion-option>Nirvana</ion-option>

0 commit comments

Comments
 (0)