Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Mar 14, 2024
1 parent 8e93f0a commit 8587f7a
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,25 @@ export const CalendarMonth = ({
const MIN_YEAR = 1900;
const MAX_YEAR = 2100;

const handleYearInputChange = (event: React.FormEvent<HTMLInputElement>) => {
const yearStr = event.currentTarget.value;

if (/^\d{0,4}$/.test(yearStr)) {
setYearInput(yearStr);

if (yearStr.length === 4) {
const yearNum = Number(yearStr);
if (yearNum >= MIN_YEAR && yearNum <= MAX_YEAR) {
const newDate = changeYear(yearNum);
setFocusedDate(newDate);
setHoveredDate(newDate);
setShouldFocus(false);
onMonthChange(event, newDate);
} else {
// If the year is not valid, reset the year input to the last valid year.
setYearInput(yearFormatted.toString());
}
const handleYearInputChange = (event: React.FormEvent<HTMLInputElement>, yearStr: string) => {
if (!/^\d{0,4}$/.test(yearStr)) {
return;
}

setYearInput(yearStr);

if (yearStr.length === 4) {
const yearNum = Number(yearStr);

if (yearNum >= MIN_YEAR && yearNum <= MAX_YEAR) {
const newDate = changeYear(yearNum);
setFocusedDate(newDate);
setHoveredDate(newDate);
setShouldFocus(false);
focusRef.current?.blur();
onMonthChange(event, newDate);
} else {
setYearInput(yearFormatted.toString());
}
}
};
Expand Down

0 comments on commit 8587f7a

Please sign in to comment.