Skip to content
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

Closed

Conversation

frontsideair
Copy link

@frontsideair frontsideair commented Oct 6, 2020

Thank you for contributing to Reach UI! Please fill in this template before submitting your PR to help us process your request more quickly.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code (Compile and run).
  • Add or edit tests to reflect the change (Run with yarn test).
  • Add or edit Storybook examples to reflect the change (Run with yarn start).
  • Ensure formatting is consistent with the project's Prettier configuration.
  • Add documentation to support any new features.

This pull request:

  • Creates a new package
  • Fixes a bug in an existing package
  • Adds additional features/functionality to an existing package
  • Updates documentation or example code
  • Other

If creating a new package:

  • Make sure the new package directory contains each of the following, and that their structure/formatting mirrors other related examples in the project:
    • examples directory
    • src directory with an index.tsx entry file
    • At least one example file per feature introduced by the new package
    • Base styles in a style.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.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 6, 2020

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:

Sandbox Source
reach/reach-ui: reach-ui Configuration
Reach UI escape issue Issue #395


await userEvent.type(input, "{esc}");

expect(queryByTestId("list")).not.toBeInTheDocument();
Copy link
Collaborator

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 frontsideair marked this pull request as draft October 9, 2020 09:42
@chaance chaance added the Type: Enhancement General improvements or suggestions label Nov 17, 2020
@stale stale bot closed this Oct 11, 2021
@indiesquidge
Copy link
Collaborator

@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();
+   }
+ }}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Escape key closes multiple components
3 participants