Skip to content

Commit 7c3737c

Browse files
authored
fix(navbar): Support always expanded navbar (fixes #2209) (#2210)
* fix(navbar): Support always expanded navbar (fixes #2209) Support always expanded navbar by setting prop `toggleable` to `false` To set a breakpoint where collapsing happens, set `toggleable` to the breakpoint (`sm|md|lg|xl`) Fixes #2209 * Update README.md * Rename navbar.spec.js to navbar-dropdown.spec.js
1 parent 7a860ee commit 7c3737c

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/components/navbar/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Input groups work as well:
260260
```
261261

262262
### `<b-navbar-toggle>` and `<b-collapse is-nav>`
263-
Navbars are responsive by default, but you can easily modify them to change that. Responsive
263+
Navbars are not responsive by default, but you can easily modify them to change that. Responsive
264264
behavior depends on our `<b-collapse>` component.
265265

266266
Wrap `<b-navbar-nav>` components in a `<b-collapse is-nav>` (**remember to set the `is-nav`
@@ -271,9 +271,9 @@ Use the `<b-navbar-toggle>` component to control the collapse component, and set
271271
`target` prop of `<b-navbar-toggle>` to the `id` of `<b-collapse>`.
272272

273273
Set the `toggleable` prop on `<b-navbar>` to the desired breakpoint you would like content
274-
to automatically collapse at. Possible `toggleable`values are `sm`, `md`, and `lg`. Setting
275-
`toggleable` to `true` (or with no explicit value) will set the breakpoint to `sm`, while
276-
setting it to `false` will disable collapsing.
274+
to automatically expand at. Possible `toggleable` values are `sm`, `md`, `lg` and `xl`. Setting
275+
`toggleable` to `true` (or with no explicit value) will set the navbar to be always collapsed, while
276+
setting it to `false` (the default) will disable collapsing (always expanded).
277277

278278
`<b-navbar-toggle>` components are left-aligned by default, but should they follow a sibling
279279
element like `<b-navbar-brand>`, they’ll automatically be aligned to the far right. Reversing
@@ -283,6 +283,10 @@ See the first example on this page for reference, and also refer to
283283
[`<b-collapse>`](/docs/components/collapse) for details on the collapse component.
284284

285285

286+
## Printing
287+
Navbars are hidden by deafult when printing. Force them to be printed by setting the `print` prop.
288+
289+
286290
## See also
287291
Also see [`<b-nav>`](/docs/components/nav) for additional components and sub-component aliases.
288292

File renamed without changes.

src/components/navbar/navbar.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,43 @@ export const props = {
1616
type: [Boolean, String],
1717
default: false
1818
},
19-
toggleBreakpoint: {
20-
// Deprecated. Set toggleable to a string breakpoint
21-
type: String,
22-
default: null
23-
},
2419
fixed: {
2520
type: String
2621
},
2722
sticky: {
2823
type: Boolean,
2924
default: false
25+
},
26+
print: {
27+
type: Boolean,
28+
default: false
3029
}
3130
}
3231

3332
export default {
3433
functional: true,
3534
props,
3635
render (h, { props, data, children }) {
37-
let breakpoint = props.toggleBreakpoint || (props.toggleable === true ? 'sm' : props.toggleable) || 'sm'
36+
let breakpoint = ''
37+
if (props.toggleable && typeof props.toggleable === 'string' && props.toggleable !== 'xs') {
38+
breakpoint = `navbar-expand-${props.toggleable}`
39+
} else if (props.toggleable === false) {
40+
breakpoint = 'navbar-expand'
41+
}
3842
return h(
3943
props.tag,
4044
mergeData(data, {
4145
staticClass: 'navbar',
4246
class: {
47+
'd-print': props.print,
48+
'sticky-top': props.sticky,
4349
[`navbar-${props.type}`]: Boolean(props.type),
4450
[`bg-${props.variant}`]: Boolean(props.variant),
4551
[`fixed-${props.fixed}`]: Boolean(props.fixed),
46-
'sticky-top': props.sticky,
47-
[`navbar-expand-${breakpoint}`]: props.toggleable !== false
52+
[`${breakpoint}`]: Boolean(breakpoint)
53+
},
54+
attrs: {
55+
role: props.tag === 'nav' ? null : 'navigation'
4856
}
4957
}),
5058
children

0 commit comments

Comments
 (0)