mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
fix(hooks): [use-popper-container] fix namespace (#9655)
This commit is contained in:
parent
69caee0d2a
commit
51a3c454ea
@ -1,22 +0,0 @@
|
||||
import { onBeforeMount } from 'vue'
|
||||
import { isClient } from '@vueuse/core'
|
||||
import { generateId } from '@element-plus/utils'
|
||||
|
||||
let cachedContainer: HTMLElement
|
||||
|
||||
export const POPPER_CONTAINER_ID = `el-popper-container-${generateId()}`
|
||||
|
||||
export const POPPER_CONTAINER_SELECTOR = `#${POPPER_CONTAINER_ID}`
|
||||
|
||||
export const usePopperContainer = () => {
|
||||
onBeforeMount(() => {
|
||||
if (!isClient) return
|
||||
|
||||
if (!cachedContainer) {
|
||||
const container = document.createElement('div')
|
||||
container.id = POPPER_CONTAINER_ID
|
||||
document.body.appendChild(container)
|
||||
cachedContainer = container
|
||||
}
|
||||
})
|
||||
}
|
@ -2,7 +2,10 @@ import { nextTick } from 'vue'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import * as vueuse from '@vueuse/core'
|
||||
import { POPPER_CONTAINER_SELECTOR, usePopperContainer } from '../src/container'
|
||||
import {
|
||||
POPPER_CONTAINER_SELECTOR,
|
||||
usePopperContainer,
|
||||
} from '../use-popper-container'
|
||||
|
||||
const AXIOM = 'rem is the best girl'
|
||||
|
||||
@ -14,11 +17,9 @@ vi.mock('@vueuse/core', () => {
|
||||
|
||||
const mountComponent = () =>
|
||||
shallowMount({
|
||||
template: `<div>
|
||||
${AXIOM}
|
||||
</div>`,
|
||||
setup() {
|
||||
usePopperContainer()
|
||||
return () => <div>{AXIOM}</div>
|
||||
},
|
||||
})
|
||||
|
@ -1,10 +1,16 @@
|
||||
import { onBeforeMount } from 'vue'
|
||||
import { isClient } from '@vueuse/core'
|
||||
import { generateId } from '@element-plus/utils'
|
||||
import { useGlobalConfig } from '../use-global-config'
|
||||
import { defaultNamespace } from '../use-namespace'
|
||||
|
||||
let cachedContainer: HTMLElement
|
||||
|
||||
export const POPPER_CONTAINER_ID = `el-popper-container-${generateId()}`
|
||||
const namespace = useGlobalConfig('namespace', defaultNamespace)
|
||||
|
||||
export const POPPER_CONTAINER_ID = `${
|
||||
namespace.value
|
||||
}-popper-container-${generateId()}`
|
||||
|
||||
export const POPPER_CONTAINER_SELECTOR = `#${POPPER_CONTAINER_ID}`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user