Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit dd9599f

Browse files
committed
fix(Button): add type prop and default to button to avoid native form submission
1 parent 3665651 commit dd9599f

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/components/buttons/button/Button.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Button/Button', () => {
1414
});
1515
expect(wrapper.text()).toContain(label);
1616
expect(wrapper.classes()).toMatch(/_btn_/);
17+
expect(wrapper.attributes('type')).toBe('button');
1718
});
1819

1920
it('passes disabled props', async () => {

src/components/buttons/button/Button.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const meta: Meta<PropsAndLabel> = {
3737
elevation: { control: 'number', table: { category: 'Shape' } },
3838
icon: { control: 'boolean', table: { category: 'Shape' } },
3939
size: { control: 'select', options: ['medium', 'sm', 'lg'] },
40+
type: { control: 'select', options: ['button', 'submit'] },
4041
disabled: { control: 'boolean', table: { category: 'State' } },
4142
loading: { control: 'boolean', table: { category: 'State' } },
4243
},

src/components/buttons/button/Button.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ButtonProps {
1515
active?: boolean;
1616
size?: 'sm' | 'lg';
1717
tag?: 'button' | 'a';
18+
type?: 'button' | 'submit';
1819
value?: ModelType;
1920
}
2021
@@ -33,6 +34,7 @@ const props = withDefaults(defineProps<ButtonProps>(), {
3334
active: false,
3435
size: undefined,
3536
tag: 'button',
37+
type: 'button',
3638
value: undefined,
3739
});
3840
@@ -98,6 +100,7 @@ const slots = useSlots();
98100
},
99101
]"
100102
:disabled="disabled || loading"
103+
:type="tag === 'button' ? type : undefined"
101104
v-bind="attrs"
102105
v-on="
103106
// eslint-disable-next-line vue/no-deprecated-dollar-listeners-api

0 commit comments

Comments
 (0)