Skip to content

Commit cb30725

Browse files
authored
Workaround for BooleanEditor quickToggle interaction with tab key (#3944)
1 parent 4f33c37 commit cb30725

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

desktop/cmp/grid/editors/BooleanEditor.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,23 @@ export const [BooleanEditor, booleanEditor] = hoistCmp.withFactory<BooleanEditor
4949
}
5050
});
5151

52-
function useInstantEditor({onValueChange, initialValue, stopEditing}: CustomCellEditorProps, ref) {
52+
function useInstantEditor(
53+
{onValueChange, initialValue, stopEditing, eventKey, eGridCell}: CustomCellEditorProps,
54+
ref
55+
) {
56+
// Don't toggle if the user has tabbed into the editor. See https://github.com/xh/hoist-react/issues/3943.
57+
// Fortunately, `eventKey` is null for tab, so we can use that to accept other keyboard events.
58+
// Unfortunately, it is also null for mouse events, so we check if the grid cell is currently
59+
// underneath the mouse position via `:hover` selector.
5360
useEffect(() => {
54-
onValueChange(!initialValue);
61+
const els = document.querySelectorAll(':hover'),
62+
topEl = els[els.length - 1];
63+
64+
if (eventKey || topEl === eGridCell) {
65+
onValueChange(!initialValue);
66+
}
5567
stopEditing();
56-
}, [stopEditing, initialValue, onValueChange]);
68+
}, [stopEditing, initialValue, onValueChange, eventKey, eGridCell]);
5769

5870
return null;
5971
}

0 commit comments

Comments
 (0)