-
Notifications
You must be signed in to change notification settings - Fork 561
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
Stop Combobox Esc propagation #683
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b9a83df:
|
|
||
await userEvent.type(input, "{esc}"); | ||
|
||
expect(queryByTestId("list")).not.toBeInTheDocument(); |
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.
@frontsideair thanks for your PR contribution!
The issue with your test seems to be the use of queryByTestId
. Using ByTestId
is not recommended if there are other queries more inline with how the software is used by people or screen readers. We can use ByRole
for most things associated with Combobox, and indeed your tests pass with these query selectors.
Given #395 also cares about the event propagating, we should also assert that our dialog remains open when escape is pressed. Perhaps something like this:
it("should not close the dialog when Esc key is pressed", async () => {
let { getByRole, queryByRole } = render(<BasicDialog />);
let input = getByRole("combobox");
expect(getByRole("dialog")).toBeInTheDocument();
await userEvent.type(input, "e");
expect(getByRole("listbox")).toBeInTheDocument();
await userEvent.type(input, "{esc}");
// escape should close our listbox
expect(queryByRole("listbox")).not.toBeInTheDocument();
// but our dialog should still be open
expect(queryByRole("dialog")).toBeInTheDocument();
});
@frontsideair it's worth pointing out that your goal of preventing the escape button from propagating up to the dialog your combobox is rendered in and closing the dialog can be prevented in your product code, without having to change Reach UI's Combobox. All Reach UI event handlers are composed in such a way that allows the consumer of the component to still access the event in their own handler. <ComboboxInput
+ onKeyDown={(event) => {
+ if (event.key === "Escape") {
+ event.stopPropagation();
+ }
+ }}
/> |
Thank you for contributing to Reach UI! Please fill in this template before submitting your PR to help us process your request more quickly.
yarn test
).yarn start
).This pull request:
If creating a new package:
examples
directorysrc
directory with anindex.tsx
entry filestyle.css
file (if needed by the new package)This PR is to fix #395 but the suggested fix doesn't seem like it works. At least the test would be useful.