Skip to content

Commit f42178e

Browse files
committed
fix: various tags styles and props
1 parent 998bc44 commit f42178e

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
<script setup lang="ts">
1717
// import type {BNavItemProps} from '../types/components'
18-
import {computed} from 'vue'
19-
import {RouteLocationRaw} from 'vue-router'
2018
import BLink from '../BLink/BLink.vue'
19+
import {computed} from 'vue'
20+
import type {RouteLocationRaw} from 'vue-router'
2121
2222
interface BNavItemProps {
2323
active?: boolean
Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
<template>
2-
<nav :class="classes">
3-
<div class="container-fluid">
4-
<slot></slot>
5-
</div>
6-
</nav>
2+
<component :is="tag" class="navbar" :class="classes" :role="computedRole">
3+
<slot />
4+
</component>
75
</template>
86

97
<script setup lang="ts">
108
import {computed} from 'vue'
11-
import {ColorVariant, NavbarBreakpoint} from '../../types/index'
9+
import type {ColorVariant, NavbarBreakpoint} from '../../types'
1210
1311
interface Props {
1412
variant?: ColorVariant
1513
toggleable?: NavbarBreakpoint
14+
tag?: string
1615
}
1716
1817
const props = withDefaults(defineProps<Props>(), {
1918
variant: 'light',
2019
toggleable: false, // navbar never collapses
20+
tag: 'nav',
2121
})
2222
23-
const classes = computed(() => {
24-
const result: {[key: string]: boolean} = {
25-
'navbar': true,
26-
'navbar-light': props.variant === 'light',
27-
'navbar-dark': props.variant !== 'light',
28-
'navbar-expand': props.toggleable === false, // for navbars that never collapse
29-
}
23+
const computedRole = computed<null | 'navigation'>(() =>
24+
props.tag === 'nav' ? null : 'navigation'
25+
)
3026
31-
if (typeof props.toggleable === 'string') {
32-
result[`navbar-expand-${props.toggleable}`] = true
33-
}
34-
35-
result[`bg-${props.variant}`] = true
36-
37-
return result
38-
})
27+
const classes = computed(() => ({
28+
'navbar-light': props.variant === 'light',
29+
'navbar-dark': props.variant !== 'light',
30+
'navbar-expand': props.toggleable === false, // for navbars that never collapse
31+
[`bg-${props.variant}`]: props.variant,
32+
[`navbar-expand-${props.toggleable}`]: typeof props.toggleable === 'string',
33+
}))
3934
</script>
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<template>
2-
<BLink v-if="href || to" :href="href" :to="to">
3-
<slot></slot>
4-
</BLink>
5-
<div v-else>
6-
<slot></slot>
7-
</div>
2+
<component :is="computedTag" v-bind="attrs">
3+
<slot />
4+
</component>
85
</template>
96

107
<script setup lang="ts">
11-
import BLink from '../BLink/BLink.vue'
12-
import {RouteLocationRaw} from 'vue-router'
8+
import {computed} from 'vue'
9+
import type {RouteLocationRaw} from 'vue-router'
1310
1411
interface Props {
15-
tag?: 'div'
12+
tag?: string
1613
href?: string
1714
to?: RouteLocationRaw
1815
}
1916
20-
defineProps<Props>()
17+
const props = withDefaults(defineProps<Props>(), {
18+
tag: 'div',
19+
})
20+
21+
const computedTag = computed<string>(() => (props.to ? 'b-link' : props.href ? 'a' : props.tag))
22+
23+
const attrs = computed(() => ({
24+
href: props.href,
25+
to: props.to,
26+
}))
2127
</script>

packages/bootstrap-vue-3/src/components/BNav/BNavbarNav.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
<slot></slot>
44
</ul>
55
</template>
6-
7-
<script setup lang="ts"></script>

packages/bootstrap-vue-3/src/components/BNav/BNavbarToggle.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,31 @@
88
import {ref} from 'vue'
99
1010
interface Props {
11-
target: string
11+
target?: string
12+
disabled?: boolean // TODO ensure that if the button is disabled that it doesn't collapse
1213
}
1314
14-
const props = defineProps<Props>()
15+
const props = withDefaults(defineProps<Props>(), {
16+
disabled: false,
17+
})
18+
19+
interface Emits {
20+
(e: 'click'): void
21+
}
22+
23+
const emit = defineEmits<Emits>()
1524
1625
const classes = ref({
1726
'navbar-toggler': true,
1827
'collapsed': true,
1928
})
2029
2130
const onButtonClicked = () => {
31+
emit('click')
32+
2233
classes.value.collapsed = !classes.value.collapsed
2334
24-
const el = document.getElementById(props.target)
35+
const el = document.getElementById(props.target) // Handle this
2536
el?.classList.toggle('show')
2637
}
2738
</script>

0 commit comments

Comments
 (0)