mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 20:27:44 +08:00
7bb6b6d99f
* refactor(utils): drop off/on/once, use EventListener instead * refactor(utils): use useEventListener * refactor(utils): use useEventListener * style(components): [roving-focus-group] useEventListener pass ref
21 lines
607 B
TypeScript
21 lines
607 B
TypeScript
export const composeEventHandlers = <E>(
|
|
theirsHandler?: (event: E) => boolean | void,
|
|
oursHandler?: (event: E) => void,
|
|
{ checkForDefaultPrevented = true } = {}
|
|
) => {
|
|
const handleEvent = (event: E) => {
|
|
const shouldPrevent = theirsHandler?.(event)
|
|
|
|
if (checkForDefaultPrevented === false || !shouldPrevent) {
|
|
return oursHandler?.(event)
|
|
}
|
|
}
|
|
return handleEvent
|
|
}
|
|
|
|
type WhenMouseHandler = (e: PointerEvent) => any
|
|
export const whenMouse = (handler: WhenMouseHandler): WhenMouseHandler => {
|
|
return (e: PointerEvent) =>
|
|
e.pointerType === 'mouse' ? handler(e) : undefined
|
|
}
|