Commit e4f9c3f6 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Fix collapsing behaviour at 1200px

parent 3e42a0c1
...@@ -47,9 +47,9 @@ export default class ContextualSidebar { ...@@ -47,9 +47,9 @@ export default class ContextualSidebar {
// TODO: use the breakpoints from breakpoints.js once they have been updated for bootstrap 4 // TODO: use the breakpoints from breakpoints.js once they have been updated for bootstrap 4
// See related issue and discussion: https://gitlab.com/gitlab-org/gitlab-ce/issues/56745 // See related issue and discussion: https://gitlab.com/gitlab-org/gitlab-ce/issues/56745
static isDesktopBreakpoint = () => bp.windowWidth() > 1200; static isDesktopBreakpoint = () => bp.windowWidth() >= 1200;
static setCollapsedCookie(value) { static setCollapsedCookie(value) {
if (bp.getBreakpointSize() !== 'lg') { if (!ContextualSidebar.isDesktopBreakpoint()) {
return; return;
} }
Cookies.set('sidebar_collapsed', value, { expires: 365 * 10 }); Cookies.set('sidebar_collapsed', value, { expires: 365 * 10 });
...@@ -92,12 +92,11 @@ export default class ContextualSidebar { ...@@ -92,12 +92,11 @@ export default class ContextualSidebar {
render() { render() {
if (!this.$sidebar.length) return; if (!this.$sidebar.length) return;
const breakpoint = bp.getBreakpointSize();
if (!ContextualSidebar.isDesktopBreakpoint()) { if (!ContextualSidebar.isDesktopBreakpoint()) {
this.toggleSidebarNav(false); this.toggleSidebarNav(false);
} else if (breakpoint === 'lg') { } else {
const collapse = parseBoolean(Cookies.get('sidebar_collapsed')); const collapse = parseBoolean(Cookies.get('sidebar_collapsed'));
this.toggleCollapsedSidebar(collapse, false); this.toggleCollapsedSidebar(collapse, true);
} }
} }
} }
...@@ -5,12 +5,9 @@ ...@@ -5,12 +5,9 @@
padding-left: $contextual-sidebar-collapsed-width; padding-left: $contextual-sidebar-collapsed-width;
} }
// NOTE: at 1200px nav sidebar should be in 'desktop mode' (not overlap the content) // At 1200px nav sidebar should not overlap the content
// https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24555#note_134136110 // https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24555#note_134136110
// But setting 'desktop mode' at 1200px will break spec/support/features/reportable_note_shared_examples.rb @include media-breakpoint-up(xl) {
$desktop-nav-sidebar-breakpoint: 1201px;
@media (min-width: $desktop-nav-sidebar-breakpoint) {
padding-left: $contextual-sidebar-width; padding-left: $contextual-sidebar-width;
} }
...@@ -215,7 +212,7 @@ ...@@ -215,7 +212,7 @@
width: 16px; width: 16px;
} }
@media (min-width: map-get($grid-breakpoints, sm)) and (max-width: map-get($grid-breakpoints, xl)) { @media (min-width: map-get($grid-breakpoints, sm)) and (max-width: map-get($grid-breakpoints, xl) - 1px) {
&:not(.sidebar-expanded-mobile) { &:not(.sidebar-expanded-mobile) {
@include collapse-contextual-sidebar; @include collapse-contextual-sidebar;
@include collapse-contextual-sidebar-content; @include collapse-contextual-sidebar-content;
......
...@@ -11,8 +11,6 @@ describe 'Projects > User sees sidebar' do ...@@ -11,8 +11,6 @@ describe 'Projects > User sees sidebar' do
sign_in(user) sign_in(user)
end end
# refactor behaviours into shared behaviours
shared_examples 'has a collapsible mobile nav sidebar' do shared_examples 'has a collapsible mobile nav sidebar' do
it 'has a collapsed desktop nav-sidebar on load' do it 'has a collapsed desktop nav-sidebar on load' do
expect(page).not_to have_content('Collapse sidebar') expect(page).not_to have_content('Collapse sidebar')
...@@ -26,6 +24,21 @@ describe 'Projects > User sees sidebar' do ...@@ -26,6 +24,21 @@ describe 'Projects > User sees sidebar' do
end end
end end
shared_examples 'has a desktop nav sidebar' do
it 'has a expanded desktop nav-sidebar on load' do
expect(page).to have_content('Collapse sidebar')
expect(page).not_to have_selector('.sidebar-collapsed-desktop')
expect(page).not_to have_selector('.sidebar-expanded-mobile')
end
it 'can collapse the nav-sidebar' do
page.find('.nav-sidebar .js-toggle-sidebar').click
expect(page).to have_selector('.sidebar-collapsed-desktop')
expect(page).not_to have_content('Collapse sidebar')
expect(page).not_to have_selector('.sidebar-expanded-mobile')
end
end
context 'with xs size' do context 'with xs size' do
before do before do
resize_screen_xs resize_screen_xs
...@@ -56,9 +69,9 @@ describe 'Projects > User sees sidebar' do ...@@ -56,9 +69,9 @@ describe 'Projects > User sees sidebar' do
it_behaves_like 'has a collapsible mobile nav sidebar' it_behaves_like 'has a collapsible mobile nav sidebar'
end end
context 'at 1200px exactly' do context 'with size 1199px' do
before do before do
resize_window(1200, 800) resize_window(1199, 800)
visit project_path(project) visit project_path(project)
expect(page).to have_selector('.nav-sidebar') expect(page).to have_selector('.nav-sidebar')
end end
...@@ -66,25 +79,14 @@ describe 'Projects > User sees sidebar' do ...@@ -66,25 +79,14 @@ describe 'Projects > User sees sidebar' do
it_behaves_like 'has a collapsible mobile nav sidebar' it_behaves_like 'has a collapsible mobile nav sidebar'
end end
context 'at 1201px exactly' do context 'with a larger screen' do
before do before do
resize_window(1201, 800) resize_window(1200, 800)
visit project_path(project) visit project_path(project)
expect(page).to have_selector('.nav-sidebar') expect(page).to have_selector('.nav-sidebar')
end end
it 'has a expanded desktop nav-sidebar on load' do it_behaves_like 'has a desktop nav sidebar'
expect(page).to have_content('Collapse sidebar')
expect(page).not_to have_selector('.sidebar-collapsed-desktop')
expect(page).not_to have_selector('.sidebar-expanded-mobile')
end
it 'can collapse the nav-sidebar' do
page.find('.nav-sidebar .js-toggle-sidebar').click
expect(page).to have_selector('.sidebar-collapsed-desktop')
expect(page).not_to have_content('Collapse sidebar')
expect(page).not_to have_selector('.sidebar-expanded-mobile')
end
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