Skip to content

Commit

Permalink
Add support for focus trapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Dec 28, 2023
1 parent 2d2256b commit 9c04904
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
* cell will open to edit mode.
*/
readonly cellActivationBehavior?: "double-click" | "single-click" | "second-click";

/**
* Controls if focus will trap inside the data grid when doing tab and caret navigation.
*/
readonly trapFocus?: boolean;
}

type ScrollToFn = (
Expand Down Expand Up @@ -782,6 +787,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
preventDiagonalScrolling,
rightElement,
rightElementProps,
trapFocus = false,
smoothScrollX,
smoothScrollY,
scaleToRem = false,
Expand Down Expand Up @@ -3040,11 +3046,14 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
// #endregion

const moved = updateSelectedCell(col, row, false, freeMove);
if (moved || !cancelOnlyOnMove) {

const didMatch = details.didMatch;

if (didMatch && (moved || !cancelOnlyOnMove || trapFocus)) {
cancel();
}

return details.didMatch;
return didMatch;
},
[
overlayOpen,
Expand All @@ -3060,6 +3069,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
onSelectionCleared,
columnsIn.length,
onDelete,
trapFocus,
deleteRange,
setSelectedColumns,
setSelectedRows,
Expand Down

0 comments on commit 9c04904

Please sign in to comment.