Skip to content

Commit

Permalink
fix: Fix Checkbox toggling twice on space bar key on Firefox (#369)
Browse files Browse the repository at this point in the history
Closes #368
  • Loading branch information
diegohaz committed May 31, 2019
1 parent cc5ae58 commit 27e9b63
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/reakit/src/Tabbable/Tabbable.ts
Expand Up @@ -123,26 +123,27 @@ export const useTabbable = unstable_createHook<
const onKeyDown = React.useCallback(
(event: React.KeyboardEvent) => {
if (options.disabled) return;
if (
clickKeysRef.current === defaultClickKeys &&
isNativeTabbable(event.target)
) {
return;
}

if (
const isClickKey =
clickKeysRef.current &&
clickKeysRef.current.indexOf(event.key) !== -1
) {
event.preventDefault();
event.target.dispatchEvent(
new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: false
})
);
clickKeysRef.current.indexOf(event.key) !== -1;

if (!isClickKey) return;

const isDefaultClickKey = defaultClickKeys.indexOf(event.key) !== -1;

if (isDefaultClickKey && isNativeTabbable(event.target)) {
return;
}

event.preventDefault();
event.target.dispatchEvent(
new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: false
})
);
},
[options.disabled]
);
Expand Down

0 comments on commit 27e9b63

Please sign in to comment.