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

Commit d6a42db

Browse files
committed
feat(BNavbar): add auto-close to disable collapse closing
1 parent 764685d commit d6a42db

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const navbarData = inject(navbarInjectionKey, null)
9595
// Pretty sure this emits if computedTag is not button and is disabled
9696
const clicked = (e: MouseEvent): void => {
9797
emit('click', e)
98-
if (navbarData !== null) {
98+
if (navbarData !== null && navbarData?.autoClose?.value === true) {
9999
collapseData?.close?.()
100100
}
101101
dropdownData?.close?.()

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:href="localHref"
1313
:class="[(activeBoolean ?? isActive) && `${activeClass} ${defaultActiveClass}`]"
1414
v-bind="$attrs"
15-
@click=";[navigate($event), closeCollapse(), clicked($event)]"
15+
@click=";[navigate($event), clicked($event)]"
1616
>
1717
<slot />
1818
</component>
@@ -78,11 +78,6 @@ const disabledBoolean = useBooleanish(() => props.disabled)
7878
const replaceBoolean = useBooleanish(() => props.replace)
7979
const collapseData = inject(collapseInjectionKey, null)
8080
const navbarData = inject(navbarInjectionKey, null)
81-
const closeCollapse = () => {
82-
if (navbarData !== null) {
83-
collapseData?.close?.()
84-
}
85-
}
8681
8782
const instance = getCurrentInstance()
8883
@@ -164,7 +159,10 @@ const clicked = (e: MouseEvent): void => {
164159
return
165160
}
166161
167-
if (collapseData?.isNav?.value === true) {
162+
if (
163+
(collapseData?.isNav?.value === true && navbarData === null) ||
164+
(navbarData !== null && navbarData?.autoClose?.value === true)
165+
) {
168166
collapseData?.close?.()
169167
}
170168

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

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const props = withDefaults(
2222
toggleable?: boolean | Breakpoint
2323
variant?: ColorVariant | null
2424
container?: 'fluid' | boolean
25+
autoClose?: boolean
2526
}>(),
2627
{
2728
variant: null,
@@ -31,6 +32,7 @@ const props = withDefaults(
3132
tag: 'nav',
3233
toggleable: false,
3334
container: 'fluid',
35+
autoClose: true,
3436
}
3537
)
3638
@@ -65,5 +67,6 @@ const computedClasses = computed(() => ({
6567
6668
provide(navbarInjectionKey, {
6769
tag: toRef(() => props.tag),
70+
autoClose: toRef(() => props.autoClose),
6871
})
6972
</script>

packages/bootstrap-vue-next/src/utils/keys.ts

+1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ export const dropdownInjectionKey: InjectionKey<{
104104

105105
export const navbarInjectionKey: InjectionKey<{
106106
tag?: Readonly<Ref<string>>
107+
autoClose?: Readonly<Ref<boolean>>
107108
}> = Symbol('navbar')

0 commit comments

Comments
 (0)