Skip to content

Commit d144e7d

Browse files
authored
Prevent the sidemodal form from immediately erroring when using the action menu (#2617)
* prevent event bubbling when the enter key is hit to select a menu item in the action menu * Add test * Move ActionMenu tests to dedicated file * Use a more universal check for the openActionMenu helper
1 parent c147df0 commit d144e7d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

app/ui/lib/ActionMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function ActionMenu(props: ActionMenuProps) {
9999
if (e.key === KEYS.enter) {
100100
if (selectedItem) {
101101
selectedItem.onSelect()
102+
e.preventDefault()
102103
onDismiss()
103104
}
104105
} else if (e.key === KEYS.down) {

test/e2e/action-menu.e2e.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import { expect, test, type Page } from '@playwright/test'
9+
10+
import { expectNotVisible } from './utils'
11+
12+
const openActionMenu = async (page: Page) => {
13+
// open the action menu (use the sidenav button, as keyboard events aren't reliable in Playwright)
14+
await page.getByRole('button', { name: 'JUMP TO' }).click()
15+
// make sure the action menu modal is visible
16+
await expect(page.getByText('Enterto submit')).toBeVisible()
17+
}
18+
19+
test('Ensure that the Enter key in the ActionMenu doesn’t prematurely submit a linked form', async ({
20+
page,
21+
}) => {
22+
await page.goto('/system/silos')
23+
await openActionMenu(page)
24+
// "New silo" is the first item in the list, so we can just hit enter to open the modal
25+
await page.keyboard.press('Enter')
26+
await expect(page.getByRole('dialog', { name: 'Create silo' })).toBeVisible()
27+
// make sure error text is not visible
28+
await expectNotVisible(page, [page.getByText('Name is required')])
29+
})

0 commit comments

Comments
 (0)