Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit ae04195

Browse files
authored
Merge pull request bootstrap-vue-next#1384 from VividLemon/main
fix: prop active and activeClass across the library have been standar…
2 parents 37db7a1 + 587ac1f commit ae04195

File tree

10 files changed

+77
-44
lines changed

10 files changed

+77
-44
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const props = withDefaults(
8181
variant: 'secondary',
8282
// Link props
8383
active: undefined,
84-
activeClass: 'router-link-active',
84+
activeClass: undefined,
8585
append: false,
8686
href: undefined,
8787
// noPrefetch: {type: [Boolean, String] as PropType<Booleanish>, default: false},

packages/bootstrap-vue-next/src/components/BBadge/BBadge.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const props = withDefaults(
3333
variant: 'secondary',
3434
// Link props
3535
active: undefined,
36-
activeClass: 'router-link-active',
36+
activeClass: undefined,
3737
append: false,
3838
disabled: false,
3939
href: undefined,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const props = withDefaults(
3737
text: undefined,
3838
// Link props
3939
active: false,
40-
activeClass: 'router-link-active',
40+
activeClass: undefined,
4141
append: false,
4242
disabled: false,
4343
event: 'click',

packages/bootstrap-vue-next/src/components/BButton/BButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const props = withDefaults(
8585
block: false,
8686
loadingText: 'Loading...',
8787
// Link props
88-
activeClass: 'router-link-active',
88+
activeClass: undefined,
8989
append: false,
9090
disabled: false,
9191
event: 'click',

packages/bootstrap-vue-next/src/components/BDropdown/BDropdownItem.vue

+64-29
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<li role="presentation">
33
<component
4-
:is="tag"
4+
:is="computedTag"
55
class="dropdown-item"
66
:class="computedClasses"
77
:disabled="disabledBoolean"
88
:aria-disabled="disabledBoolean ? true : null"
99
:aria-current="activeBoolean ? true : null"
10-
:href="tag === 'a' ? href : null"
10+
:href="computedTag === 'a' ? href : null"
1111
:rel="rel"
12-
:type="tag === 'button' ? 'button' : null"
12+
:type="computedTag === 'button' ? 'button' : null"
1313
:target="target"
14-
v-bind="componentAttrs"
14+
v-bind="computedLinkProps"
1515
@click="clicked"
1616
>
1717
<slot />
@@ -21,33 +21,48 @@
2121

2222
<script setup lang="ts">
2323
import BLink from '../BLink/BLink.vue'
24-
import {computed, inject, useAttrs} from 'vue'
25-
import type {Booleanish, ClassValue, ColorVariant, LinkTarget} from '../../types'
24+
import {computed, inject} from 'vue'
25+
import type {BLinkProps, ClassValue} from '../../types'
2626
import {useBooleanish} from '../../composables'
27-
import {collapseInjectionKey, dropdownInjectionKey, navbarInjectionKey} from '../../utils'
27+
import {
28+
collapseInjectionKey,
29+
dropdownInjectionKey,
30+
isLink,
31+
navbarInjectionKey,
32+
pick,
33+
} from '../../utils'
2834
2935
defineOptions({
3036
inheritAttrs: false,
3137
})
3238
3339
const props = withDefaults(
34-
defineProps<{
35-
href?: string
36-
linkClass?: ClassValue
37-
active?: Booleanish
38-
disabled?: Booleanish
39-
rel?: string
40-
target?: LinkTarget
41-
variant?: ColorVariant | null
42-
}>(),
40+
defineProps<
41+
{
42+
linkClass?: ClassValue
43+
} & Omit<BLinkProps, 'event' | 'routerTag'>
44+
>(),
4345
{
44-
active: false,
45-
disabled: false,
46-
rel: undefined,
47-
target: '_self',
48-
variant: null,
4946
linkClass: undefined,
47+
// Link props
48+
active: undefined,
49+
activeClass: undefined,
50+
append: false,
5051
href: undefined,
52+
// noPrefetch: {type: [Boolean, String] as PropType<Booleanish>, default: false},
53+
// prefetch: {type: [Boolean, String] as PropType<Booleanish>, default: null},
54+
rel: undefined,
55+
replace: false,
56+
routerComponentName: 'router-link',
57+
target: '_self',
58+
to: undefined,
59+
opacity: undefined,
60+
opacityHover: undefined,
61+
underlineVariant: null,
62+
underlineOffset: undefined,
63+
underlineOffsetHover: undefined,
64+
underlineOpacity: undefined,
65+
underlineOpacityHover: undefined,
5166
}
5267
)
5368
@@ -63,8 +78,6 @@ defineSlots<{
6378
default?: (props: Record<string, never>) => any
6479
}>()
6580
66-
const attrs = useAttrs()
67-
6881
const computedClasses = computed(() => [
6982
props.linkClass,
7083
{
@@ -74,19 +87,41 @@ const computedClasses = computed(() => [
7487
},
7588
])
7689
77-
const tag = computed<'button' | 'a' | typeof BLink>(() =>
78-
props.href ? 'a' : attrs.to ? BLink : 'button'
90+
const computedLink = computed<boolean>(() => isLink(props))
91+
92+
const computedTag = computed<typeof BLink | 'button' | 'a'>(() =>
93+
computedLink.value ? BLink : props.href ? 'a' : 'button'
7994
)
8095
81-
const componentAttrs = computed(() => ({
82-
...(attrs.to ? {activeClass: 'active', ...attrs} : attrs),
83-
}))
96+
const computedLinkProps = computed(() =>
97+
computedLink.value
98+
? pick(props, [
99+
'active',
100+
'activeClass',
101+
'append',
102+
'href',
103+
'rel',
104+
'replace',
105+
'routerComponentName',
106+
'target',
107+
'to',
108+
'variant',
109+
'opacity',
110+
'opacityHover',
111+
'underlineVariant',
112+
'underlineOffset',
113+
'underlineOffsetHover',
114+
'underlineOpacity',
115+
'underlineOpacityHover',
116+
])
117+
: {}
118+
)
84119
85120
const collapseData = inject(collapseInjectionKey, null)
86121
const dropdownData = inject(dropdownInjectionKey, null)
87122
const navbarData = inject(navbarInjectionKey, null)
88123
89-
// Pretty sure this emits if tag is not button and is disabled
124+
// Pretty sure this emits if computedTag is not button and is disabled
90125
const clicked = (e: MouseEvent): void => {
91126
emit('click', e)
92127
if (navbarData !== null) {

packages/bootstrap-vue-next/src/components/BDropdown/dropdown-item.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ describe('dropdown-item', () => {
4242
expect($blink.exists()).toBe(true)
4343
})
4444

45-
it('child is tag prefers a over blink', () => {
45+
it('child prefers to be blink when href and to', () => {
4646
const wrapper = mount(BDropdownItem, {
4747
props: {href: '/abc', to: '/abc'},
4848
})
49-
const $a = wrapper.find('a')
5049
const $blink = wrapper.findComponent(BLink)
51-
expect($blink.exists()).toBe(false)
52-
expect($a.exists()).toBe(true)
50+
expect($blink.exists()).toBe(true)
5351
})
5452

5553
it('child is tag prefers Blink over button', () => {

packages/bootstrap-vue-next/src/components/BLink/BLink.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defineSlots<{
3737
3838
const props = withDefaults(defineProps<BLinkProps>(), {
3939
active: undefined,
40-
activeClass: 'router-link-active',
40+
activeClass: undefined,
4141
append: false,
4242
disabled: false,
4343
event: 'click',
@@ -151,7 +151,7 @@ const routerAttr = computed(() => ({
151151
}))
152152
153153
const computedLinkClasses = computed(() => ({
154-
[props.activeClass]: activeBoolean.value,
154+
[props.activeClass ?? 'active']: activeBoolean.value,
155155
disabled: disabledBoolean.value,
156156
}))
157157
@@ -176,7 +176,7 @@ const clicked = (e: MouseEvent): void => {
176176
*/
177177
export const BLINK_PROPS = {
178178
active: {type: [Boolean, String, undefined] as PropType<Booleanish>, default: undefined},
179-
activeClass: {type: String, default: 'router-link-active'},
179+
activeClass: {type: String, default: undefined},
180180
append: {type: [Boolean, String] as PropType<Booleanish>, default: false},
181181
disabled: {type: [Boolean, String] as PropType<Booleanish>, default: false},
182182
event: {type: [String, Array], default: 'click'},

packages/bootstrap-vue-next/src/components/BLink/link.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('link', () => {
139139
})
140140

141141
expect(wrapper.element.tagName).toBe('A')
142-
expect(wrapper.classes()).toContain('router-link-active')
142+
expect(wrapper.classes()).toContain('active')
143143
expect(wrapper.classes().length).toBe(1)
144144
})
145145

packages/bootstrap-vue-next/src/components/BNav/BNavItem.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="nav-link"
55
:class="linkClass"
66
v-bind="{...computedLinkProps, ...linkAttrs}"
7-
:active-class="activeClass ?? 'active'"
7+
:active-class="activeClass"
88
:tabindex="disabledBoolean ? -1 : undefined"
99
:aria-disabled="disabledBoolean ? true : undefined"
1010
@click="emit('click', $event)"
@@ -37,7 +37,7 @@ const props = withDefaults(
3737
linkClass: undefined,
3838
// Link props
3939
active: undefined,
40-
activeClass: 'router-link-active',
40+
activeClass: undefined,
4141
append: false,
4242
linkAttrs: undefined,
4343
disabled: false,

packages/bootstrap-vue-next/src/components/BNavbar/BNavbarBrand.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const props = withDefaults(
2525
tag: 'div',
2626
// Link props
2727
active: undefined,
28-
activeClass: 'router-link-active',
28+
activeClass: undefined,
2929
append: false,
3030
disabled: false,
3131
href: undefined,

0 commit comments

Comments
 (0)