Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.

Commit bbab313

Browse files
authored
DataTable: Fix and Simplify overlay handling in cell edit mode (#7951)
* Improve Overlay Handling (Minimal) * cleanup * Add Props to other overlay components
1 parent 2e5dbf2 commit bbab313

7 files changed

Lines changed: 21 additions & 41 deletions

File tree

components/lib/autocomplete/AutoCompletePanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ export const AutoCompletePanel = React.memo(
268268
{
269269
className: classNames(props.panelClassName, cx('panel', { context })),
270270
style,
271-
onClick: (e) => props.onClick(e)
271+
onClick: (e) => props.onClick(e),
272+
'data-pr-is-overlay': true
272273
},
273274
_ptm('panel')
274275
);

components/lib/calendar/CalendarPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const CalendarPanel = React.forwardRef((props, ref) => {
1818
'aria-label': localeOption('chooseDate', props.locale),
1919
'aria-modal': props.inline ? null : 'true',
2020
onClick: props.onClick,
21-
onMouseUp: props.onMouseUp
21+
onMouseUp: props.onMouseUp,
22+
'data-pr-is-overlay': true
2223
},
2324
props.ptm('panel', { hostName: props.hostName })
2425
);

components/lib/colorpicker/ColorPickerPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const ColorPickerPanel = React.forwardRef((props, ref) => {
1414
{
1515
className: cx('panel', { panelProps: props, context }),
1616
style: props.panelStyle,
17-
onClick: props.onClick
17+
onClick: props.onClick,
18+
'data-pr-is-overlay': true
1819
},
1920
ptm('panel', { hostName: props.hostName })
2021
);

components/lib/datatable/BodyCell.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ChevronDownIcon } from '../icons/chevrondown';
88
import { ChevronRightIcon } from '../icons/chevronright';
99
import { PencilIcon } from '../icons/pencil';
1010
import { TimesIcon } from '../icons/times';
11-
import { OverlayService } from '../overlayservice/OverlayService';
1211
import { Ripple } from '../ripple/Ripple';
1312
import { DomHandler, IconUtils, ObjectUtils, classNames } from '../utils/Utils';
1413
import { RowCheckbox } from './RowCheckbox';
@@ -21,13 +20,10 @@ export const Cell = (props) => {
2120
const [styleObjectState, setStyleObjectState] = React.useState({});
2221
const elementRef = React.useRef(null);
2322
const keyHelperRef = React.useRef(null);
24-
const overlayEventListener = React.useRef(null);
25-
const selfClick = React.useRef(false);
2623
const focusTimeout = React.useRef(null);
2724
const initFocusTimeout = React.useRef(null);
2825
const editingRowDataStateRef = React.useRef(null);
2926
const { ptm, ptmo, cx } = props.ptCallbacks;
30-
3127
const getColumnProp = (name) => ColumnBase.getCProp(props.column, name);
3228

3329
const getColumnPTOptions = (key) => {
@@ -58,18 +54,18 @@ export const Cell = (props) => {
5854
return getColumnProp('cellEditValidateOnClose');
5955
};
6056

57+
const isIgnoredElement = (element) => {
58+
const isOverlay = (el) => el.getAttribute && el.getAttribute('data-pr-is-overlay');
59+
60+
return isOverlay(element) || DomHandler.getParents(element).find((el) => isOverlay(el));
61+
};
62+
6163
const [bindDocumentClickListener, unbindDocumentClickListener] = useEventListener({
6264
type: 'click',
6365
listener: (e) => {
64-
setTimeout(() => {
65-
if (!selfClick.current && isOutsideClicked(e.target)) {
66-
// #2666 for overlay components and outside is clicked
67-
68-
switchCellToViewMode(e, true);
69-
}
70-
}, 0);
71-
72-
selfClick.current = false;
66+
if (!isIgnoredElement(e.target) && isOutsideClicked(e.target)) {
67+
switchCellToViewMode(e, true);
68+
}
7369
},
7470
options: true,
7571
when: isEditable()
@@ -120,9 +116,6 @@ export const Cell = (props) => {
120116
setTimeout(() => {
121117
setEditingState(false);
122118
unbindDocumentClickListener();
123-
OverlayService.off('overlay-click', overlayEventListener.current);
124-
overlayEventListener.current = null;
125-
selfClick.current = false;
126119
}, 1);
127120
};
128121

@@ -175,7 +168,7 @@ export const Cell = (props) => {
175168
};
176169

177170
const onClick = (event) => {
178-
props.onClick(event, getCellCallbackParams(event), isEditable(), editingState, setEditingState, selfClick, props.column, bindDocumentClickListener, overlayEventListener, isOutsideClicked);
171+
props.onClick(event, getCellCallbackParams(event), isEditable(), editingState, setEditingState, props.column, bindDocumentClickListener);
179172
};
180173

181174
const onMouseDown = (event) => {
@@ -276,8 +269,6 @@ export const Cell = (props) => {
276269
};
277270

278271
const onBlur = (event) => {
279-
selfClick.current = false;
280-
281272
if (props.editMode !== 'row' && editingState && getColumnProp('cellEditValidatorEvent') === 'blur') {
282273
switchCellToViewMode(event, true);
283274
}
@@ -363,11 +354,6 @@ export const Cell = (props) => {
363354
}, [editingState]);
364355

365356
useUnmountEffect(() => {
366-
if (overlayEventListener.current) {
367-
OverlayService.off('overlay-click', overlayEventListener.current);
368-
overlayEventListener.current = null;
369-
}
370-
371357
if (editingRowDataStateRef.current) {
372358
editingRowDataStateRef.current = null;
373359
}

components/lib/datatable/BodyRow.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ColumnBase } from '../column/ColumnBase';
33
import { useMergeProps } from '../hooks/Hooks';
44
import { classNames, DomHandler, ObjectUtils } from '../utils/Utils';
55
import { BodyCell, RadioCheckCell } from './BodyCell';
6-
import { OverlayService } from '../overlayservice/OverlayService';
76
import { Fragment } from 'react';
87

98
export const BodyRow = React.memo((props) => {
@@ -534,10 +533,8 @@ export const BodyRow = React.memo((props) => {
534533
}
535534
}, []);
536535

537-
const onCellClick = (event, params, isEditable, editingState, setEditingState, selfClick, column, bindDocumentClickListener, overlayEventListener, isOutsideClicked) => {
536+
const onCellClick = (event, params, isEditable, editingState, setEditingState, column, bindDocumentClickListener) => {
538537
if (props.editMode !== 'row' && isEditable && !editingState && (props.selectOnEdit || (!props.selectOnEdit && props.isRowSelected))) {
539-
selfClick.current = true;
540-
541538
const onBeforeCellEditShow = getColumnProp(column, 'onBeforeCellEditShow');
542539
const onCellEditInit = getColumnProp(column, 'onCellEditInit');
543540
const cellEditValidatorEvent = getColumnProp(column, 'cellEditValidatorEvent');
@@ -571,14 +568,6 @@ export const BodyRow = React.memo((props) => {
571568

572569
if (cellEditValidatorEvent === 'click') {
573570
bindDocumentClickListener();
574-
575-
overlayEventListener.current = (e) => {
576-
if (!isOutsideClicked(e.target)) {
577-
selfClick.current = true;
578-
}
579-
};
580-
581-
OverlayService.on('overlay-click', overlayEventListener.current);
582571
}
583572
}, 1);
584573
}

components/lib/dropdown/DropdownPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ export const DropdownPanel = React.memo(
309309
{
310310
className: classNames(props.panelClassName, cx('panel', { context })),
311311
style: sx('panel'),
312-
onClick: props.onClick
312+
onClick: props.onClick,
313+
'data-pr-is-overlay': true
313314
},
314315
getPTOptions('panel')
315316
);

components/lib/multiselect/MultiSelectPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ export const MultiSelectPanel = React.memo(
266266
{
267267
className: classNames(props.panelClassName, cx('panel', { panelProps: props, context, allowOptionSelect })),
268268
style: props.panelStyle,
269-
onClick: props.onClick
269+
onClick: props.onClick,
270+
'data-pr-is-overlay': true
270271
},
271272
getPTOptions('panel')
272273
);

0 commit comments

Comments
 (0)