-
Notifications
You must be signed in to change notification settings - Fork 141
Make navigation menus accessible on smaller screens #1445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,39 @@ | ||
| <template> | ||
| <nav ref="navbar" :class="['navbar', 'navbar-expand-md', themeOptions, addClass, fixedOptions]"> | ||
| <div class="container-fluid"> | ||
| <div class="navbar-brand"> | ||
| <slot name="brand"></slot> | ||
| </div> | ||
| <button | ||
| v-if="!slots.collapse" | ||
| class="navbar-toggler" | ||
| type="button" | ||
| aria-expanded="false" | ||
| aria-label="Toggle navigation" | ||
| @click="toggleCollapse" | ||
| > | ||
| <span class="navbar-toggler-icon"></span> | ||
| <slot name="collapse"></slot> | ||
| </button> | ||
| <div> | ||
| <nav ref="navbar" :class="['navbar', 'navbar-expand-md', themeOptions, addClass, fixedOptions]"> | ||
| <div class="container-fluid"> | ||
| <div class="navbar-brand"> | ||
| <slot name="brand"></slot> | ||
| </div> | ||
| <button | ||
| v-if="!slots.collapse" | ||
| class="navbar-toggler" | ||
| type="button" | ||
| aria-expanded="false" | ||
| aria-label="Toggle navigation" | ||
| @click="toggleCollapse" | ||
| > | ||
| <span class="navbar-toggler-icon"></span> | ||
| <slot name="collapse"></slot> | ||
| </button> | ||
|
|
||
| <div :class="['navbar-collapse',{collapse:collapsed}]"> | ||
| <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> | ||
| <slot></slot> | ||
| </ul> | ||
| <ul v-if="slots.right" class="navbar-nav navbar-right"> | ||
| <slot name="right"></slot> | ||
| </ul> | ||
| <div :class="['navbar-collapse',{collapse:collapsed}]"> | ||
| <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> | ||
| <slot></slot> | ||
| </ul> | ||
| <ul v-if="slots.right" class="navbar-nav navbar-right"> | ||
| <slot name="right"></slot> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| <div ref="lowerNavbar" v-show="isLowerNavbarShowing" class="lower-navbar-container"> | ||
| <slot name="lower-navbar"> | ||
| <site-nav-button /> | ||
| <page-nav-button /> | ||
| </slot> | ||
| </div> | ||
| </nav> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
|
|
@@ -52,11 +60,17 @@ export default { | |
| default: 'sibling-or-child', | ||
| }, | ||
| }, | ||
| provide() { | ||
| return { | ||
| toggleLowerNavbar: this.toggleLowerNavbar, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about just a prop? since they're in the same compilation scope
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm just to clarify, if this is passed to then it won't be passed down to the component in this case?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }; | ||
| }, | ||
| data() { | ||
| return { | ||
| id: 'bs-example-navbar-collapse-1', | ||
| collapsed: true, | ||
| styles: {}, | ||
| isLowerNavbarShowing: false, | ||
| }; | ||
| }, | ||
| computed: { | ||
|
|
@@ -198,6 +212,13 @@ export default { | |
| } | ||
| } | ||
| }, | ||
| toggleLowerNavbar() { | ||
| if (this.$refs.lowerNavbar.childElementCount > 0) { | ||
| this.isLowerNavbarShowing = true; | ||
| } else { | ||
| this.isLowerNavbarShowing = false; | ||
| } | ||
| }, | ||
| }, | ||
| created() { | ||
| this._navbar = true; | ||
|
|
@@ -228,10 +249,14 @@ export default { | |
|
|
||
| // highlight current nav link | ||
| this.highlightLink(window.location.href); | ||
|
|
||
| this.toggleLowerNavbar(); | ||
| $(window).on('resize', this.toggleLowerNavbar); | ||
| }, | ||
| beforeDestroy() { | ||
| $('.dropdown', this.$el).off('click').offBlur(); | ||
| if (this.slots.collapse) $('[data-toggle="collapse"]', this.$el).off('click'); | ||
| $(window).off('resize', this.toggleLowerNavbar); | ||
| }, | ||
| }; | ||
| </script> | ||
|
|
@@ -255,4 +280,12 @@ export default { | |
| color: #fff !important; | ||
| background: #007bff; | ||
| } | ||
|
|
||
| .lower-navbar-container { | ||
| background-color: #fff; | ||
| border-bottom: 1px solid #c1c1c1; | ||
| height: 50px; | ||
| width: 100%; | ||
| position: relative; | ||
| } | ||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <template> | ||
| <div> | ||
| <span | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: pull the icon upward using scoped slots, so the component specific styles can be moved up there not sure if it would end up more verbose though 😐
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shifted this up. Doesn't look too verbose :) |
||
| :class="[{ 'nav-menu-close-icon': show }]" | ||
| @click="toggleNavMenu" | ||
| > | ||
| <slot name="navMenuIcon"></slot> | ||
| </span> | ||
| <div ref="navMenuContainer" :class="['nav-menu', { 'nav-menu-open': show }]"> | ||
| <retriever | ||
| v-if="hasIdentifier" | ||
| :src="src" | ||
| :fragment="fragment" | ||
| @src-loaded="navMenuLoaded" | ||
| /> | ||
| <div v-else ref="navigationMenu"></div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import retriever from './Retriever.vue'; | ||
| import $ from './utils/NodeList'; | ||
| import { publish, subscribe } from './utils/pubsub'; | ||
|
|
||
| export default { | ||
| components: { | ||
| retriever, | ||
| }, | ||
| props: { | ||
| type: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| src: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| fragment: { | ||
| type: String, | ||
| default: null, | ||
| }, | ||
| hasIdentifier: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| getNavMenuContent: { | ||
| type: Function, | ||
| default: () => {}, | ||
| }, | ||
| }, | ||
| inject: ['toggleLowerNavbar'], | ||
| data() { | ||
| return { | ||
| show: false, | ||
| }; | ||
| }, | ||
| methods: { | ||
| toggleNavMenu() { | ||
| if (!this.show) { publish('closeOverlay'); } | ||
| this.show = !this.show; | ||
| }, | ||
| navMenuLoaded() { | ||
| this.toggleLowerNavbar(); | ||
| $(this.$refs.navMenuContainer).find('a').on('click', () => { | ||
| this.toggleNavMenu(); | ||
| }); | ||
| }, | ||
| }, | ||
| mounted() { | ||
| const navMenu = this.$refs.navigationMenu; | ||
| const buildNav = (navMenuItems) => { | ||
| if (!navMenuItems) { return; } | ||
| for (let i = 0; i < navMenuItems.childNodes.length; i += 1) { | ||
| navMenu.appendChild(navMenuItems.childNodes[i].cloneNode(true)); | ||
| } | ||
| this.navMenuLoaded(); | ||
| }; | ||
|
|
||
| if (!this.hasIdentifier) { | ||
| buildNav(this.getNavMenuContent()); | ||
| } | ||
|
|
||
| subscribe('closeOverlay', () => { this.show = false; }); | ||
| }, | ||
| }; | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .nav-menu { | ||
| display: none; | ||
| padding: 50px 10px 20px; | ||
| position: fixed; | ||
| overflow-y: auto; | ||
| z-index: -1; | ||
| } | ||
|
|
||
| .nav-menu-close-icon > span::before { | ||
| content: "\e014" !important; | ||
| } | ||
|
|
||
| .nav-menu-open { | ||
| display: block !important; | ||
| width: 100% !important; | ||
| background: #fff; | ||
| height: 100%; | ||
| clear: both; | ||
| } | ||
| </style> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more minor styling issue: (navbar example in ug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed :)