mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 23:58:13 +08:00
feat(checkbox): ionChange fires on user interaction (#25923)
BREAKING CHANGE: `ionChange` is no longer emitted when the `checked` property of `ion-checkbox` is modified externally. `ionChange` is only emitted from user committed changes, such as clicking or tapping the checkbox.
This commit is contained in:
@ -10,3 +10,52 @@ test.describe('checkbox: basic', () => {
|
||||
expect(await page.screenshot()).toMatchSnapshot(`checkbox-basic-${page.getSnapshotSettings()}.png`);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('checkbox: ionChange', () => {
|
||||
test.beforeEach(({ skip }) => {
|
||||
skip.rtl();
|
||||
});
|
||||
test('should fire ionChange when interacting with checkbox', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<ion-checkbox value="my-checkbox"></ion-checkbox>
|
||||
`);
|
||||
|
||||
const ionChange = await page.spyOnEvent('ionChange');
|
||||
const checkbox = page.locator('ion-checkbox');
|
||||
|
||||
await checkbox.click();
|
||||
await expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
|
||||
|
||||
await checkbox.click();
|
||||
await expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
|
||||
});
|
||||
|
||||
test('should fire ionChange when interacting with checkbox in item', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<ion-item>
|
||||
<ion-checkbox value="my-checkbox"></ion-checkbox>
|
||||
</ion-item>
|
||||
`);
|
||||
|
||||
const ionChange = await page.spyOnEvent('ionChange');
|
||||
const item = page.locator('ion-item');
|
||||
|
||||
await item.click();
|
||||
await expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
|
||||
|
||||
await item.click();
|
||||
await expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
|
||||
});
|
||||
|
||||
test('should not fire when programmatically setting a value', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<ion-checkbox value="my-checkbox"></ion-checkbox>
|
||||
`);
|
||||
|
||||
const ionChange = await page.spyOnEvent('ionChange');
|
||||
const checkbox = page.locator('ion-checkbox');
|
||||
|
||||
await checkbox.evaluate((el: HTMLIonCheckboxElement) => (el.checked = true));
|
||||
await expect(ionChange).not.toHaveReceivedEvent();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user