mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* fix(components): [select/V2] width of dropdown panel exceeds the input * fix(components): [select/V2] width of drop-down panel exceeds the input * fix: select constants * fix: select --------- Co-authored-by: 2586740555 <15972343+CYJ090915@user.noreply.gitee.com>
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import { unrefElement } from '@vueuse/core'
|
|
import { isClient } from '@element-plus/utils'
|
|
|
|
import type { ComponentPublicInstance } from 'vue'
|
|
import type { MaybeRef } from '@vueuse/core'
|
|
import type { Modifier } from '@popperjs/core'
|
|
import type { Measurable } from './constants'
|
|
import type { PopperCoreConfigProps } from './content'
|
|
|
|
export const buildPopperOptions = (
|
|
props: PopperCoreConfigProps,
|
|
modifiers: Modifier<any, any>[] = []
|
|
) => {
|
|
const { placement, strategy, popperOptions } = props
|
|
const options = {
|
|
placement,
|
|
strategy,
|
|
...popperOptions,
|
|
modifiers: [...genModifiers(props), ...modifiers],
|
|
}
|
|
|
|
deriveExtraModifiers(options, popperOptions?.modifiers)
|
|
return options
|
|
}
|
|
|
|
export const unwrapMeasurableEl = (
|
|
$el: MaybeRef<Measurable | undefined | ComponentPublicInstance>
|
|
) => {
|
|
if (!isClient) return
|
|
return unrefElement($el as HTMLElement)
|
|
}
|
|
|
|
function genModifiers(options: PopperCoreConfigProps) {
|
|
const { offset, gpuAcceleration, fallbackPlacements } = options
|
|
return [
|
|
{
|
|
name: 'offset',
|
|
options: {
|
|
offset: [0, offset ?? 12],
|
|
},
|
|
},
|
|
{
|
|
name: 'preventOverflow',
|
|
options: {
|
|
padding: {
|
|
top: 0,
|
|
bottom: 0,
|
|
left: 0,
|
|
right: 0,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: 'flip',
|
|
options: {
|
|
padding: 5,
|
|
fallbackPlacements,
|
|
},
|
|
},
|
|
{
|
|
name: 'computeStyles',
|
|
options: {
|
|
gpuAcceleration,
|
|
},
|
|
},
|
|
]
|
|
}
|
|
|
|
function deriveExtraModifiers(
|
|
options: any,
|
|
modifiers: PopperCoreConfigProps['popperOptions']['modifiers']
|
|
) {
|
|
if (modifiers) {
|
|
options.modifiers = [...options.modifiers, ...(modifiers ?? [])]
|
|
}
|
|
}
|