Skip to content

Commit

Permalink
Merge pull request #2457 from SpareBank1/develop_fix-datepicker-scroll
Browse files Browse the repository at this point in the history
fix(ffe-datepicker-react): prevent scroll when arrow buttons are pres…
  • Loading branch information
pethel authored Dec 19, 2024
2 parents 443b6f9 + bd1e291 commit 982f16c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ffe-datepicker-react/src/datepicker/SpinButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ export const SpinButton = React.forwardRef<HTMLSpanElement, SpinButtonProps>(
history.current = [];
onSpinButtonChange(history.current);
} else if (evt.key === 'ArrowUp') {
evt.preventDefault();
let newValue = (value ?? 0) + 1;
if (newValue && newValue !== null && newValue > max) {
newValue = min;
}
onSpinButtonChange([newValue], false);
} else if (evt.key === 'ArrowDown') {
evt.preventDefault();
let newValue = (value ?? 0) - 1;
if (newValue < min) {
newValue = max;
}
onSpinButtonChange([newValue], false);
} else if (evt.key === 'ArrowLeft') {
evt.preventDefault();
prevSpinButton?.current?.focus();
} else if (evt.key === 'ArrowRight') {
evt.preventDefault();
nextSpinButton?.current?.focus();
}
};
Expand Down

0 comments on commit 982f16c

Please sign in to comment.