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

Fix top navigation positioning when window is resized #13007

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions packages/kolibri/components/pages/AppBarPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@
},
mixins: [commonCoreStrings],
setup() {
const { windowBreakpoint, windowIsSmall } = useKResponsiveWindow();
const { windowIsSmall } = useKResponsiveWindow();
const { isAppContext } = useUser();
return {
windowBreakpoint,
windowIsSmall,
isAppContext,
};
Expand Down Expand Up @@ -146,20 +145,17 @@
return show;
},
},
watch: {
windowBreakpoint() {
//Update the the app bar height at every breakpoint
this.appBarHeight = this.$refs.appBar.$el.scrollHeight || 0;
},
beforeUpdate() {
// Update appBarHeight after AppBar is rerendered and updated
this.appBarHeight = this.$refs.appBar.$el.scrollHeight || 0;
},
mounted() {
this.$nextTick(() => {
this.appBarHeight = this.$refs.appBar.$el.scrollHeight || 0;
});
this.addScrollListener();
window.addEventListener('resize', this.handleWindowResize);
},
beforeUnmount() {
beforeDestroy() {
this.removeScrollListener();
window.removeEventListener('resize', this.handleWindowResize);
},
methods: {
addScrollListener() {
Expand Down Expand Up @@ -190,6 +186,10 @@
this.throttledHandleScroll = null;
}
},
handleWindowResize() {
// Update the app bar height when window is resized
this.appBarHeight = this.$refs.appBar.$el.offsetHeight || 0;
},
},
};

Expand Down
22 changes: 18 additions & 4 deletions packages/kolibri/components/pages/AppBarPage/internal/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</template>

<template
v-if="showNavigation && windowIsLarge"
v-if="showNavigation && showTopNavBar"
#navigation
>
<slot name="sub-nav">
Expand Down Expand Up @@ -116,7 +116,7 @@
</KToolbar>
</header>
<div
v-if="showNavigation && !windowIsLarge && !showAppNavView"
v-show="showNavigation && !showAppNavView && !showTopNavBar"
class="subpage-nav"
>
<slot name="sub-nav">
Expand Down Expand Up @@ -160,7 +160,7 @@
setup() {
const store = getCurrentInstance().proxy.$store;
const $route = computed(() => store.state.route);
const { windowIsLarge, windowIsSmall } = useKResponsiveWindow();
const { windowIsSmall, windowBreakpoint } = useKResponsiveWindow();
const { topBarHeight, navItems } = useNav();
const { isLearner, isUserLoggedIn, username, full_name } = useUser();
const { totalPoints, fetchPoints } = useTotalProgress();
Expand All @@ -178,8 +178,8 @@
});
return {
themeConfig,
windowIsLarge,
windowIsSmall,
windowBreakpoint,
topBarHeight,
links,
isUserLoggedIn,
Expand Down Expand Up @@ -207,6 +207,8 @@
data() {
return {
pointsDisplayed: false,
breakpointLimit: 4,
showTopNavBar: false,
};
},
computed: {
Expand All @@ -222,9 +224,18 @@
window.addEventListener('click', this.handleWindowClick);
window.addEventListener('keydown', this.handlePopoverByKeyboard, true);
},
beforeUpdate() {
// Essential for title updates after data finishes loading
this.breakpointLimit = this.title && this.title.length >= 20 ? 4 : 3;
this.showTopNavBar = this.windowBreakpoint > this.breakpointLimit;
},
beforeDestroy() {
window.removeEventListener('click', this.handleWindowClick);
window.removeEventListener('keydown', this.handlePopoverByKeyboard, true);
window.removeEventListener('resize', this.handleWindowResize);
},
mounted() {
window.addEventListener('resize', this.handleWindowResize);
},
methods: {
handleWindowClick(event) {
Expand All @@ -246,6 +257,9 @@
this.pointsDisplayed = false;
}
},
handleWindowResize() {
this.showTopNavBar = this.windowBreakpoint >= this.breakpointLimit;
},
truncateText(value, maxLength) {
if (value && value.length > maxLength) {
return value.substring(0, maxLength) + '...';
Expand Down
Loading