fix: dropdowm item can not click (#5257)

This commit is contained in:
kooriookami 2022-01-10 09:48:59 +08:00 committed by GitHub
parent e3417babe2
commit 43ad4aa072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,7 +42,7 @@ export default defineComponent({
ElDropdownItemImpl,
},
props: dropdownItemProps,
emits: ['pointermove', 'pointerleave'],
emits: ['pointermove', 'pointerleave', 'click'],
setup(props, { emit }) {
const { elDropdown } = useDropdown()
const _instance = getCurrentInstance()
@ -79,17 +79,23 @@ export default defineComponent({
onItemLeave(e)
})
)
function handleClick(e: UIEvent) {
// if disabled don't collapse the drop-down list
if (props.disabled) {
e.stopImmediatePropagation()
return
const handleClick = composeEventHandlers(
(e: PointerEvent) => {
emit('click', e)
return e.defaultPrevented
},
(e) => {
if (props.disabled) {
e.stopImmediatePropagation()
return
}
if (elDropdown?.hideOnClick?.value) {
elDropdown.handleClick?.()
}
elDropdown.commandHandler?.(props.command, _instance, e)
}
if (elDropdown?.hideOnClick?.value) {
elDropdown.handleClick?.()
}
elDropdown.commandHandler?.(props.command, _instance, e)
}
)
return {
handleClick,