Skip to content

Commit 2eed5e2

Browse files
committed
fix(select): emit the ionSelect option when selecting an option
1 parent f43539e commit 2eed5e2

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

src/components/alert/alert-component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ export class AlertCmp {
145145
label: input.label,
146146
checked: !!input.checked,
147147
disabled: !!input.disabled,
148-
id: 'alert-input-' + this.id + '-' + index
148+
id: 'alert-input-' + this.id + '-' + index,
149+
handler: isPresent(input.handler) ? input.handler : null,
149150
};
150151
});
151152

@@ -237,12 +238,20 @@ export class AlertCmp {
237238
input.checked = (checkedInput === input);
238239
});
239240
this.activeId = checkedInput.id;
241+
242+
if (checkedInput.handler) {
243+
checkedInput.handler(checkedInput);
244+
}
240245
}
241246
}
242247

243248
cbClick(checkedInput: any) {
244249
if (this.enabled) {
245250
checkedInput.checked = !checkedInput.checked;
251+
252+
if (checkedInput.handler) {
253+
checkedInput.handler(checkedInput);
254+
}
246255
}
247256
}
248257

src/components/select/select.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
296296
handler: () => {
297297
this.onChange(input.value);
298298
this.ionChange.emit(input.value);
299+
input.ionSelect.emit(input.value);
299300
}
300301
};
301302
}));
@@ -319,7 +320,14 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
319320
label: input.text,
320321
value: input.value,
321322
checked: input.selected,
322-
disabled: input.disabled
323+
disabled: input.disabled,
324+
handler: (selectedOption: any) => {
325+
// Only emit the select event if it is being checked
326+
// For multi selects this won't emit when unchecking
327+
if (selectedOption.checked) {
328+
input.ionSelect.emit(input.value);
329+
}
330+
}
323331
};
324332
});
325333

src/components/select/test/multiple-value/app-module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class E2EPage {
4141
console.log('onSubmit', data);
4242
}
4343

44+
toppingsSelect(selectedValue: any) {
45+
console.log('Selected', selectedValue);
46+
}
47+
4448
}
4549

4650

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<ion-option value="mushrooms">Mushrooms</ion-option>
2020
<ion-option value="onions">Onions</ion-option>
2121
<ion-option value="pepperoni">Pepperoni</ion-option>
22-
<ion-option value="pineapple">Pineapple</ion-option>
22+
<ion-option value="pineapple" (ionSelect)="toppingsSelect($event)">Pineapple</ion-option>
2323
<ion-option value="sausage">Sausage</ion-option>
2424
<ion-option value="Spinach">Spinach</ion-option>
2525
</ion-select>

src/components/select/test/single-value/app-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ export class E2EPage {
6767
console.log('Gaming Select, Change value:', selectedValue);
6868
}
6969

70-
stpSelect() {
71-
console.log('STP selected');
70+
musicSelect(selectedValue: any) {
71+
console.log('Music selected', selectedValue);
72+
}
73+
74+
notificationSelect(selectedValue: any) {
75+
console.log('Notification select', selectedValue);
7276
}
7377

7478
statusChange(ev: string) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
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>
51-
<ion-option value="mute_year">Mute for a year</ion-option>
51+
<ion-option value="mute_year" (ionSelect)="notificationSelect($event)">Mute for a year</ion-option>
5252
</ion-select>
5353
</ion-item>
5454

@@ -61,7 +61,7 @@
6161
<ion-option>Pearl Jam</ion-option>
6262
<ion-option>Smashing Pumpkins</ion-option>
6363
<ion-option>Soundgarden</ion-option>
64-
<ion-option (ionSelect)="stpSelect()">Stone Temple Pilots</ion-option>
64+
<ion-option (ionSelect)="musicSelect($event)">Stone Temple Pilots</ion-option>
6565
</ion-select>
6666
</ion-item>
6767

0 commit comments

Comments
 (0)