mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-21 23:40:39 +01:00
fix(Button): duplicate click handlers (#2213)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -25,7 +25,7 @@ export interface ButtonProps extends UseComponentIconsProps, Omit<LinkProps, 'ra
|
||||
block?: boolean
|
||||
/** Set loading state automatically based on the `@click` promise state */
|
||||
loadingAuto?: boolean
|
||||
onClick?: (event: Event) => void | Promise<void>
|
||||
onClick?: ((event: MouseEvent) => void | Promise<void>) | Array<((event: MouseEvent) => void | Promise<void>)>
|
||||
class?: any
|
||||
ui?: PartialString<typeof button.slots>
|
||||
}
|
||||
@@ -56,10 +56,11 @@ const { orientation, size: buttonSize } = useButtonGroup<ButtonProps>(props)
|
||||
const loadingAutoState = ref(false)
|
||||
const formLoading = inject<Ref<boolean> | 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user