Skip to content

Commit 2e95f6d

Browse files
authored
fix(VRipple): hide ripple on blur (#13264)
fixes #13189
1 parent b9739f7 commit 2e95f6d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/vuetify/src/directives/ripple/__tests__/ripple.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,18 @@ describe('ripple.ts', () => {
145145
jest.runAllTimers()
146146
expect(wrapper.findAll('.v-ripple__container')).toHaveLength(0)
147147
})
148+
149+
it('should hide ripple on blur if keyboardRipple is true', () => {
150+
const wrapper = mountFunction()
151+
const keydownEvent = new KeyboardEvent('keydown', { keyCode: 13 })
152+
wrapper.element.dispatchEvent(keydownEvent)
153+
154+
expect(wrapper.find('.v-ripple__container').exists()).toBe(true)
155+
156+
const blurEvent = new FocusEvent('blur')
157+
wrapper.element.dispatchEvent(blurEvent)
158+
159+
jest.runAllTimers()
160+
expect(wrapper.find('.v-ripple__container').exists()).toBe(false)
161+
})
148162
})

packages/vuetify/src/directives/ripple/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ function keyboardRippleHide (e: KeyboardEvent) {
253253
rippleHide(e)
254254
}
255255

256+
function focusRippleHide (e: FocusEvent) {
257+
if (keyboardRipple === true) {
258+
keyboardRipple = false
259+
rippleHide(e)
260+
}
261+
}
262+
256263
function updateRipple (el: HTMLElement, binding: VNodeDirective, wasEnabled: boolean) {
257264
const enabled = isRippleEnabled(binding.value)
258265
if (!enabled) {
@@ -283,6 +290,8 @@ function updateRipple (el: HTMLElement, binding: VNodeDirective, wasEnabled: boo
283290
el.addEventListener('keydown', keyboardRippleShow)
284291
el.addEventListener('keyup', keyboardRippleHide)
285292

293+
el.addEventListener('blur', focusRippleHide)
294+
286295
// Anchor tags can be dragged, causes other hides to fail - #1537
287296
el.addEventListener('dragstart', rippleHide, { passive: true })
288297
} else if (!enabled && wasEnabled) {
@@ -301,6 +310,7 @@ function removeListeners (el: HTMLElement) {
301310
el.removeEventListener('keydown', keyboardRippleShow)
302311
el.removeEventListener('keyup', keyboardRippleHide)
303312
el.removeEventListener('dragstart', rippleHide)
313+
el.removeEventListener('blur', focusRippleHide)
304314
}
305315

306316
function directive (el: HTMLElement, binding: VNodeDirective, node: VNode) {

0 commit comments

Comments
 (0)