Skip to content

Commit 9153b43

Browse files
authored
Merge pull request #715 from VividLemon/master
fix(#714): v-bind={text} causes breaking items to not display text in nested BLink component
2 parents aee0c63 + 9d4060f commit 9153b43

File tree

5 files changed

+70
-35
lines changed

5 files changed

+70
-35
lines changed

packages/bootstrap-vue-3/src/components/BBreadcrumb/BBreadcrumbItem.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
<component
44
:is="computedTag"
55
:aria-current="computedAriaCurrent"
6-
v-bind="$props"
6+
v-bind="computedTag !== 'span' ? pluckedLinkProps : undefined"
77
@click="clicked"
88
>
9-
<slot />
9+
<slot>
10+
{{ text }}
11+
</slot>
1012
</component>
1113
</li>
1214
</template>
1315

1416
<script lang="ts">
15-
import {omit} from '../../utils'
17+
import {omit, pluckProps} from '../../utils'
1618
import {useBooleanish} from '../../composables'
1719
import {computed, defineComponent, PropType, toRef} from 'vue'
1820
import BLink, {BLINK_PROPS} from '../BLink/BLink.vue'
@@ -55,7 +57,13 @@ export default defineComponent({
5557
if (!disabledBoolean.value) emit('click', e)
5658
}
5759
60+
// TODO test and make sure that only the correct props are given to BLINK
61+
// Since the BLink resolved to an <a>, passing "text" prop down caused
62+
// <a> slot text to be overwritten by prop text!
63+
const pluckedLinkProps = computed(() => pluckProps(props, linkProps))
64+
5865
return {
66+
pluckedLinkProps,
5967
liClasses,
6068
computedTag,
6169
computedAriaCurrent,
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
<component :is="tag" class="placeholder" :class="classes" />
2+
<component :is="tag" class="placeholder" :class="classes" :style="computedStyle" />
33
</template>
44

55
<script setup lang="ts">
6-
import {computed} from 'vue'
6+
import {computed, StyleValue} from 'vue'
77
import {ColorVariant} from '../../types'
88
99
interface Props {
@@ -19,28 +19,32 @@ const props = withDefaults(defineProps<Props>(), {
1919
tag: 'span',
2020
})
2121
22-
/**
23-
* Converts numbers, strings, or strings in percent to a string
24-
* ex 100% => 100 for w-100
25-
*/
26-
const filterer = (str: string | number | undefined): string | undefined =>
27-
str === undefined
22+
const widthString = computed<string | undefined>(() =>
23+
props.width === undefined
2824
? undefined
29-
: typeof str === 'string'
30-
? str.indexOf('%') === -1
31-
? str
32-
: str.replaceAll('%', '')
33-
: str.toString()
25+
: typeof props.width === 'number'
26+
? props.width.toString()
27+
: props.width.includes('%')
28+
? props.width.replaceAll('%', '')
29+
: props.width
30+
)
3431
35-
const colsString = computed<string | undefined>(() => filterer(props.cols))
36-
37-
const widthString = computed<string | undefined>(() => filterer(props.width))
32+
const colsString = computed<string | undefined>(() =>
33+
props.cols === undefined
34+
? undefined
35+
: typeof props.cols === 'number'
36+
? props.cols.toString()
37+
: props.cols
38+
)
3839
3940
const classes = computed(() => ({
40-
[`col-${colsString.value}`]: colsString.value !== undefined,
41-
[`w-${widthString.value}`]: colsString.value === undefined && widthString.value !== undefined,
41+
[`col-${colsString.value}`]: colsString.value !== undefined && widthString.value === undefined,
4242
[`bg-${props.variant}`]: props.variant !== undefined,
4343
[`placeholder-${props.size}`]: props.size !== undefined,
4444
[`placeholder-${props.animation}`]: props.animation !== undefined,
4545
}))
46+
47+
const computedStyle = computed<StyleValue | undefined>(() =>
48+
widthString.value === undefined ? undefined : `width: ${widthString.value}%;`
49+
)
4650
</script>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {enableAutoUnmount, mount} from '@vue/test-utils'
2+
import {afterEach, describe, expect, it} from 'vitest'
3+
import BPlaceholderWrapper from './BPlaceholderWrapper.vue'
4+
5+
describe('placeholder-wrapper', () => {
6+
enableAutoUnmount(afterEach)
7+
8+
it('renders slot default by default', () => {
9+
const wrapper = mount(BPlaceholderWrapper, {
10+
slots: {default: 'default', loading: 'loading'},
11+
})
12+
expect(wrapper.text()).toBe('default')
13+
})
14+
15+
it('renders slot default when prop loading false', () => {
16+
const wrapper = mount(BPlaceholderWrapper, {
17+
props: {loading: false},
18+
slots: {default: 'default', loading: 'loading'},
19+
})
20+
expect(wrapper.text()).toBe('default')
21+
})
22+
23+
it('renders slot loading when prop loading true', () => {
24+
const wrapper = mount(BPlaceholderWrapper, {
25+
props: {loading: true},
26+
slots: {default: 'default', loading: 'loading'},
27+
})
28+
expect(wrapper.text()).toBe('loading')
29+
})
30+
})

packages/bootstrap-vue-3/src/components/BPlaceholder/placeholder.spec.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,27 @@ describe('placeholder', () => {
3838
expect(wrapper.classes()).toContain('col-6')
3939
})
4040

41-
it('has class col-{type} when prop cols is string and contains %', () => {
42-
const wrapper = mount(BPlaceholder, {
43-
props: {cols: '%6%'},
44-
})
45-
expect(wrapper.classes()).toContain('col-6')
46-
})
47-
48-
it('has class w-{type} when prop width is number', async () => {
41+
it('has style width: {type}%; when prop width is number', async () => {
4942
const wrapper = mount(BPlaceholder, {
5043
props: {width: 6},
5144
})
52-
expect(wrapper.classes()).toContain('w-6')
45+
expect(wrapper.attributes('style')).toContain('width: 6%;')
5346
await wrapper.setProps({width: undefined})
54-
expect(wrapper.classes()).not.toContain('w-6')
47+
expect(wrapper.attributes('style')).toBeUndefined()
5548
})
5649

57-
it('has class w-{type} when prop width is string', () => {
50+
it('has style width: {type}%; when prop width is string', () => {
5851
const wrapper = mount(BPlaceholder, {
5952
props: {width: '6'},
6053
})
61-
expect(wrapper.classes()).toContain('w-6')
54+
expect(wrapper.attributes('style')).toContain('width: 6%;')
6255
})
6356

64-
it('has class w-{type} when prop width is string and contains %', () => {
57+
it('has style width: {type}%; when prop width is string and contains %', () => {
6558
const wrapper = mount(BPlaceholder, {
6659
props: {width: '%6%'},
6760
})
68-
expect(wrapper.classes()).toContain('w-6')
61+
expect(wrapper.attributes('style')).toContain('width: 6%;')
6962
})
7063

7164
it('has class bg-{type} when prop variant', async () => {

0 commit comments

Comments
 (0)