Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ ion-select,part,supporting-text
ion-select,part,text

ion-select-modal,scoped
ion-select-modal,prop,cancelText,string,'Close',false,false
ion-select-modal,prop,header,string | undefined,undefined,false,false
ion-select-modal,prop,multiple,boolean | undefined,undefined,false,false
ion-select-modal,prop,options,SelectModalOption[],[],false,false
Expand Down
10 changes: 10 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,11 @@ export namespace Components {
"value"?: any | null;
}
interface IonSelectModal {
/**
* The text to display on the cancel button.
* @default 'Close'
*/
"cancelText": string;
"header"?: string;
"multiple"?: boolean;
/**
Expand Down Expand Up @@ -8548,6 +8553,11 @@ declare namespace LocalJSX {
"value"?: any | null;
}
interface IonSelectModal {
/**
* The text to display on the cancel button.
* @default 'Close'
*/
"cancelText"?: string;
"header"?: string;
"multiple"?: boolean;
/**
Expand Down
7 changes: 6 additions & 1 deletion core/src/components/select-modal/select-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export class SelectModal implements ComponentInterface {

@Prop() header?: string;

/**
* The text to display on the cancel button.
*/
@Prop() cancelText = 'Close';

@Prop() multiple?: boolean;

@Prop() options: SelectModalOption[] = [];
Expand Down Expand Up @@ -149,7 +154,7 @@ export class SelectModal implements ComponentInterface {
{this.header !== undefined && <ion-title>{this.header}</ion-title>}

<ion-buttons slot="end">
<ion-button onClick={() => this.closeModal()}>Close</ion-button>
<ion-button onClick={() => this.closeModal()}>{this.cancelText}</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
Expand Down
40 changes: 40 additions & 0 deletions core/src/components/select-modal/test/custom/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Select - Custom</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
</head>

<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Select Modal - Custom</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-modal is-open="true">
<ion-select-modal multiple="false" cancel-text="Close me"></ion-select-modal>
</ion-modal>
</ion-content>
</ion-app>

<script>
const selectModal = document.querySelector('ion-select-modal');
selectModal.options = [
{ value: 'apple', text: 'Apple', disabled: false, checked: true },
{ value: 'banana', text: 'Banana', disabled: false, checked: false },
];
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

import type { SelectModalOption } from '../../select-modal-interface';
import { SelectModalPage } from '../fixtures';

const options: SelectModalOption[] = [
{ value: 'apple', text: 'Apple', disabled: false, checked: false },
{ value: 'banana', text: 'Banana', disabled: false, checked: false },
];

/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('select-modal: custom'), () => {
let selectModalPage: SelectModalPage;

test.beforeEach(async ({ page }) => {
selectModalPage = new SelectModalPage(page);
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
test('should render custom cancel text when prop is provided', async ({ page: _page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30295',
});

await selectModalPage.setup(config, options, false);

const cancelButton = selectModalPage.selectModal.locator('ion-button');

// Verify the default text on the cancel button
await expect(cancelButton).toHaveText('Close');

await selectModalPage.selectModal.evaluate((selectModal: HTMLIonSelectModalElement) => {
selectModal.cancelText = 'Close me';
});

// Verify the cancel button text has been updated
await expect(cancelButton).toHaveText('Close me');
});
});
});
1 change: 1 addition & 0 deletions core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ export class Select implements ComponentInterface {
component: 'ion-select-modal',
componentProps: {
header: interfaceOptions.header,
cancelText: this.cancelText,
multiple,
value,
options: this.createOverlaySelectOptions(this.childOpts, value),
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is the cancel button text. Since we are passing the cancel button text from select, it now uses the default value that select sets for cancel button. I believe this is actually a fix because it lines up with the other interfaces.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions core/src/components/select/test/custom/select.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,91 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
const wrapper = page.locator('.wrapper');
await expect(wrapper).toHaveScreenshot(screenshot(`select-custom-parts-diff`));
});

test('should render custom cancel text when prop is provided with alert interface', async ({ page }) => {
await page.setContent(
`
<ion-select label="Fruit" interface="alert" value="bananas" cancel-text="Close me">
<ion-select-option value="apples">Apples</ion-select-option>
<ion-select-option value="bananas">Bananas</ion-select-option>
<ion-select-option value="oranges">Oranges</ion-select-option>
</ion-select>
`,
config
);

const select = page.locator('ion-select');
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');

await select.click();
await ionAlertDidPresent.next();

await page.waitForChanges();

const alert = page.locator('ion-alert');
const cancelButton = alert.locator('.alert-button-role-cancel');

// Verify the cancel button text
await expect(cancelButton).toHaveText('Close me');
});

test('should render custom cancel text when prop is provided with action sheet interface', async ({ page }) => {
await page.setContent(
`
<ion-select label="Fruit" interface="action-sheet" value="bananas" cancel-text="Close me">
<ion-select-option value="apples">Apples</ion-select-option>
<ion-select-option value="bananas">Bananas</ion-select-option>
<ion-select-option value="oranges">Oranges</ion-select-option>
</ion-select>
`,
config
);

const select = page.locator('ion-select');
const ionActionSheetDidPresent = await page.spyOnEvent('ionActionSheetDidPresent');

await select.click();
await ionActionSheetDidPresent.next();

await page.waitForChanges();

const actionSheet = page.locator('ion-action-sheet');
const cancelButton = actionSheet.locator('.action-sheet-cancel');

// Verify the cancel button text
await expect(cancelButton).toHaveText('Close me');
});

test('should render custom cancel text when prop is provided with modal interface', async ({ page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30295',
});

await page.setContent(
`
<ion-select label="Fruit" interface="modal" value="bananas" cancel-text="Close me">
<ion-select-option value="apples">Apples</ion-select-option>
<ion-select-option value="bananas">Bananas</ion-select-option>
<ion-select-option value="oranges">Oranges</ion-select-option>
</ion-select>
`,
config
);

const select = page.locator('ion-select');
const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent');

await select.click();
await ionModalDidPresent.next();

await page.waitForChanges();

const modal = page.locator('ion-modal');
const cancelButton = modal.locator('ion-button');

// Verify the cancel button text
await expect(cancelButton).toHaveText('Close me');
});
});
});
4 changes: 2 additions & 2 deletions packages/angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,14 +2192,14 @@ This event will not emit when programmatically setting the `value` property.


@ProxyCmp({
inputs: ['header', 'multiple', 'options']
inputs: ['cancelText', 'header', 'multiple', 'options']
})
@Component({
selector: 'ion-select-modal',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['header', 'multiple', 'options'],
inputs: ['cancelText', 'header', 'multiple', 'options'],
})
export class IonSelectModal {
protected el: HTMLIonSelectModalElement;
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/standalone/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1921,14 +1921,14 @@ export declare interface IonSegmentView extends Components.IonSegmentView {

@ProxyCmp({
defineCustomElementFn: defineIonSelectModal,
inputs: ['header', 'multiple', 'options']
inputs: ['cancelText', 'header', 'multiple', 'options']
})
@Component({
selector: 'ion-select-modal',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['header', 'multiple', 'options'],
inputs: ['cancelText', 'header', 'multiple', 'options'],
standalone: true
})
export class IonSelectModal {
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ export const IonSelect: StencilVueComponent<JSX.IonSelect, JSX.IonSelect["value"

export const IonSelectModal: StencilVueComponent<JSX.IonSelectModal> = /*@__PURE__*/ defineContainer<JSX.IonSelectModal>('ion-select-modal', defineIonSelectModal, [
'header',
'cancelText',
'multiple',
'options'
]);
Expand Down
Loading