From ea7a764b57e8d6fbeb86880babb072c06d41efc5 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Thu, 19 Dec 2019 14:06:41 -0600 Subject: [PATCH 1/6] Ensure enter key closes the menu --- src/use-dropdown-menu.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/use-dropdown-menu.ts b/src/use-dropdown-menu.ts index f58c2d8..ebf43d9 100644 --- a/src/use-dropdown-menu.ts +++ b/src/use-dropdown-menu.ts @@ -82,8 +82,12 @@ export default function useDropdownMenu(itemCount: number) { } else if (key === 'Tab') { setIsOpen(false); return; - } else if (key === 'Enter' && !e.currentTarget.href) { - e.currentTarget.click(); + } else if (key === 'Enter') { + if (!e.currentTarget.href) { + e.currentTarget.click(); + } + + setIsOpen(false); return; } From b8586130e5bbe602aab9d775500e037b12e64fb4 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Thu, 19 Dec 2019 14:50:35 -0600 Subject: [PATCH 2/6] Tweak the wording of the behavior --- demo/src/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/app.tsx b/demo/src/app.tsx index f9cb191..b6c7c7d 100644 --- a/demo/src/app.tsx +++ b/demo/src/app.tsx @@ -48,7 +48,7 @@ const App: React.FC = () => {
  • The up / down arrow keys allow for navigation through the menu items
  • Pressing tab will close the menu and move the focus to the next focusable element
  • Pressing escape will close the menu and return the focus to the button
  • -
  • Pressing enter will trigger that item (whether itʼs a link or has a click handler attached)
  • +
  • Pressing enter will activate that item and close the menu (whether itʼs a link or has a click handler attached)
  • From 2474e32ce236b1008109ee3e83bfb9984ad5b900 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Thu, 19 Dec 2019 15:05:50 -0600 Subject: [PATCH 3/6] Strip out unnecessary code from test component --- test/test-component.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test-component.tsx b/test/test-component.tsx index 8818b2a..ab8f795 100644 --- a/test/test-component.tsx +++ b/test/test-component.tsx @@ -1,5 +1,5 @@ // Imports -import React from 'react'; +import React, { useState } from 'react'; import useDropdownMenu from '../src/use-dropdown-menu'; // A mock component for testing the Hook @@ -8,25 +8,25 @@ const TestComponent: React.FC = () => { return ( - - - + {isOpen ? 'true' : 'false'} From de75478e24dc7183bcf59ffb6697c985723d3bb5 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Thu, 19 Dec 2019 15:14:34 -0600 Subject: [PATCH 6/6] Format the code --- demo/src/app.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demo/src/app.tsx b/demo/src/app.tsx index b6c7c7d..ac4085a 100644 --- a/demo/src/app.tsx +++ b/demo/src/app.tsx @@ -48,7 +48,10 @@ const App: React.FC = () => {
  • The up / down arrow keys allow for navigation through the menu items
  • Pressing tab will close the menu and move the focus to the next focusable element
  • Pressing escape will close the menu and return the focus to the button
  • -
  • Pressing enter will activate that item and close the menu (whether itʼs a link or has a click handler attached)
  • +
  • + Pressing enter will activate that item and close the menu (whether itʼs a link or has a click handler + attached) +