Skip to content

Commit

Permalink
fix(click-outside): correctly remove shadow DOM event listeners (#20273)
Browse files Browse the repository at this point in the history
fixes #19616
  • Loading branch information
cgodo authored Aug 3, 2024
1 parent 40f7197 commit 9b02b0d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ describe('click-outside.js within the Shadow DOM', () => {
const { outsideClickHandler, shadowEl, binding } = bootstrap()
expect(window.document.addEventListener).toHaveBeenCalledWith('click', outsideClickHandler, true)

ClickOutside.unmounted(shadowEl, binding)
ClickOutside.beforeUnmount(shadowEl, binding)
expect(window.document.removeEventListener).toHaveBeenCalledWith('click', outsideClickHandler, true)
})

it('should register and unregister handler within the shadow DOM', () => {
const { shadowClickHandler, shadowRoot, shadowEl, binding } = bootstrap()
expect(shadowRoot.addEventListener).toHaveBeenCalledWith('click', shadowClickHandler, true)

ClickOutside.unmounted(shadowEl, binding)
ClickOutside.beforeUnmount(shadowEl, binding)
expect(shadowRoot.removeEventListener).toHaveBeenCalledWith('click', shadowClickHandler, true)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('v-click-outside', () => {
const { clickHandler, el, binding } = bootstrap()
expect(window.document.addEventListener).toHaveBeenCalledWith('click', clickHandler, true)

ClickOutside.unmounted(el, binding)
ClickOutside.beforeUnmount(el, binding)
expect(window.document.removeEventListener).toHaveBeenCalledWith('click', clickHandler, true)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/directives/click-outside/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const ClickOutside = {
}
},

unmounted (el: HTMLElement, binding: ClickOutsideDirectiveBinding) {
beforeUnmount (el: HTMLElement, binding: ClickOutsideDirectiveBinding) {
if (!el._clickOutside) return

handleShadow(el, (app: HTMLElement) => {
Expand Down

0 comments on commit 9b02b0d

Please sign in to comment.