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

Commit 683c51d

Browse files
committed
feat(BNavItemDropdown): adds open, close and toggle methods.
1 parent 464c172 commit 683c51d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ defineSlots<{
8989
'button-content'?: (props: Record<string, never>) => any
9090
}>()
9191
92-
const modelValue = useVModel(props, 'modelValue', emit)
92+
const modelValue = useVModel(props, 'modelValue', emit, {passive: true})
9393
9494
const modelValueBoolean = useBooleanish(modelValue)
9595
@@ -100,4 +100,20 @@ const dropdownValue = computed({
100100
},
101101
})
102102
const usableProps = computed(() => omit(props, ['modelValue'] as const))
103+
104+
const close = () => {
105+
modelValue.value = false
106+
}
107+
const open = () => {
108+
modelValue.value = true
109+
}
110+
const toggle = () => {
111+
modelValue.value = !modelValueBoolean.value
112+
}
113+
114+
defineExpose({
115+
close,
116+
open,
117+
toggle,
118+
})
103119
</script>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {enableAutoUnmount, mount} from '@vue/test-utils'
22
import {afterEach, describe, expect, it} from 'vitest'
33
import BNavItemDropdown from './BNavItemDropdown.vue'
4+
import BButton from '../BButton/BButton.vue'
45
import BDropdown from '../BDropdown/BDropdown.vue'
56

67
describe('nav-item-dropdown', () => {
@@ -22,5 +23,29 @@ describe('nav-item-dropdown', () => {
2223
expect($bdropdown.exists()).toBe(true)
2324
})
2425

26+
it('is opened if open called', async () => {
27+
const wrapper = mount(BNavItemDropdown)
28+
const $bbutton = wrapper.findComponent(BButton)
29+
await wrapper.vm.open()
30+
expect($bbutton.classes()).toContain('show')
31+
})
32+
33+
it('is closed if close called', async () => {
34+
const wrapper = mount(BNavItemDropdown)
35+
const $bbutton = wrapper.findComponent(BButton)
36+
await wrapper.vm.open()
37+
await wrapper.vm.close()
38+
expect($bbutton.classes()).not.toContain('show')
39+
})
40+
41+
it('is toggled if toggle called', async () => {
42+
const wrapper = mount(BNavItemDropdown)
43+
const $bbutton = wrapper.findComponent(BButton)
44+
await wrapper.vm.toggle()
45+
expect($bbutton.classes()).toContain('show')
46+
await wrapper.vm.toggle()
47+
expect($bbutton.classes()).not.toContain('show')
48+
})
49+
2550
// There are more tests here, but the component seems broken
2651
})

0 commit comments

Comments
 (0)