-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(select): emit single ionChange event for popover option selection #26796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sean-perkins
merged 12 commits into
feature-7.0
from
fix/select-popover-duplicate-change-events
Feb 21, 2023
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a717c0e
fix(select): emit single ionChange event for popover option selection
sean-perkins 18c3b36
fix: usage with multiple
sean-perkins c49a12b
fix: select popover dismisses from single selection with keyboard
sean-perkins c67c144
Merge branch 'feature-7.0' into fix/select-popover-duplicate-change-e…
sean-perkins 4abe30c
chore: solve test flakiness
sean-perkins a014c1f
chore: skip flaky test
sean-perkins a753d08
chore: remove invalid enter-key tests
sean-perkins 8b86062
fix: use legacy prop, remove unnecessary tests
sean-perkins 1f4e51a
chore: update warning message, remove unused prop
sean-perkins 76ff317
fix: align keyboard interaction with radio group
sean-perkins 7fcc150
refactor: speed up tests
sean-perkins 62a9d71
Merge branch 'feature-7.0' into fix/select-popover-duplicate-change-e…
sean-perkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 - Popover</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 Popover - Basic</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
<ion-popover class="select-popover" is-open="true"> | ||
<ion-select-popover multiple="false"></ion-select-popover> | ||
</ion-popover> | ||
</ion-content> | ||
</ion-app> | ||
|
||
<script> | ||
const selectPopover = document.querySelector('ion-select-popover'); | ||
selectPopover.options = [ | ||
{ value: 'apple', text: 'Apple', disabled: false, checked: true }, | ||
{ value: 'banana', text: 'Banana', disabled: false, checked: false }, | ||
]; | ||
</script> | ||
</body> | ||
</html> |
65 changes: 65 additions & 0 deletions
65
core/src/components/select-popover/test/basic/select-popover.e2e.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { expect } from '@playwright/test'; | ||
import { test } from '@utils/test/playwright'; | ||
|
||
import type { SelectPopoverOption } from '../../select-popover-interface'; | ||
import { SelectPopoverPage } from '../fixtures'; | ||
|
||
const options: SelectPopoverOption[] = [ | ||
{ value: 'apple', text: 'Apple', disabled: false, checked: false }, | ||
{ value: 'banana', text: 'Banana', disabled: false, checked: false }, | ||
]; | ||
|
||
const checkedOptions: SelectPopoverOption[] = [ | ||
{ value: 'apple', text: 'Apple', disabled: false, checked: true }, | ||
{ value: 'banana', text: 'Banana', disabled: false, checked: false }, | ||
]; | ||
|
||
test.describe('select-popover: basic', () => { | ||
test.beforeEach(({ skip, browserName }) => { | ||
skip.rtl(); | ||
skip.mode('ios', 'Consistent behavior across modes'); | ||
test.skip(browserName === 'webkit', 'https://ionic-cloud.atlassian.net/browse/FW-2979'); | ||
}); | ||
|
||
test.describe('single selection', () => { | ||
let selectPopoverPage: SelectPopoverPage; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
selectPopoverPage = new SelectPopoverPage(page); | ||
}); | ||
|
||
test('clicking an unselected option should dismiss the popover', async () => { | ||
await selectPopoverPage.setup(options, false); | ||
|
||
await selectPopoverPage.clickOption('apple'); | ||
await selectPopoverPage.ionPopoverDidDismiss.next(); | ||
await expect(selectPopoverPage.popover).not.toBeVisible(); | ||
}); | ||
|
||
test('clicking a selected option should dismiss the popover', async () => { | ||
await selectPopoverPage.setup(checkedOptions, false); | ||
|
||
await selectPopoverPage.clickOption('apple'); | ||
await selectPopoverPage.ionPopoverDidDismiss.next(); | ||
await expect(selectPopoverPage.popover).not.toBeVisible(); | ||
}); | ||
|
||
test('pressing Space on an unselected option should dismiss the popover', async () => { | ||
await selectPopoverPage.setup(options, false); | ||
|
||
await selectPopoverPage.pressSpaceOnOption('apple'); | ||
await selectPopoverPage.ionPopoverDidDismiss.next(); | ||
await expect(selectPopoverPage.popover).not.toBeVisible(); | ||
}); | ||
|
||
test('pressing Space on a selected option should dismiss the popover', async ({ browserName }) => { | ||
test.skip(browserName === 'firefox', 'Same behavior as https://ionic-cloud.atlassian.net/browse/FW-2979'); | ||
|
||
await selectPopoverPage.setup(checkedOptions, false); | ||
|
||
await selectPopoverPage.pressSpaceOnOption('apple'); | ||
await selectPopoverPage.ionPopoverDidDismiss.next(); | ||
await expect(selectPopoverPage.popover).not.toBeVisible(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { E2EPage, E2ELocator, EventSpy } from '@utils/test/playwright'; | ||
|
||
import type { SelectPopoverOption } from '../select-popover-interface'; | ||
|
||
export class SelectPopoverPage { | ||
private page: E2EPage; | ||
private multiple?: boolean; | ||
private options: SelectPopoverOption[] = []; | ||
|
||
// Locators | ||
popover!: E2ELocator; | ||
selectPopover!: E2ELocator; | ||
|
||
// Event spies | ||
ionPopoverDidDismiss!: EventSpy; | ||
|
||
constructor(page: E2EPage) { | ||
this.page = page; | ||
} | ||
|
||
async setup(options: SelectPopoverOption[], multiple = false) { | ||
const { page } = this; | ||
|
||
await page.setContent(` | ||
<ion-popover> | ||
<ion-select-popover></ion-select-popover> | ||
</ion-popover> | ||
<script> | ||
const selectPopover = document.querySelector('ion-select-popover'); | ||
selectPopover.options = ${JSON.stringify(options)}; | ||
selectPopover.multiple = ${multiple}; | ||
</script> | ||
`); | ||
|
||
const ionPopoverDidPresent = await page.spyOnEvent('ionPopoverDidPresent'); | ||
this.ionPopoverDidDismiss = await page.spyOnEvent('ionPopoverDidDismiss'); | ||
|
||
this.popover = page.locator('ion-popover'); | ||
this.selectPopover = page.locator('ion-select-popover'); | ||
this.multiple = multiple; | ||
this.options = options; | ||
|
||
await this.popover.evaluate((popover: HTMLIonPopoverElement) => popover.present()); | ||
|
||
await ionPopoverDidPresent.next(); | ||
} | ||
|
||
async clickOption(value: string) { | ||
const option = this.getOption(value); | ||
await option.click(); | ||
} | ||
|
||
async pressSpaceOnOption(value: string) { | ||
const option = this.getOption(value); | ||
await option.press('Space'); | ||
} | ||
|
||
private getOption(value: string) { | ||
const { multiple, selectPopover } = this; | ||
const selector = multiple ? 'ion-checkbox' : 'ion-radio'; | ||
const index = this.options.findIndex((o) => o.value === value); | ||
|
||
return selectPopover.locator(selector).nth(index); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './playwright-page'; | ||
export * from './playwright-declarations'; | ||
export * from './page/event-spy'; | ||
export * from './page/utils'; | ||
export * from './drag-element'; | ||
export * from './matchers'; | ||
export * from './viewports'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are good with the wording here, I can follow-up with another PR to apply across all form controls for v7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍