Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions js/src/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="#">)
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)
Expand Down
17 changes: 9 additions & 8 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading