Skip to content

Commit 37d7b6a

Browse files
committed
fix(datagrid-web): preventScroll on column selector focus
1 parent 8ed842c commit 37d7b6a

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

packages/pluggableWidgets/datagrid-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We fixed an issue where the datagrid's horizontal scrollbar would unexpectedly jump to the right when the column selector was enabled.
12+
913
## [3.3.0] - 2025-08-28
1014

1115
### Added

packages/pluggableWidgets/datagrid-web/src/components/ColumnSelector.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { autoUpdate, size, useClick, useDismiss, useFloating, useInteractions } from "@floating-ui/react";
2-
import { createElement, ReactElement, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
1+
import {
2+
FloatingFocusManager,
3+
autoUpdate,
4+
size,
5+
useClick,
6+
useDismiss,
7+
useFloating,
8+
useInteractions
9+
} from "@floating-ui/react";
10+
import { createElement, ReactElement, useEffect, useMemo, useState } from "react";
311
import { flushSync } from "react-dom";
412
import { GridColumn } from "../typings/GridColumn";
513
import { FaEye } from "./icons/FaEye";
@@ -15,7 +23,6 @@ export function ColumnSelector(props: ColumnSelectorProps): ReactElement {
1523
const { visibleLength } = props;
1624
const [show, setShow] = useState(false);
1725
const [maxHeight, setMaxHeight] = useState<number>(0);
18-
const buttonRef = useRef<HTMLButtonElement>(null);
1926
const { refs, floatingStyles, context, update } = useFloating({
2027
open: show,
2128
placement: "bottom-end",
@@ -49,20 +56,6 @@ export function ColumnSelector(props: ColumnSelectorProps): ReactElement {
4956
const firstHidableColumnIndex = useMemo(() => props.columns.findIndex(c => c.canHide), [props.columns]);
5057
const lastHidableColumnIndex = useMemo(() => props.columns.map(c => c.canHide).lastIndexOf(true), [props.columns]);
5158

52-
useLayoutEffect(() => {
53-
if (show) {
54-
// Focus the first visible column
55-
setTimeout(() => {
56-
(refs.floating?.current?.querySelector("li") as HTMLElement)?.focus();
57-
}, 10);
58-
} else {
59-
// focus back to the button when closing
60-
setTimeout(() => {
61-
(refs.reference?.current as HTMLElement)?.focus();
62-
}, 10);
63-
}
64-
}, [show]);
65-
6659
const optionsComponent = (
6760
<ul
6861
ref={refs.setFloating}
@@ -102,7 +95,6 @@ export function ColumnSelector(props: ColumnSelectorProps): ReactElement {
10295
) {
10396
e.preventDefault();
10497
setShow(false);
105-
buttonRef.current?.focus();
10698
}
10799
}}
108100
role="menuitem"
@@ -147,7 +139,11 @@ export function ColumnSelector(props: ColumnSelectorProps): ReactElement {
147139
<FaEye />
148140
</button>
149141
</div>
150-
{show && optionsComponent}
142+
{show && (
143+
<FloatingFocusManager context={context} modal={false}>
144+
{optionsComponent}
145+
</FloatingFocusManager>
146+
)}
151147
</div>
152148
);
153149
}

0 commit comments

Comments
 (0)