Skip to content

Commit 248a1ce

Browse files
committed
fix(datetime): avoid adding cancel and done button repeatedly
references #7333
1 parent 75cf887 commit 248a1ce

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/components/datetime/datetime.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,20 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
525525
// the user may have assigned some options specifically for the picker
526526
const pickerOptions = {...this.pickerOptions};
527527

528-
// Configure picker under the hood
529-
const picker = this._picker = this._pickerCtrl.create(pickerOptions);
530-
picker.addButton({
528+
// Add a cancel and done button by default to the picker
529+
const defaultButtons = [{
531530
text: this.cancelText,
532531
role: 'cancel',
533532
handler: () => this.ionCancel.emit(this)
534-
});
535-
picker.addButton({
533+
}, {
536534
text: this.doneText,
537535
handler: (data: any) => this.value = data,
538-
});
536+
}];
537+
538+
pickerOptions.buttons = (pickerOptions.buttons || []).concat(defaultButtons);
539+
540+
// Configure picker under the hood
541+
const picker = this._picker = this._pickerCtrl.create(pickerOptions);
539542

540543
picker.ionChange.subscribe(() => {
541544
this.validate();

0 commit comments

Comments
 (0)