forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web-components): fix enterkey interaction on menu (microsoft#31894)
- Loading branch information
1 parent
16b43e3
commit 2ccb9dd
Showing
5 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-e417861e-ef1b-4b4f-8c25-fef57cda85d9.json
This file contains 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,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "fix(web-components): fix menu enterkey interaction ", | ||
"packageName": "@fluentui/web-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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 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,165 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import type { Locator, Page } from '@playwright/test'; | ||
import { fixtureURL } from '../helpers.tests.js'; | ||
import type { Menu } from './menu.js'; | ||
|
||
const menuFixture = ` | ||
<fluent-menu> | ||
<fluent-menu-button appearance="primary" slot="trigger">Toggle Menu</fluent-menu-button> | ||
<fluent-menu-list> | ||
<fluent-menu-item>Menu item 1</fluent-menu-item> | ||
<fluent-menu-item>Menu item 2</fluent-menu-item> | ||
<fluent-menu-item>Menu item 3</fluent-menu-item> | ||
<fluent-menu-item>Menu item 4</fluent-menu-item> | ||
</fluent-menu-list> | ||
</fluent-menu> | ||
`; | ||
|
||
test.describe('Menu', () => { | ||
let page: Page; | ||
let element: Locator; | ||
let menuButton: Locator; | ||
let menuList: Locator; | ||
let menuItems: Locator; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
|
||
element = page.locator('fluent-menu'); | ||
|
||
menuButton = element.locator('fluent-menu-button'); | ||
|
||
menuList = element.locator('fluent-menu-list'); | ||
|
||
menuItems = menuList.locator('fluent-menu-item'); | ||
|
||
await page.goto(fixtureURL('components-menu--default')); | ||
|
||
page.setContent(menuFixture); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test('should have menu-list be initially hidden', async () => { | ||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should be visible when the button is clicked', async () => { | ||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
}); | ||
|
||
test('should be hidden when the button is clicked again', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should be hidden when an item is clicked', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await menuItems.first().click(); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should close when an item is keyboard clicked', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await menuItems.first().focus(); | ||
|
||
await page.keyboard.press('Enter'); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should be hidden when clicked outside', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await page.mouse.click(0, 0); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should be hidden when the escape key is pressed', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await page.keyboard.press('Escape'); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should be hidden when the escape key is pressed on an item', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await menuButton.click(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
|
||
await menuItems.first().focus(); | ||
|
||
await page.keyboard.press('Escape'); | ||
|
||
await expect(menuList).toBeHidden(); | ||
}); | ||
|
||
test('should open on hover when openOnHover is true', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await expect(menuList).toBeHidden(); | ||
await menuButton.hover(); | ||
await expect(menuList).toBeHidden(); | ||
await page.mouse.move(0, 0); | ||
|
||
await element.evaluate((x: Menu) => { | ||
x.openOnHover = true; | ||
}); | ||
|
||
await expect(menuList).toBeHidden(); | ||
|
||
await menuButton.hover(); | ||
|
||
await expect(menuList).toBeVisible(); | ||
}); | ||
|
||
test('should open on context when openOnContext is true', async () => { | ||
page.setContent(menuFixture); | ||
|
||
await expect(menuList).toBeHidden(); | ||
await menuButton.click({ button: 'right' }); | ||
await expect(menuList).toBeHidden(); | ||
|
||
await element.evaluate((x: Menu) => { | ||
x.openOnContext = true; | ||
}); | ||
|
||
await expect(menuList).toBeHidden(); | ||
await menuButton.dispatchEvent('contextmenu'); | ||
await expect(menuList).toBeVisible(); | ||
}); | ||
}); |
This file contains 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 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