Skip to content

Commit b9b3fd3

Browse files
committed
feat(BInputGroupAppend)!: remove useless props
Prop id was pretty useless, and since the component doesn't need a dynamic wrapper, tag is removed. (The single root is removed since it's not needed in Vue 3) feat(BInputGroupPrepend)!: remove useless props fix(#470): no rounded corners when using BInputGrooupPrepend or BInputGroupAppend test: fix test files for above changes
1 parent 875d942 commit b9b3fd3

File tree

6 files changed

+26
-138
lines changed

6 files changed

+26
-138
lines changed
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
<template>
2-
<component :is="tag" :id="id" class="d-flex" :class="computedClasses">
3-
<b-input-group-text v-if="isTextBoolean">
4-
<slot />
5-
</b-input-group-text>
6-
<slot v-else />
7-
</component>
2+
<b-input-group-text v-if="isTextBoolean">
3+
<slot />
4+
</b-input-group-text>
5+
<slot v-else />
86
</template>
97

108
<script setup lang="ts">
119
// import type {BInputGroupAddonProps} from '../../types/components'
1210
import type {Booleanish} from '../../types'
1311
import {useBooleanish} from '../../composables'
14-
import {computed, toRef} from 'vue'
12+
import {toRef} from 'vue'
1513
import BInputGroupText from './BInputGroupText.vue'
1614
1715
interface BInputGroupAddonProps {
18-
append?: Booleanish
19-
id?: string
2016
isText?: Booleanish
21-
tag?: string
2217
}
2318
2419
const props = withDefaults(defineProps<BInputGroupAddonProps>(), {
25-
append: false,
26-
tag: 'div',
2720
isText: false,
2821
})
2922
30-
const appendBoolean = useBooleanish(toRef(props, 'append'))
3123
const isTextBoolean = useBooleanish(toRef(props, 'isText'))
32-
33-
const computedClasses = computed(() => ({
34-
'input-group-append': appendBoolean.value,
35-
'input-group-prepend': !appendBoolean.value,
36-
}))
3724
</script>
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
<template>
2-
<b-input-group-addon v-bind="computedAttrs">
2+
<b-input-group-addon :is-text="isText">
33
<slot />
44
</b-input-group-addon>
55
</template>
66

77
<script setup lang="ts">
88
// import type {BInputGroupAppendProps} from '../../types/components'
99
import BInputGroupAddon from './BInputGroupAddon.vue'
10-
import {computed} from 'vue'
1110
import type {Booleanish} from '../../types'
1211
1312
interface BInputGroupAppendProps {
14-
id?: string
1513
isText?: Booleanish
16-
tag?: string
1714
}
1815
19-
const props = withDefaults(defineProps<BInputGroupAppendProps>(), {
20-
tag: 'div',
16+
withDefaults(defineProps<BInputGroupAppendProps>(), {
2117
isText: false,
2218
})
23-
24-
const computedAttrs = computed(() => ({
25-
id: props.id,
26-
isText: props.isText,
27-
tag: props.tag,
28-
append: true,
29-
}))
3019
</script>
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
<template>
2-
<b-input-group-addon v-bind="computedAttrs">
2+
<b-input-group-addon :is-text="isText">
33
<slot />
44
</b-input-group-addon>
55
</template>
66

77
<script setup lang="ts">
88
// import type {BInputGroupPrependProps} from '../../types/components'
99
import BInputGroupAddon from './BInputGroupAddon.vue'
10-
import {computed} from 'vue'
1110
import type {Booleanish} from '../../types'
1211
1312
interface BInputGroupPrependProps {
14-
id?: string
1513
isText?: Booleanish
16-
tag?: string
1714
}
1815
19-
const props = withDefaults(defineProps<BInputGroupPrependProps>(), {
20-
tag: 'div',
16+
withDefaults(defineProps<BInputGroupPrependProps>(), {
2117
isText: false,
2218
})
23-
24-
const computedAttrs = computed(() => ({
25-
id: props.id,
26-
isText: props.isText,
27-
tag: props.tag,
28-
append: false,
29-
}))
3019
</script>

packages/bootstrap-vue-3/src/components/BInputGroup/input-group-addon.spec.ts

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,40 @@ import {enableAutoUnmount, mount} from '@vue/test-utils'
22
import BInputGroupAddon from './BInputGroupAddon.vue'
33
import BInputGroupText from './BInputGroupText.vue'
44
import {afterEach, describe, expect, it} from 'vitest'
5+
import {h} from 'vue'
56

67
describe('input-group-addon', () => {
78
enableAutoUnmount(afterEach)
89

9-
it('tag is div by default', () => {
10-
const wrapper = mount(BInputGroupAddon)
11-
expect(wrapper.element.tagName).toBe('DIV')
12-
})
13-
14-
it('tag is prop tag', () => {
15-
const wrapper = mount(BInputGroupAddon, {
16-
props: {tag: 'span'},
17-
})
18-
expect(wrapper.element.tagName).toBe('SPAN')
19-
})
20-
21-
it('has attr id when prop id', async () => {
22-
const wrapper = mount(BInputGroupAddon, {
23-
props: {id: 'foobar'},
24-
})
25-
expect(wrapper.attributes('id')).toBe('foobar')
26-
await wrapper.setProps({id: 'bar'})
27-
expect(wrapper.attributes('id')).toBe('bar')
28-
})
29-
30-
it('has static class d-flex', () => {
31-
const wrapper = mount(BInputGroupAddon)
32-
expect(wrapper.classes()).toContain('d-flex')
33-
})
34-
35-
it('has class input-group-append when prop append', () => {
36-
const wrapper = mount(BInputGroupAddon, {
37-
props: {append: true},
38-
})
39-
expect(wrapper.classes()).toContain('input-group-append')
40-
})
41-
42-
it('has class input-group-prepend when prop append is false', () => {
10+
it('is not wrapped in BInputGroupText when not prop isText', () => {
4311
const wrapper = mount(BInputGroupAddon, {
44-
props: {append: false},
12+
props: {isText: false},
4513
})
46-
expect(wrapper.classes()).toContain('input-group-prepend')
14+
const $inputgrouptext = wrapper.findComponent(BInputGroupText)
15+
expect($inputgrouptext.exists()).toBe(false)
4716
})
4817

49-
it('has BInputGroupText when prop isText', () => {
18+
it('is wrapped in BInputGroupText when not isText', () => {
5019
const wrapper = mount(BInputGroupAddon, {
5120
props: {isText: true},
5221
})
5322
const $inputgrouptext = wrapper.findComponent(BInputGroupText)
5423
expect($inputgrouptext.exists()).toBe(true)
5524
})
5625

57-
it('does not have BInputGroupText when prop not isText', () => {
26+
it('renders default sloot when not prop isText', () => {
5827
const wrapper = mount(BInputGroupAddon, {
59-
props: {isText: false},
28+
slots: {default: 'foobar'},
6029
})
61-
const $inputgrouptext = wrapper.findComponent(BInputGroupText)
62-
expect($inputgrouptext.exists()).toBe(false)
30+
expect(wrapper.text()).toBe('foobar')
6331
})
6432

65-
it('BInputGroupText renders default slot', () => {
33+
it('renders default sloot when not prop isText', () => {
6634
const wrapper = mount(BInputGroupAddon, {
67-
props: {isText: true},
6835
slots: {default: 'foobar'},
36+
props: {isText: true},
6937
})
7038
const $inputgrouptext = wrapper.getComponent(BInputGroupText)
7139
expect($inputgrouptext.text()).toBe('foobar')
7240
})
73-
74-
it('renders default slot', () => {
75-
const wrapper = mount(BInputGroupAddon, {
76-
slots: {default: 'foobar'},
77-
})
78-
expect(wrapper.text()).toBe('foobar')
79-
})
8041
})

packages/bootstrap-vue-3/src/components/BInputGroup/input-group-append.spec.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ describe('input-group-append', () => {
1212
expect($inputgroupaddon.exists()).toBe(true)
1313
})
1414

15-
it('BInputGroupAddon is given prop id', async () => {
16-
const wrapper = mount(BInputGroupAppend, {
17-
props: {id: 'foobar'},
18-
})
19-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
20-
expect($inputgroupaddon.props('id')).toBe('foobar')
21-
await wrapper.setProps({id: 'foo'})
22-
expect($inputgroupaddon.props('id')).toBe('foo')
23-
})
24-
2515
it('BInputGroupAddon is given prop isText', async () => {
2616
const wrapper = mount(BInputGroupAppend, {
2717
props: {isText: true},
@@ -32,19 +22,10 @@ describe('input-group-append', () => {
3222
expect($inputgroupaddon.props('isText')).toBe(false)
3323
})
3424

35-
it('BInputGroupAddon is given prop tag', async () => {
25+
it('renders default slot', () => {
3626
const wrapper = mount(BInputGroupAppend, {
37-
props: {tag: 'span'},
27+
slots: {default: 'foobar'},
3828
})
39-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
40-
expect($inputgroupaddon.props('tag')).toBe('span')
41-
await wrapper.setProps({tag: 'div'})
42-
expect($inputgroupaddon.props('tag')).toBe('div')
43-
})
44-
45-
it('BInputGroupAddon is given prop append to be true', () => {
46-
const wrapper = mount(BInputGroupAppend)
47-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
48-
expect($inputgroupaddon.props('append')).toBe(true)
29+
expect(wrapper.text()).toBe('foobar')
4930
})
5031
})

packages/bootstrap-vue-3/src/components/BInputGroup/input-group.prepend.spec.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ describe('input-group-prepend', () => {
1212
expect($inputgroupaddon.exists()).toBe(true)
1313
})
1414

15-
it('BInputGroupAddon is given prop id', async () => {
16-
const wrapper = mount(BInputGroupPrepend, {
17-
props: {id: 'foobar'},
18-
})
19-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
20-
expect($inputgroupaddon.props('id')).toBe('foobar')
21-
await wrapper.setProps({id: 'foo'})
22-
expect($inputgroupaddon.props('id')).toBe('foo')
23-
})
24-
2515
it('BInputGroupAddon is given prop isText', async () => {
2616
const wrapper = mount(BInputGroupPrepend, {
2717
props: {isText: true},
@@ -32,19 +22,10 @@ describe('input-group-prepend', () => {
3222
expect($inputgroupaddon.props('isText')).toBe(false)
3323
})
3424

35-
it('BInputGroupAddon is given prop tag', async () => {
25+
it('renders default slot', () => {
3626
const wrapper = mount(BInputGroupPrepend, {
37-
props: {tag: 'span'},
27+
slots: {default: 'foobar'},
3828
})
39-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
40-
expect($inputgroupaddon.props('tag')).toBe('span')
41-
await wrapper.setProps({tag: 'div'})
42-
expect($inputgroupaddon.props('tag')).toBe('div')
43-
})
44-
45-
it('BInputGroupAddon is given prop append to be false', () => {
46-
const wrapper = mount(BInputGroupPrepend)
47-
const $inputgroupaddon = wrapper.getComponent(BInputGroupAddon)
48-
expect($inputgroupaddon.props('append')).toBe(false)
29+
expect(wrapper.text()).toBe('foobar')
4930
})
5031
})

0 commit comments

Comments
 (0)