Skip to content

Commit

Permalink
feat: Close dropdown with Esc
Browse files Browse the repository at this point in the history
  • Loading branch information
EnMod committed Sep 6, 2024
1 parent 24c1285 commit ac022de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@hashicorp/react-alert-banner": "^7.1.0",
"@hashicorp/react-button": "^6.3.1",
"@hashicorp/react-code-block": "^6.7.0",
"@hashicorp/react-components": "^0.0.0-canary.524cb71",
"@hashicorp/react-components": "^0.0.0-canary.b79ea47",
"@hashicorp/react-consent-manager": "^9.3.0",
"@hashicorp/react-content": "^8.3.0",
"@hashicorp/react-design-system-components": "0.0.0-nightly.05f1ad1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SUPPORTED_ICONS } from 'content/supported-icons'
import { ProductSlug } from 'types/products'
import useCurrentPath from 'hooks/use-current-path'
import useOnClickOutside from 'hooks/use-on-click-outside'
import useOnEscapeKeyDown from 'hooks/use-on-escape-key-down'
import useOnFocusOutside from 'hooks/use-on-focus-outside'
import useOnRouteChangeStart from 'hooks/use-on-route-change-start'
import deriveKeyEventState from 'lib/derive-key-event-state'
Expand Down Expand Up @@ -63,6 +64,9 @@ const NavigationHeaderDropdownMenu = ({
// Handles closing the menu if focus moves outside of it and it is open.
useOnFocusOutside([menuRef], () => setIsOpen(false), isOpen)

// Handles closing the menu if Esc is pressed while navigating with a keyboard and the menu is focused.
useOnEscapeKeyDown([menuRef], () => setIsOpen(false), isOpen)

// Check for a visible icon or label
if (!label && !hasLeadingIcon) {
throw new Error(
Expand Down

0 comments on commit ac022de

Please sign in to comment.