Skip to content

Commit 0448cfa

Browse files
committed
fix(BAvatar): fix tag to be button and has attr type when prop button and prop buttonType
1 parent 943188f commit 0448cfa

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

packages/bootstrap-vue-3/src/components/BAvatar/BAvatar.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import {isEmptySlot, isNumeric, toFloat} from '../../utils'
3030
import type {BAvatarGroupParentData} from '../../types/components'
3131
import {computed, inject, StyleValue, toRef, useSlots} from 'vue'
32-
import type {Booleanish, ColorVariant, TextColorVariant} from '../../types'
32+
import type {Booleanish, ButtonType, ColorVariant, TextColorVariant} from '../../types'
3333
import {injectionKey} from './BAvatarGroup.vue'
3434
import {useBooleanish} from '../../composables'
3535
@@ -42,7 +42,7 @@ interface BAvatarProps {
4242
badgeTop?: Booleanish
4343
badgeVariant?: ColorVariant
4444
button?: Booleanish
45-
buttonType?: string
45+
buttonType?: ButtonType
4646
disabled?: Booleanish
4747
icon?: string
4848
rounded?: boolean | string
@@ -117,6 +117,7 @@ const computedRounded = computed<string | boolean>(() =>
117117
)
118118
119119
const attrs = computed(() => ({
120+
'type': buttonBoolean.value ? props.buttonType : undefined,
120121
'aria-label': props.ariaLabel || null,
121122
'disabled': disabledBoolean.value || null,
122123
}))
@@ -184,8 +185,7 @@ const marginStyle = computed(() => {
184185
return value ? {marginLeft: value, marginRight: value} : {}
185186
})
186187
187-
// TODO this is incorrect. If buttonType is 'submit' and prop button is true, it will break the component
188-
const tag = computed<string>(() => (buttonBoolean.value ? props.buttonType : 'span'))
188+
const tag = computed<'button' | 'span'>(() => (buttonBoolean.value ? 'button' : 'span'))
189189
const tagStyle = computed(() => ({
190190
...marginStyle.value,
191191
width: computedSize.value,

packages/bootstrap-vue-3/src/components/BAvatar/avatar.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,32 @@ describe('avatar', () => {
1010
expect(wrapper.classes()).toContain('b-avatar')
1111
})
1212

13-
it('tag is default button when prop button is true', () => {
13+
it('tag is button when prop button is true', () => {
1414
const wrapper = mount(BAvatar, {
1515
props: {button: true},
1616
})
1717
expect(wrapper.element.tagName).toBe('BUTTON')
1818
})
1919

20-
it('tag is prop buttonType when prop button is true', () => {
20+
it('has attr type when prop button to be default button', () => {
2121
const wrapper = mount(BAvatar, {
22-
props: {button: true, buttonType: 'div'},
22+
props: {button: true},
23+
})
24+
expect(wrapper.attributes('type')).toBe('button')
25+
})
26+
27+
it('has attr type when prop button to be prop buttonType', () => {
28+
const wrapper = mount(BAvatar, {
29+
props: {button: true, buttonType: 'submit'},
30+
})
31+
expect(wrapper.attributes('type')).toBe('submit')
32+
})
33+
34+
it('does not have attr type when prop buttonType but not prop button', () => {
35+
const wrapper = mount(BAvatar, {
36+
props: {button: false, buttonType: 'submit'},
2337
})
24-
expect(wrapper.element.tagName).toBe('DIV')
38+
expect(wrapper.attributes('type')).toBeUndefined()
2539
})
2640

2741
it('tag is default span', () => {

0 commit comments

Comments
 (0)