Skip to content

Commit 75a9e83

Browse files
committed
Fix focus for active cell
1 parent 1ea0957 commit 75a9e83

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/ActiveCell.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Props = {
1414
};
1515

1616
const ActiveCell: React.FC<Props> = (props) => {
17+
const rootRef = React.useRef<HTMLDivElement>(null);
1718
const { getBindingsForCell } = props;
1819

1920
const dispatch = useDispatch();
@@ -60,6 +61,13 @@ const ActiveCell: React.FC<Props> = (props) => {
6061
[setCellData, active]
6162
);
6263

64+
React.useEffect(() => {
65+
const root = rootRef.current;
66+
if (!hidden && root) {
67+
root.focus();
68+
}
69+
}, [rootRef, hidden]);
70+
6371
React.useEffect(() => {
6472
const prevActive = prevActiveRef.current;
6573
const prevCell = prevCellRef.current;
@@ -101,12 +109,14 @@ const ActiveCell: React.FC<Props> = (props) => {
101109

102110
return hidden ? null : (
103111
<div
112+
ref={rootRef}
104113
className={classnames(
105114
"Spreadsheet__active-cell",
106115
`Spreadsheet__active-cell--${mode}`
107116
)}
108117
style={dimensions}
109118
onClick={mode === "view" && !readOnly ? edit : undefined}
119+
tabIndex={0}
110120
>
111121
{mode === "edit" && active && (
112122
<DataEditor

0 commit comments

Comments
 (0)