Skip to content

Commit 1df0280

Browse files
committed
fix(select): set modal interface cancel button to "Okay" by default
1 parent 8cfdced commit 1df0280

8 files changed

Lines changed: 21 additions & 9 deletions

core/src/components.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,10 +3022,9 @@ export namespace Components {
30223022
}
30233023
interface IonSelect {
30243024
/**
3025-
* The text to display on the cancel button.
3026-
* @default 'Cancel'
3025+
* The text to display on the cancel button. Defaults to `'Cancel'` for the `alert` and `action-sheet` interfaces, and `'Okay'` for the `modal` interface.
30273026
*/
3028-
"cancelText": string;
3027+
"cancelText"?: string;
30293028
/**
30303029
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics). This property is only available when using the modern select syntax.
30313030
*/
@@ -8205,8 +8204,7 @@ declare namespace LocalJSX {
82058204
}
82068205
interface IonSelect {
82078206
/**
8208-
* The text to display on the cancel button.
8209-
* @default 'Cancel'
8207+
* The text to display on the cancel button. Defaults to `'Cancel'` for the `alert` and `action-sheet` interfaces, and `'Okay'` for the `modal` interface.
82108208
*/
82118209
"cancelText"?: string;
82128210
/**

core/src/components/select/select.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ export class Select implements ComponentInterface {
9494

9595
/**
9696
* The text to display on the cancel button.
97+
* Defaults to `'Cancel'` for the `alert` and `action-sheet`
98+
* interfaces, and `'Okay'` for the `modal` interface.
9799
*/
98-
@Prop() cancelText = 'Cancel';
100+
@Prop() cancelText?: string;
99101

100102
/**
101103
* The color to use from your application's color palette.
@@ -525,6 +527,18 @@ export class Select implements ComponentInterface {
525527
return overlay;
526528
}
527529

530+
/**
531+
* Resolves the cancel button text, falling back to the
532+
* per-interface default when `cancelText` is not set:
533+
* `'Okay'` for the `modal` interface, `'Cancel'` otherwise.
534+
*/
535+
private get interfaceCancelText(): string {
536+
if (this.cancelText !== undefined) {
537+
return this.cancelText;
538+
}
539+
return this.interface === 'modal' ? 'Ok' : 'Cancel';
540+
}
541+
528542
private createOverlay(ev?: UIEvent): Promise<OverlaySelect> {
529543
let selectInterface = this.interface;
530544
if (selectInterface === 'action-sheet' && this.multiple) {
@@ -609,7 +623,7 @@ export class Select implements ComponentInterface {
609623

610624
// Add "cancel" button
611625
actionSheetButtons.push({
612-
text: this.cancelText,
626+
text: this.interfaceCancelText,
613627
role: 'cancel',
614628
handler: () => {
615629
this.ionCancel.emit();
@@ -783,7 +797,7 @@ export class Select implements ComponentInterface {
783797
inputs: this.createAlertInputs(this.childOpts, inputType, this.value),
784798
buttons: [
785799
{
786-
text: this.cancelText,
800+
text: this.interfaceCancelText,
787801
role: 'cancel',
788802
handler: () => {
789803
this.ionCancel.emit();
@@ -830,7 +844,7 @@ export class Select implements ComponentInterface {
830844
component: 'ion-select-modal',
831845
componentProps: {
832846
header: interfaceOptions.header,
833-
cancelText: this.cancelText,
847+
cancelText: this.interfaceCancelText,
834848
multiple,
835849
value,
836850
options: this.createOverlaySelectOptions(this.childOpts, value),
-562 Bytes
Loading
-628 Bytes
Loading
-700 Bytes
Loading
-307 Bytes
Loading
-488 Bytes
Loading
-675 Bytes
Loading

0 commit comments

Comments
 (0)