Commit 9ef058be authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Updated nav-sidebar to collapse on load

Adds the collapsed mixin to the styling for .nav-sidebar
ensuring the nav-sidebar is collapsed on load via media
queries. Removes the need for an intermediate class to
collapse the sidebar on mobile viewports

Updated toggleCollapsedSidebar to check for desktop breakpoint
parent 1622e863
...@@ -42,8 +42,7 @@ export default class ContextualSidebar { ...@@ -42,8 +42,7 @@ export default class ContextualSidebar {
const breakpoint = bp.getBreakpointSize(); const breakpoint = bp.getBreakpointSize();
if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) { if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) {
const collapsed = !this.$sidebar.hasClass('sidebar-collapsed-mobile'); this.toggleSidebarNav(!this.$sidebar.hasClass('sidebar-expanded-mobile'));
this.toggleMobileCollapsedSidebar(collapsed);
} else if (breakpoint === 'lg') { } else if (breakpoint === 'lg') {
const value = !this.$sidebar.hasClass('sidebar-collapsed-desktop'); const value = !this.$sidebar.hasClass('sidebar-collapsed-desktop');
this.toggleCollapsedSidebar(value, true); this.toggleCollapsedSidebar(value, true);
...@@ -64,25 +63,22 @@ export default class ContextualSidebar { ...@@ -64,25 +63,22 @@ export default class ContextualSidebar {
} }
toggleSidebarNav(show) { toggleSidebarNav(show) {
this.$sidebar.toggleClass('sidebar-expanded-mobile', show); const breakpoint = bp.getBreakpointSize();
this.$overlay.toggleClass('mobile-nav-open', show); const dbp = ContextualSidebar.isDesktopBreakpoint(breakpoint);
this.$sidebar.removeClass('sidebar-collapsed-desktop');
}
toggleMobileCollapsedSidebar(collapsed) { this.$sidebar.toggleClass('sidebar-expanded-mobile', !dbp ? show : false);
this.$sidebar.toggleClass('sidebar-collapsed-mobile', collapsed); this.$overlay.toggleClass('mobile-nav-open', breakpoint === 'xs' ? show : false);
this.$sidebar.toggleClass('sidebar-expanded-mobile', !collapsed);
this.$sidebar.removeClass('sidebar-collapsed-desktop'); this.$sidebar.removeClass('sidebar-collapsed-desktop');
this.$page.toggleClass('page-with-icon-sidebar', true); this.$page.toggleClass('page-with-contextual-sidebar', true);
this.$page.toggleClass('page-with-contextual-sidebar', false);
requestIdleCallback(() => this.toggleSidebarOverflow());
} }
toggleCollapsedSidebar(collapsed, saveCookie) { toggleCollapsedSidebar(collapsed, saveCookie) {
const breakpoint = bp.getBreakpointSize(); const breakpoint = bp.getBreakpointSize();
const dbp = ContextualSidebar.isDesktopBreakpoint(breakpoint);
if (this.$sidebar.length) { if (this.$sidebar.length) {
this.$sidebar.toggleClass('sidebar-collapsed-desktop', collapsed); this.$sidebar.toggleClass('sidebar-collapsed-desktop', collapsed);
this.$sidebar.toggleClass('sidebar-expanded-mobile', !dbp ? !collapsed : false);
this.$page.toggleClass('page-with-icon-sidebar', breakpoint === 'sm' ? true : collapsed); this.$page.toggleClass('page-with-icon-sidebar', breakpoint === 'sm' ? true : collapsed);
this.$page.toggleClass('page-with-contextual-sidebar', true); this.$page.toggleClass('page-with-contextual-sidebar', true);
} }
...@@ -106,9 +102,8 @@ export default class ContextualSidebar { ...@@ -106,9 +102,8 @@ export default class ContextualSidebar {
if (!this.$sidebar.length) return; if (!this.$sidebar.length) return;
const breakpoint = bp.getBreakpointSize(); const breakpoint = bp.getBreakpointSize();
if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) { if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) {
this.toggleMobileCollapsedSidebar(true); this.toggleSidebarNav(false);
} else if (breakpoint === 'lg') { } else if (breakpoint === 'lg') {
const collapse = parseBoolean(Cookies.get('sidebar_collapsed')); const collapse = parseBoolean(Cookies.get('sidebar_collapsed'));
this.toggleCollapsedSidebar(collapse, false); this.toggleCollapsedSidebar(collapse, false);
......
...@@ -71,6 +71,44 @@ ...@@ -71,6 +71,44 @@
} }
} }
@mixin collapse-contextual-sidebar-content {
.context-header {
height: 60px;
width: $contextual-sidebar-collapsed-width;
a {
padding: 10px 4px;
}
}
.sidebar-top-level-items > li {
.sidebar-sub-level-items {
&:not(.flyout-list) {
display: none;
}
}
}
.nav-icon-container {
margin-right: 0;
}
.toggle-sidebar-button {
padding: 16px;
width: $contextual-sidebar-collapsed-width - 1px;
.collapse-text,
.icon-angle-double-left {
display: none;
}
.icon-angle-double-right {
display: block;
margin: 0;
}
}
}
.nav-sidebar { .nav-sidebar {
transition: width $sidebar-transition-duration, left $sidebar-transition-duration; transition: width $sidebar-transition-duration, left $sidebar-transition-duration;
position: fixed; position: fixed;
...@@ -119,13 +157,6 @@ ...@@ -119,13 +157,6 @@
@include collapse-contextual-sidebar; @include collapse-contextual-sidebar;
} }
&.sidebar-collapsed-mobile {
// md = 768, xl = 1200px
@media (min-width: map-get($grid-breakpoints, sm)) and (max-width: map-get($grid-breakpoints, xl)) {
@include collapse-contextual-sidebar;
}
}
&.sidebar-expanded-mobile { &.sidebar-expanded-mobile {
left: 0; left: 0;
} }
...@@ -178,6 +209,13 @@ ...@@ -178,6 +209,13 @@
height: 16px; height: 16px;
width: 16px; width: 16px;
} }
&:not(.sidebar-expanded-mobile) {
@media (min-width: map-get($grid-breakpoints, sm)) and (max-width: map-get($grid-breakpoints, xl)) {
@include collapse-contextual-sidebar;
@include collapse-contextual-sidebar-content;
}
}
} }
.nav-sidebar-inner-scroll { .nav-sidebar-inner-scroll {
...@@ -368,54 +406,10 @@ ...@@ -368,54 +406,10 @@
overflow: hidden; overflow: hidden;
} }
@mixin collapse-contextual-sidebar-content {
.context-header {
height: 60px;
width: $contextual-sidebar-collapsed-width;
a {
padding: 10px 4px;
}
}
.sidebar-top-level-items > li {
.sidebar-sub-level-items {
&:not(.flyout-list) {
display: none;
}
}
}
.nav-icon-container {
margin-right: 0;
}
.toggle-sidebar-button {
padding: 16px;
width: $contextual-sidebar-collapsed-width - 1px;
.collapse-text,
.icon-angle-double-left {
display: none;
}
.icon-angle-double-right {
display: block;
margin: 0;
}
}
}
.sidebar-collapsed-desktop { .sidebar-collapsed-desktop {
@include collapse-contextual-sidebar-content; @include collapse-contextual-sidebar-content;
} }
.sidebar-collapsed-mobile {
@media (min-width: map-get($grid-breakpoints, sm)) and (max-width: map-get($grid-breakpoints, xl)) {
@include collapse-contextual-sidebar-content;
}
}
.fly-out-top-item { .fly-out-top-item {
> a { > a {
display: flex; display: flex;
......
.nav-sidebar.qa-admin-sidebar.sidebar-collapsed-mobile{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar.qa-admin-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
.nav-sidebar-inner-scroll .nav-sidebar-inner-scroll
.context-header .context-header
= link_to admin_root_path, title: _('Admin Overview') do = link_to admin_root_path, title: _('Admin Overview') do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- merge_requests_count = group_merge_requests_count(state: 'opened') - merge_requests_count = group_merge_requests_count(state: 'opened')
- issues_sub_menu_items = ['groups#issues', 'labels#index', 'milestones#index', 'boards#index', 'boards#show'] - issues_sub_menu_items = ['groups#issues', 'labels#index', 'milestones#index', 'boards#index', 'boards#show']
.nav-sidebar.sidebar-collapsed-mobile{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
.nav-sidebar-inner-scroll .nav-sidebar-inner-scroll
.context-header .context-header
= link_to group_path(@group), title: @group.name do = link_to group_path(@group), title: @group.name do
......
.nav-sidebar.sidebar-collapsed-mobile{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
.nav-sidebar-inner-scroll .nav-sidebar-inner-scroll
.context-header .context-header
= link_to instance_statistics_root_path, title: _('Instance Statistics') do = link_to instance_statistics_root_path, title: _('Instance Statistics') do
......
.nav-sidebar.sidebar-collapsed-mobile{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
.nav-sidebar-inner-scroll .nav-sidebar-inner-scroll
.context-header .context-header
= link_to profile_path, title: _('Profile Settings') do = link_to profile_path, title: _('Profile Settings') do
......
.nav-sidebar.sidebar-collapsed-mobile{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
.nav-sidebar-inner-scroll .nav-sidebar-inner-scroll
- can_edit = can?(current_user, :admin_project, @project) - can_edit = can?(current_user, :admin_project, @project)
.context-header .context-header
......
...@@ -4,6 +4,8 @@ shared_examples 'has nav sidebar' do ...@@ -4,6 +4,8 @@ shared_examples 'has nav sidebar' do
it 'has collapsed nav sidebar on mobile' do it 'has collapsed nav sidebar on mobile' do
render render
expect(rendered).to have_selector('.nav-sidebar.sidebar-collapsed-mobile') expect(rendered).to have_selector('.nav-sidebar')
expect(rendered).not_to have_selector('.sidebar-collapsed-desktop')
expect(rendered).not_to have_selector('.sidebar-expanded-mobile')
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment