Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ describe('Overlayable.ts', () => {
expect(wrapper.vm.overlay).toBeFalsy()
})

it('destroyOverlay безопасен когда оверлея нет', () => {
const wrapper = mountFunction()
expect(() => wrapper.vm.destroyOverlay()).not.toThrow()
expect(wrapper.vm.overlay).toBeFalsy()
})

it('should remove overlay app container after close', async () => {
const wrapper = mountFunction()

Expand Down Expand Up @@ -210,6 +216,24 @@ describe('Overlayable.ts', () => {
expect(wrapper.vm.overlay!.$el.isConnected).toBe(true)
})

it('beforeUnmount уничтожает оверлей даже при isActive (фикс залипшего overlay)', async () => {
const wrapper = mountDrawerLike()

wrapper.vm.temporary = true
wrapper.vm.isActive = true
await nextTick()
await waitAnimationFrame()

const app = document.querySelector('[data-app]') as HTMLElement
expect(app.querySelector('.v-overlay')).toBeTruthy()
expect(document.querySelectorAll('[data-v-app]')).toHaveLength(1)

wrapper.unmount()

expect(app.querySelector('.v-overlay')).toBeNull()
expect(document.querySelectorAll('[data-v-app]')).toHaveLength(0)
})

it('showOverlay true→true не вызывает genOverlay после потери [data-app]', async () => {
const genOverlay = jest.fn()
const removeOverlay = jest.fn()
Expand Down
48 changes: 25 additions & 23 deletions packages/vuetify/src/mixins/overlayable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
},

beforeUnmount () {
this.removeOverlay()
this.destroyOverlay()
},

methods: {
Expand Down Expand Up @@ -113,14 +113,7 @@ export default defineComponent({
if (this.hideOverlay) return

if (!this.overlay?.$el?.isConnected) {
if (this.overlay) {
cancelAnimationFrame(this.animationFrame)
const container = this.overlay.$el?.parentNode as HTMLElement | null
this.overlayApp?.unmount()
this.overlayApp = null
if (container?.parentNode) container.parentNode.removeChild(container)
this.overlay = null
}
this.teardownOverlay()
this.createOverlay()
}

Expand All @@ -142,10 +135,7 @@ export default defineComponent({
removeOverlay (showScroll = true) {
if (this.overlay) {
if (!this.overlay.$el?.isConnected) {
cancelAnimationFrame(this.animationFrame)
this.overlayApp?.unmount()
this.overlayApp = null
this.overlay = null
this.teardownOverlay()
showScroll && this.showScroll()
return
}
Expand All @@ -159,16 +149,7 @@ export default defineComponent({
this.isActive
) return

const overlayContainer = this.overlay.$el.parentNode as HTMLElement | null

this.overlayApp?.unmount()
this.overlayApp = null

if (overlayContainer?.parentNode) {
overlayContainer.parentNode.removeChild(overlayContainer)
}

this.overlay = null
this.teardownOverlay()
})

// Cancel animation frame in case
Expand All @@ -181,6 +162,27 @@ export default defineComponent({

showScroll && this.showScroll()
},
teardownOverlay () {
cancelAnimationFrame(this.animationFrame)

if (!this.overlay) return

const container = this.overlay.$el?.parentNode as HTMLElement | null

this.overlayApp?.unmount()
this.overlayApp = null

if (container?.parentNode) {
container.parentNode.removeChild(container)
}

this.overlay = null
},
/** Синхронно уничтожает оверлей независимо от isActive/анимации. Для unmount. */
destroyOverlay () {
this.teardownOverlay()
this.showScroll()
},
scrollListener (e: WheelEvent | KeyboardEvent) {
if ('key' in e) {
if (
Expand Down
Loading