Skip to content

Commit a6b52ea

Browse files
authored
fix: fixes focus moving to next cell when using arrow keys on slider (#1338)
Previously when using the Arrow Keys for changing the range slider the focus would move to the next/previous cell. This is now prevented. The only downside is that the user has to press Tab again to move the focus outside of the slider, which in my point should be okay as he has to tab in to get focus. Additionally this is now consistent with text input filters. Fixes #1254
1 parent 780c269 commit a6b52ea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/material-react-table/src/components/inputs/MRT_FilterRangeSlider.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export const MRT_FilterRangeSlider = <TData extends MRT_RowData>({
5454

5555
const isMounted = useRef(false);
5656

57+
// prevent moving the focus to the next/prev cell when using the arrow keys
58+
const handleKeyDown = (event: React.KeyboardEvent) => {
59+
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
60+
event.stopPropagation();
61+
}
62+
};
63+
5764
useEffect(() => {
5865
if (isMounted.current) {
5966
if (columnFilterValue === undefined) {
@@ -84,6 +91,7 @@ export const MRT_FilterRangeSlider = <TData extends MRT_RowData>({
8491
}
8592
}
8693
}}
94+
onKeyDown={handleKeyDown}
8795
value={filterValues}
8896
valueLabelDisplay="auto"
8997
{...sliderProps}

0 commit comments

Comments
 (0)