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

close mobile navigator, when clicking on any navigation item #364

Open
wants to merge 3 commits into
base: main
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
1 change: 1 addition & 0 deletions src/components/Navigator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
:allow-hiding="allowHiding"
:navigator-references="navigatorReferences"
@close="$emit('close')"
@navigate="$emit('navigate', $event)"
>
<template #filter><slot name="filter" /></template>
</NavigatorCard>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Navigator/NavigatorCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,8 @@ export default {
* that points to another technology.
*/
handleNavigationChange(uid) {
// force-close the navigator on mobile
this.$emit('navigate', uid);
// if the path is outside of this technology tree, dont store the uid
if (this.childrenMap[uid].path.startsWith(this.technologyPath)) {
this.setActiveUID(uid);
Expand Down
11 changes: 11 additions & 0 deletions src/views/DocumentationTopic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
:scrollLockID="scrollLockID"
:render-filter-on-top="breakpoint !== BreakpointName.large"
@close="handleToggleSidenav(breakpoint)"
@navigate="handleNavigate(breakpoint)"
>
<template v-if="enableQuickNavigation" #filter>
<QuickNavigationButton @click.native="openQuickNavigationModal" />
Expand Down Expand Up @@ -314,6 +315,15 @@ export default {
this.openQuickNavigationModal();
event.preventDefault();
},
/**
* Closes the mobile nav, on each navigation. This is generally done when the route changes,
* but we also want to do that when any link is slicked in the navigator.
* @param {string} breakpoint
*/
handleNavigate(breakpoint) {
if (breakpoint === BreakpointName.large) return;
this.toggleMobileSidenav(false);
},
},
mounted() {
this.$bridge.on('contentUpdate', this.handleContentUpdateFromBridge);
Expand Down Expand Up @@ -394,6 +404,7 @@ export default {
.generic-modal {
overflow-y: overlay;
}

.modal-fullscreen > .container {
background-color: transparent;
height: fit-content;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/components/Navigator/NavigatorCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,8 @@ describe('NavigatorCard', () => {
expect(getChildPositionInScroller).toHaveBeenCalledTimes(2);
expect(DynamicScrollerStub.methods.scrollToItem).toHaveBeenCalledTimes(1);
expect(DynamicScrollerStub.methods.scrollToItem).toHaveBeenLastCalledWith(2); // 3-rd item
// assert `navigate` event was emitted
expect(wrapper.emitted('navigate')).toHaveLength(1);
// now simulate the router change
wrapper.setProps({ activePath: [root0.path, root0Child1.path] });
await flushPromises();
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/views/DocumentationTopic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,36 @@ describe('DocumentationTopic', () => {
expect(storage.set).toHaveBeenCalledTimes(0);
});

it('handles the `@navigate` event, only on Mobile breakpoints', async () => {
wrapper.setData({
topicData: {
...topicData,
schemaVersion: schemaVersionWithSidebar,
},
});
await flushPromises();
const navigator = wrapper.find(Navigator);
const nav = wrapper.find(Nav);
// toggle the navigator from the Nav component, in Small breakpoint
nav.vm.$emit('toggle-sidenav', BreakpointName.small);
const sidebar = wrapper.find(AdjustableSidebarWidth);
// set the breakpoint to small on the sidebar
sidebar.vm.breakpoint = BreakpointName.small;
expect(sidebar.props('shownOnMobile')).toBe(true);
await flushPromises();
navigator.vm.$emit('navigate');
expect(sidebar.props('shownOnMobile')).toBe(false);
// Test that Medium works with the same set of props/events
// toggle the navigator from the Nav component, in Medium breakpoint
nav.vm.$emit('toggle-sidenav', BreakpointName.medium);
expect(sidebar.props('shownOnMobile')).toBe(true);
await flushPromises();
sidebar.vm.breakpoint = BreakpointName.medium;
navigator.vm.$emit('navigate');
expect(sidebar.props('shownOnMobile')).toBe(false);
expect(storage.set).toHaveBeenCalledTimes(0);
});

it('handles the `@close`, on Navigator, for `Large` breakpoints', async () => {
wrapper.setData({
topicData: {
Expand Down