Skip to content

Commit 29cf0ab

Browse files
authored
Fix popovers dismiss in Chrome browsers (#42352)
* Update popover API to properly register listeners and avoid Chrome/Webkit differences in button focus * Apply same fix to Tooltips
1 parent b29893b commit 29cf0ab

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

js/src/popover.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,19 @@ const initPopover = event => {
8686
return
8787
}
8888

89-
// Prevent default for click events to avoid navigation
89+
// Prevent default for click events to avoid navigation (e.g. <a href="#">)
9090
if (event.type === 'click') {
9191
event.preventDefault()
9292
}
9393

94-
// Get or create instance
95-
const popover = Popover.getOrCreateInstance(target)
96-
97-
// Trigger the appropriate action based on event type
98-
if (event.type === 'click') {
99-
popover.toggle()
100-
} else if (event.type === 'focusin') {
101-
popover._activeTrigger.focus = true
102-
popover._enter()
103-
}
94+
// Lazily create the instance. The instance's own `_setListeners()` registers
95+
// the appropriate listeners on the element for the configured triggers
96+
// (click/focus/hover), so we don't toggle or call `_enter` here — doing so
97+
// would duplicate handlers and leave stale state on `_activeTrigger`.
98+
Popover.getOrCreateInstance(target)
10499
}
105100

106-
// Support click (default), hover, and focus triggers
101+
// Auto-initialize popovers on first interaction for click, hover, and focus triggers
107102
EventHandler.on(document, EVENT_CLICK, SELECTOR_DATA_TOGGLE, initPopover)
108103
EventHandler.on(document, EVENT_FOCUSIN, SELECTOR_DATA_TOGGLE, initPopover)
109104
EventHandler.on(document, EVENT_MOUSEENTER, SELECTOR_DATA_TOGGLE, initPopover)

js/src/tooltip.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,17 @@ const initTooltip = event => {
733733
return
734734
}
735735

736-
// Get or create instance and trigger the appropriate action
737-
const tooltip = Tooltip.getOrCreateInstance(target)
738-
739-
// For focus events, manually trigger enter to show
740-
if (event.type === 'focusin') {
741-
tooltip._activeTrigger.focus = true
742-
tooltip._enter()
743-
}
736+
// Lazily create the instance. The instance's own `_setListeners()` registers
737+
// the appropriate listeners on the element for the configured triggers
738+
// (hover/focus by default), so we don't mutate `_activeTrigger` or call
739+
// `_enter` here — doing so would show tooltips for triggers the user didn't
740+
// opt into (e.g. `focusin` firing for click-focused buttons in Chromium,
741+
// even when `trigger="hover"` or `trigger="manual"`) and leave stale state
742+
// on `_activeTrigger`.
743+
Tooltip.getOrCreateInstance(target)
744744
}
745745

746+
// Auto-initialize tooltips on first interaction for hover and focus triggers
746747
EventHandler.on(document, EVENT_FOCUSIN, SELECTOR_DATA_TOGGLE, initTooltip)
747748
EventHandler.on(document, EVENT_MOUSEENTER, SELECTOR_DATA_TOGGLE, initTooltip)
748749

0 commit comments

Comments
 (0)