Skip to content

Commit b23d995

Browse files
committed
address review: restore focusEvent dedupe in WithPopoverMenu
The class-component version tracked the native click event that just triggered focus via the container's onClick so the document-level listener (registered once focused) could skip it. Without this, the same click bubbles to document after a re-render has detached its event.target, causing shouldFocus to return false and immediately undoing the focus. Preserve that behavior via focusEventRef.
1 parent ac478cd commit b23d995

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

superset-frontend/src/dashboard/components/menu/WithPopoverMenu.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,25 @@ function WithPopoverMenu({
130130
const [isFocused, setIsFocused] = useState(isFocusedProp);
131131
const containerRef = useRef<ShouldFocusContainer | null>(null);
132132
const menuRef = useRef<HTMLDivElement | null>(null);
133+
// Tracks the native event that just triggered focus via the container's
134+
// onClick so the document-level listener (registered once focused) can
135+
// skip it. Without this, the same click bubbles to document after a
136+
// re-render has detached its event.target, causing shouldFocus to return
137+
// false and immediately undoing the focus.
138+
const focusEventRef = useRef<Event | null>(null);
133139

134140
const handleClick = useCallback(
135141
(event: any) => {
136142
if (!editMode) {
137143
return;
138144
}
139145

146+
const nativeEvent = event.nativeEvent || event;
147+
if (focusEventRef.current === nativeEvent) {
148+
focusEventRef.current = null;
149+
return;
150+
}
151+
140152
const shouldFocusResult = shouldFocusFunc(
141153
event,
142154
containerRef.current,
@@ -146,6 +158,7 @@ function WithPopoverMenu({
146158
if (shouldFocusResult === isFocused) return;
147159

148160
if (!disableClick && shouldFocusResult && !isFocused) {
161+
focusEventRef.current = nativeEvent;
149162
setIsFocused(true);
150163
if (onChangeFocus) onChangeFocus(true);
151164
} else if (!shouldFocusResult && isFocused) {

0 commit comments

Comments
 (0)