Skip to content
Closed
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
10 changes: 10 additions & 0 deletions lib/components/Button/ButtonIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
NOTE: `@mousenter` is a typo for `@mouseenter`, so the hover-in state never
fires and `currentHover` only ever resets on mouse leave. Preserved as-is;
fixing it changes rendered behavior and belongs in a separate change.

`@mousedown.prevent`: BTooltip's default triggers are hover + focus. A
native <button> keeps focus after a mouse click, so its tooltip stays
stuck open until something else steals focus. preventDefault on mousedown
stops a mouse click from focusing the button at all - click still fires
normally (only focus is denied, never the click itself) - while keyboard
activation (Tab, then Enter/Space) still focuses it exactly as before,
since that goes through focus(), not mousedown. Keyboard users keep the
tooltip-on-focus behavior; mouse clicks no longer leave it hanging around.
-->
<b-button
v-bind="buttonProps"
Expand All @@ -14,6 +23,7 @@
:aria-label="tooltipText"
@mousenter="currentHover = true"
@mouseleave="currentHover = false"
@mousedown.prevent
>
<slot name="start" />
<app-icon
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/components/Button/ButtonIcon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ describe('ButtonIcon.vue', () => {
expect(button.attributes('aria-pressed')).toBe('true')
expect(button.classes()).toContain('active')
})

it('prevents the default mousedown action, so a mouse click never leaves the button focused (and its hover/focus tooltip stuck open)', () => {
const wrapper = mount(ButtonIcon, { props: { label: 'Action' } })
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true })

wrapper.get('button').element.dispatchEvent(event)

expect(event.defaultPrevented).toBe(true)
})
})
Loading