Skip to content

Commit

Permalink
refactor: ♻️ Move the isSpaceKeyDown check to a helper function for r…
Browse files Browse the repository at this point in the history
…euse

Closes Hacker0x01#4482
  • Loading branch information
Balaji Sridharan committed Feb 13, 2024
1 parent 95169b0 commit 7e82975
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,8 @@ export function isDateBefore(date, dateToCompare) {

return isBefore(midnightDate, midnightDateToCompare);
}

export function isSpaceKeyDown(event) {
const SPACE_KEY = " ";
return event.key === SPACE_KEY;
}
3 changes: 1 addition & 2 deletions src/month.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,7 @@ export default class Month extends React.Component {
this.onMonthClick(ev, m);
}}
onKeyDown={(ev) => {
const SPACE_KEY = " ";
if (ev.key === SPACE_KEY) {
if (utils.isSpaceKeyDown(ev)) {
ev.preventDefault();
ev.key = "Enter";
}
Expand Down
3 changes: 1 addition & 2 deletions src/year.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ export default class Year extends React.Component {
this.onYearClick(ev, y);
}}
onKeyDown={(ev) => {
const SPACE_KEY = " ";
if (ev.key === SPACE_KEY) {
if (utils.isSpaceKeyDown(ev)) {
ev.preventDefault();
ev.key = "Enter";
}
Expand Down

0 comments on commit 7e82975

Please sign in to comment.