diff --git a/src/runtime/components/Button.vue b/src/runtime/components/Button.vue index 28972ae2..66888334 100644 --- a/src/runtime/components/Button.vue +++ b/src/runtime/components/Button.vue @@ -25,7 +25,7 @@ export interface ButtonProps extends UseComponentIconsProps, Omit void | Promise + onClick?: ((event: MouseEvent) => void | Promise) | Array<((event: MouseEvent) => void | Promise)> class?: any ui?: PartialString } @@ -56,10 +56,11 @@ const { orientation, size: buttonSize } = useButtonGroup(props) const loadingAutoState = ref(false) const formLoading = inject | undefined>(formLoadingInjectionKey, undefined) -async function onClickWrapper(event: Event) { +async function onClickWrapper(event: MouseEvent) { loadingAutoState.value = true + const callbacks = Array.isArray(props.onClick) ? props.onClick : [props.onClick] try { - await props.onClick?.(event) + await Promise.all(callbacks.map(fn => fn?.(event))) } finally { loadingAutoState.value = false } diff --git a/src/runtime/components/LinkBase.vue b/src/runtime/components/LinkBase.vue index 67a5391c..481e03eb 100644 --- a/src/runtime/components/LinkBase.vue +++ b/src/runtime/components/LinkBase.vue @@ -3,7 +3,7 @@ export interface LinkBaseProps { as?: string type?: string disabled?: boolean - click?: (e: MouseEvent) => void + onClick?: (e: MouseEvent) => void | Promise href?: string navigate?: (e: MouseEvent) => void rel?: string @@ -20,15 +20,15 @@ const props = withDefaults(defineProps(), { type: 'button' }) -function onClick(e: MouseEvent) { +function onClickWrapper(e: MouseEvent) { if (props.disabled) { e.stopPropagation() e.preventDefault() return } - if (props.click) { - props.click(e) + if (props.onClick) { + props.onClick(e) } if (props.href && props.navigate && !props.isExternal) { @@ -54,7 +54,7 @@ function onClick(e: MouseEvent) { }" :rel="rel" :target="target" - @click="onClick" + @click="onClickWrapper" >