refactor(ui): button only submits form if onClick is undefined
This commit is contained in:
parent
d76191a188
commit
ee480eaf43
|
@ -18,7 +18,7 @@ const props = defineProps<{
|
||||||
round?: boolean
|
round?: boolean
|
||||||
icon?: string | `right ${string}`
|
icon?: string | `right ${string}`
|
||||||
|
|
||||||
onClick?: (...args: any[]) => void | Promise<void>
|
onClick?: (...args: any[]) => void | Promise<void> // The default fallback is `submit`
|
||||||
|
|
||||||
split?: boolean // Add this prop for split button support
|
split?: boolean // Add this prop for split button support
|
||||||
splitIcon?: string // Add this prop for the split button icon
|
splitIcon?: string // Add this prop for the split button icon
|
||||||
|
@ -142,6 +142,7 @@ onMounted(() => {
|
||||||
'is-shadow': shadow,
|
'is-shadow': shadow,
|
||||||
}"
|
}"
|
||||||
@click="click"
|
@click="click"
|
||||||
|
:type="onClick ? 'button' : 'submit' /* Prevents default `submit` if onCLick is set */"
|
||||||
>
|
>
|
||||||
<i v-if="icon && !icon.startsWith('right ')" :class="['bi', icon]" />
|
<i v-if="icon && !icon.startsWith('right ')" :class="['bi', icon]" />
|
||||||
<span v-if="!isIconOnly">
|
<span v-if="!isIconOnly">
|
||||||
|
|
|
@ -36,6 +36,22 @@ Buttons are UI elements that users can interact with to perform actions and mani
|
||||||
& AlignmentProps
|
& AlignmentProps
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Action
|
||||||
|
|
||||||
|
[The default action of buttons is `submit` \[mdn\]](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#type). Specify an `onClick` function to change the behavior of a button.
|
||||||
|
|
||||||
|
```vue-html
|
||||||
|
<form>
|
||||||
|
<Button>Without `onClick`</Button>
|
||||||
|
<Button :onClick="() => {}">With `onClick`</Button>
|
||||||
|
</form>
|
||||||
|
```
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<Button>Without `onClick`</Button>
|
||||||
|
<Button :onClick="() => {}">With `onClick`</Button>
|
||||||
|
</form>
|
||||||
|
|
||||||
## Button colors
|
## Button colors
|
||||||
|
|
||||||
Buttons come in different types depending on the type of action they represent.
|
Buttons come in different types depending on the type of action they represent.
|
||||||
|
|
Loading…
Reference in New Issue