Skip to content

Commit

Permalink
fix escape in combobox in dialog: no capture:true in radix esc handler
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Dec 10, 2024
1 parent dc5562f commit e75cb1d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions patches/@radix-ui+react-use-escape-keydown+1.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs b/node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs
index 0788d1b..3bb001c 100644
--- a/node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs
+++ b/node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs
@@ -9,8 +9,8 @@ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.docum
onEscapeKeyDown(event);
}
};
- ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
- return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
+ ownerDocument.addEventListener("keydown", handleKeyDown);
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown);
}, [onEscapeKeyDown, ownerDocument]);
}
export {
33 changes: 33 additions & 0 deletions test/e2e/firewall-rules.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,36 @@ test('arbitrary values combobox', async ({ page }) => {
// same options show up after blur (there was a bug around this)
await expectOptions(page, ['db1', 'Custom: d'])
})

test("esc in combobox doesn't close form", async ({ page }) => {
await page.goto('/projects/mock-project/vpcs/mock-vpc/firewall-rules-new')

// make form dirty so we can get the confirm modal on close attempts
await page.getByRole('textbox', { name: 'Name' }).fill('a')

// make sure the confirm modal does pop up on esc when we're not in a combobox
const confirmModal = page.getByRole('dialog', { name: 'Confirm navigation' })
await expect(confirmModal).toBeHidden()
await page.keyboard.press('Escape')
await expect(confirmModal).toBeVisible()
await confirmModal.getByRole('button', { name: 'Keep editing' }).click()
await expect(confirmModal).toBeHidden()

const formModal = page.getByRole('dialog', { name: 'Add firewall rule' })
await expect(formModal).toBeVisible()

const input = page.getByRole('combobox', { name: 'VPC name' }).first()
await input.focus()

await expect(page.getByRole('option').first()).toBeVisible()
await expectOptions(page, ['mock-vpc'])

await page.keyboard.press('Escape')
// options are closed, but the whole form modal is not
await expect(confirmModal).toBeHidden()
await expect(page.getByRole('option')).toBeHidden()
await expect(formModal).toBeVisible()
// now press esc again to leave the form
await page.keyboard.press('Escape')
await expect(confirmModal).toBeVisible()
})

0 comments on commit e75cb1d

Please sign in to comment.