Files
element-plus/packages/components/popper/src/content.ts
qiang 4684320916 fix(components): [popconfirm] unable to capture focus (#22310)
* fix(components): [popconfirm] unable to capture focus

* fix: test

* chore: revert event
2025-09-26 20:58:19 +08:00

151 lines
4.2 KiB
TypeScript

import { placements } from '@popperjs/core'
import { buildProps, definePropType } from '@element-plus/utils'
import { useAriaProps } from '@element-plus/hooks'
import { popperArrowProps } from './arrow'
import type { PopperEffect } from './popper'
import type {
ExtractPropTypes,
StyleValue,
__ExtractPublicPropTypes,
} from 'vue'
import type { Options, Placement } from '@popperjs/core'
import type { Measurable } from './constants'
import type Content from './content.vue'
type ClassObjectType = Record<string, boolean>
type ClassType = string | ClassObjectType | ClassType[]
const POSITIONING_STRATEGIES = ['fixed', 'absolute'] as const
export interface CreatePopperInstanceParams {
referenceEl: Measurable
popperContentEl: HTMLElement
arrowEl: HTMLElement | undefined
}
export const popperCoreConfigProps = buildProps({
boundariesPadding: {
type: Number,
default: 0,
},
fallbackPlacements: {
type: definePropType<Placement[]>(Array),
default: undefined,
},
gpuAcceleration: {
type: Boolean,
default: true,
},
/**
* @description offset of the Tooltip
*/
offset: {
type: Number,
default: 12,
},
/**
* @description position of Tooltip
*/
placement: {
type: String,
values: placements,
default: 'bottom',
},
/**
* @description [popper.js](https://popper.js.org/docs/v2/) parameters
*/
popperOptions: {
type: definePropType<Partial<Options>>(Object),
default: () => ({}),
},
strategy: {
type: String,
values: POSITIONING_STRATEGIES,
default: 'absolute',
},
} as const)
export type PopperCoreConfigProps = ExtractPropTypes<
typeof popperCoreConfigProps
>
export type PopperCoreConfigPropsPublic = __ExtractPublicPropTypes<
typeof popperCoreConfigProps
>
export const popperContentProps = buildProps({
...popperCoreConfigProps,
...popperArrowProps,
id: String,
style: {
type: definePropType<StyleValue>([String, Array, Object]),
},
className: {
type: definePropType<ClassType>([String, Array, Object]),
},
effect: {
type: definePropType<PopperEffect>(String),
default: 'dark',
},
visible: Boolean,
enterable: {
type: Boolean,
default: true,
},
pure: Boolean,
focusOnShow: Boolean,
trapping: Boolean,
popperClass: {
type: definePropType<ClassType>([String, Array, Object]),
},
popperStyle: {
type: definePropType<StyleValue>([String, Array, Object]),
},
referenceEl: {
type: definePropType<HTMLElement>(Object),
},
triggerTargetEl: {
type: definePropType<HTMLElement>(Object),
},
stopPopperMouseEvent: {
type: Boolean,
default: true,
},
virtualTriggering: Boolean,
zIndex: Number,
...useAriaProps(['ariaLabel']),
loop: Boolean,
} as const)
export type PopperContentProps = ExtractPropTypes<typeof popperContentProps>
export type PopperContentPropsPublic = __ExtractPublicPropTypes<
typeof popperContentProps
>
export const popperContentEmits = {
mouseenter: (evt: MouseEvent) => evt instanceof MouseEvent,
mouseleave: (evt: MouseEvent) => evt instanceof MouseEvent,
focus: () => true,
blur: () => true,
close: () => true,
}
export type PopperContentEmits = typeof popperContentEmits
export type PopperContentInstance = InstanceType<typeof Content> & unknown
/** @deprecated use `popperCoreConfigProps` instead, and it will be deprecated in the next major version */
export const usePopperCoreConfigProps = popperCoreConfigProps
/** @deprecated use `popperContentProps` instead, and it will be deprecated in the next major version */
export const usePopperContentProps = popperContentProps
/** @deprecated use `popperContentEmits` instead, and it will be deprecated in the next major version */
export const usePopperContentEmits = popperContentEmits
/** @deprecated use `PopperCoreConfigProps` instead, and it will be deprecated in the next major version */
export type UsePopperCoreConfigProps = PopperCoreConfigProps
/** @deprecated use `PopperContentProps` instead, and it will be deprecated in the next major version */
export type UsePopperContentProps = PopperContentProps
/** @deprecated use `PopperContentInstance` instead, and it will be deprecated in the next major version */
export type ElPopperArrowContent = PopperContentInstance