Skip to content
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

Tweak navbar overflow logic to catch selected items #11778

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions kolibri/core/assets/src/views/HorizontalNavBarWithOverflowMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

<script>

import isUndefined from 'lodash/isUndefined';
import Navbar from 'kolibri.coreVue.components.Navbar';
import NavbarLink from 'kolibri.coreVue.components.NavbarLink';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
Expand Down Expand Up @@ -91,29 +92,33 @@
return this.$themeTokens.textInverted;
},
overflowMenuLinks() {
return (this.mounted && this.windowWidth
? this.allLinks.filter((link, index) => {
const navLink = this.$refs.navLinks[index].$el;
const navLinkTop = navLink.offsetTop;

const containerTop = this.$refs.navContainer.offsetTop;
const containerBottom = containerTop + this.$refs.navContainer.clientHeight;
// Accounts for changes in container height that is not matched by height of buttons
// as mobile styles are applied to the nav bar
const heightDifference = Math.abs(
this.$refs.navContainer.clientHeight - navLink.clientHeight
);
return navLinkTop + heightDifference >= containerBottom;
})
: []
).map(l => ({ label: l.title, value: l.link, icon: l.icon }));
if (!this.mounted || isUndefined(this.windowWidth)) {
return [];
}
const containerTop = this.$refs.navContainer.offsetTop;
const containerHeight = this.$refs.navContainer.clientHeight;
return this.allLinks
.filter((link, index) => {
const navLink = this.$refs.navLinks[index].$el;
// Calculate navLinkTop relative to the navContainer by subtracting the container's top
const navLinkTop = navLink.offsetTop - containerTop;
const navLinkHeight = navLink.clientHeight;
const navLinkBottom = navLinkTop + navLinkHeight;
// Check if the navLink is _not_ completely bounded the container, top and bottom.
return !(navLinkTop >= 0 && navLinkBottom <= containerHeight);
})
.map(l => ({ label: l.title, value: l.link, icon: l.icon }));
},
},
mounted() {
this.mounted = true;
},
methods: {
handleSelect(option) {
// Prevent redundant navigation
if (this.$route.name === option.value.name) {
return;
}
this.$router.push(this.$router.getRoute(option.value.name));
},
},
Expand Down