Skip to content

Commit

Permalink
[DataGridPro] Fix keyboard navigation issue in header filters (#10358)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi authored Sep 18, 2023
1 parent ffc58b3 commit f051b1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
const onMouseDown = React.useCallback(
(event: React.MouseEvent) => {
if (!hasFocus) {
if (inputRef.current) {
if (inputRef.current && inputRef.current.contains(event.target as HTMLElement)) {
inputRef.current.focus();
}
apiRef.current.setColumnHeaderFilterFocus(colDef.field, event);
Expand Down Expand Up @@ -255,7 +255,21 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
inputRef={inputRef}
applyValue={applyFilterChanges}
onFocus={() => apiRef.current.startHeaderFilterEditMode(colDef.field)}
onBlur={() => apiRef.current.stopHeaderFilterEditMode()}
onBlur={(event: React.FocusEvent) => {
apiRef.current.stopHeaderFilterEditMode();
// Blurring an input element should reset focus state only if `relatedTarget` is not the header filter cell
if (!event.relatedTarget?.className.includes('columnHeader')) {
apiRef.current.setState((state) => ({
...state,
focus: {
cell: null,
columnHeader: null,
columnHeaderFilter: null,
columnGroupHeader: null,
},
}));
}
}}
label={capitalize(label)}
placeholder=""
isFilterActive={isFilterActive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ describe('<DataGridPro /> - Filter', () => {
const filterCell = getColumnHeaderCell(0, 1);
const filterCellInput = filterCell.querySelector('input')!;
expect(filterCellInput).not.toHaveFocus();
fireEvent.mouseDown(filterCell);
fireEvent.mouseDown(filterCellInput);
expect(filterCellInput).toHaveFocus();
fireEvent.change(filterCellInput, { target: { value: 'ad' } });
clock.tick(SUBMIT_FILTER_STROKE_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ export const useGridFocus = (
}, [apiRef, handleDocumentClick]);

useGridApiEventHandler(apiRef, 'columnHeaderBlur', handleBlur);
useGridApiEventHandler(apiRef, 'headerFilterBlur', handleBlur);
useGridApiEventHandler(apiRef, 'cellDoubleClick', handleCellDoubleClick);
useGridApiEventHandler(apiRef, 'cellMouseDown', handleCellMouseDown);
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
Expand Down

0 comments on commit f051b1f

Please sign in to comment.