mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
fix(components): [popper-container] recreate container when unmounted (#7076)
This commit is contained in:
parent
993971e872
commit
14b9b9f542
@ -8,6 +8,13 @@ export const POPPER_CONTAINER_ID = `el-popper-container-${generateId()}`
|
||||
|
||||
export const POPPER_CONTAINER_SELECTOR = `#${POPPER_CONTAINER_ID}`
|
||||
|
||||
const createContainer = () => {
|
||||
const container = document.createElement('div')
|
||||
container.id = POPPER_CONTAINER_ID
|
||||
document.body.appendChild(container)
|
||||
return container
|
||||
}
|
||||
|
||||
export const usePopperContainer = () => {
|
||||
onBeforeMount(() => {
|
||||
if (!isClient) return
|
||||
@ -15,11 +22,12 @@ export const usePopperContainer = () => {
|
||||
// This is for bypassing the error that when under testing env, we often encounter
|
||||
// document.body.innerHTML = '' situation
|
||||
// for this we need to disable the caching since it's not really needed
|
||||
if (process.env.NODE_ENV === 'test' || !cachedContainer) {
|
||||
const container = document.createElement('div')
|
||||
container.id = POPPER_CONTAINER_ID
|
||||
document.body.appendChild(container)
|
||||
cachedContainer = container
|
||||
if (
|
||||
process.env.NODE_ENV === 'test' ||
|
||||
!cachedContainer ||
|
||||
!document.body.querySelector(POPPER_CONTAINER_SELECTOR)
|
||||
) {
|
||||
cachedContainer = createContainer()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user