From: Mark Otto Date: Wed, 22 Apr 2026 19:32:43 +0000 (-0700) Subject: Fix popovers dismiss in Chrome browsers (#42352) X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=29cf0abca53c0fbba5bcdc90d9f1b9036689f53e;p=thirdparty%2Fbootstrap.git 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 --- diff --git a/js/src/popover.js b/js/src/popover.js index d11eaa3340..807e6bdb48 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -86,24 +86,19 @@ const initPopover = event => { return } - // Prevent default for click events to avoid navigation + // Prevent default for click events to avoid navigation (e.g. ) if (event.type === 'click') { event.preventDefault() } - // Get or create instance - const popover = Popover.getOrCreateInstance(target) - - // Trigger the appropriate action based on event type - if (event.type === 'click') { - popover.toggle() - } else if (event.type === 'focusin') { - popover._activeTrigger.focus = true - popover._enter() - } + // Lazily create the instance. The instance's own `_setListeners()` registers + // the appropriate listeners on the element for the configured triggers + // (click/focus/hover), so we don't toggle or call `_enter` here — doing so + // would duplicate handlers and leave stale state on `_activeTrigger`. + Popover.getOrCreateInstance(target) } -// Support click (default), hover, and focus triggers +// Auto-initialize popovers on first interaction for click, hover, and focus triggers EventHandler.on(document, EVENT_CLICK, SELECTOR_DATA_TOGGLE, initPopover) EventHandler.on(document, EVENT_FOCUSIN, SELECTOR_DATA_TOGGLE, initPopover) EventHandler.on(document, EVENT_MOUSEENTER, SELECTOR_DATA_TOGGLE, initPopover) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 4c3f59d834..bf5fadb977 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -733,16 +733,17 @@ const initTooltip = event => { return } - // Get or create instance and trigger the appropriate action - const tooltip = Tooltip.getOrCreateInstance(target) - - // For focus events, manually trigger enter to show - if (event.type === 'focusin') { - tooltip._activeTrigger.focus = true - tooltip._enter() - } + // Lazily create the instance. The instance's own `_setListeners()` registers + // the appropriate listeners on the element for the configured triggers + // (hover/focus by default), so we don't mutate `_activeTrigger` or call + // `_enter` here — doing so would show tooltips for triggers the user didn't + // opt into (e.g. `focusin` firing for click-focused buttons in Chromium, + // even when `trigger="hover"` or `trigger="manual"`) and leave stale state + // on `_activeTrigger`. + Tooltip.getOrCreateInstance(target) } +// Auto-initialize tooltips on first interaction for hover and focus triggers EventHandler.on(document, EVENT_FOCUSIN, SELECTOR_DATA_TOGGLE, initTooltip) EventHandler.on(document, EVENT_MOUSEENTER, SELECTOR_DATA_TOGGLE, initTooltip)