Skip to content

Commit

Permalink
refactor(timepicker): ♻️ add guard clause to createonkeydown
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Oct 12, 2020
1 parent 0a514ad commit 9e46551
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/timepicker/TimePickerContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ export const useTimePickerContent = createHook<
keyMap: () => {
return {
ArrowRight: () => {
if (ref.current) {
const nextTabbableElement = getNextTabbable(ref.current);
if (nextTabbableElement) {
focus(nextTabbableElement);
}
if (!ref.current) return;

const nextTabbableElement = getNextTabbable(ref.current);
if (nextTabbableElement) {
focus(nextTabbableElement);
}
},
ArrowLeft: () => {
if (ref.current) {
const previousTabbableElement = getPreviousTabbable(
ref.current,
);
if (previousTabbableElement) {
focus(previousTabbableElement);
}
if (!ref.current) return;

const previousTabbableElement = getPreviousTabbable(ref.current);
if (previousTabbableElement) {
focus(previousTabbableElement);
}
},
};
Expand Down

0 comments on commit 9e46551

Please sign in to comment.