Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
45c750b2
Commit
45c750b2
authored
Jun 10, 2021
by
Paul Slaughter
Committed by
Ezekiel Kigbo
Jun 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix race condition of `menu-expanded` and top nav
parent
fa8f391c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
12 deletions
+42
-12
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+3
-0
app/assets/javascripts/nav/components/responsive_app.vue
app/assets/javascripts/nav/components/responsive_app.vue
+10
-4
app/assets/javascripts/nav/utils/has_menu_expanded.js
app/assets/javascripts/nav/utils/has_menu_expanded.js
+5
-0
app/assets/javascripts/nav/utils/index.js
app/assets/javascripts/nav/utils/index.js
+2
-0
spec/frontend/nav/components/responsive_app_spec.js
spec/frontend/nav/components/responsive_app_spec.js
+22
-8
No files found.
app/assets/javascripts/main.js
View file @
45c750b2
...
...
@@ -203,6 +203,9 @@ document.addEventListener('DOMContentLoaded', () => {
});
$
(
'
.navbar-toggler
'
).
on
(
'
click
'
,
()
=>
{
// The order is important. The `menu-expanded` is used as a source of truth for now.
// This can be simplified when the :combined_menu feature flag is removed.
// https://gitlab.com/gitlab-org/gitlab/-/issues/333180
$
(
'
.header-content
'
).
toggleClass
(
'
menu-expanded
'
);
navEventHub
.
$emit
(
EVENT_RESPONSIVE_TOGGLE
);
});
...
...
app/assets/javascripts/nav/components/responsive_app.vue
View file @
45c750b2
...
...
@@ -3,7 +3,7 @@ import { FREQUENT_ITEMS_PROJECTS, FREQUENT_ITEMS_GROUPS } from '~/frequent_items
import
{
BV_DROPDOWN_SHOW
,
BV_DROPDOWN_HIDE
}
from
'
~/lib/utils/constants
'
;
import
KeepAliveSlots
from
'
~/vue_shared/components/keep_alive_slots.vue
'
;
import
eventHub
,
{
EVENT_RESPONSIVE_TOGGLE
}
from
'
../event_hub
'
;
import
{
resetMenuItemsActive
}
from
'
../utils/reset_menu_items_active
'
;
import
{
resetMenuItemsActive
,
hasMenuExpanded
}
from
'
../utils
'
;
import
ResponsiveHeader
from
'
./responsive_header.vue
'
;
import
ResponsiveHome
from
'
./responsive_home.vue
'
;
import
TopNavContainerView
from
'
./top_nav_container_view.vue
'
;
...
...
@@ -33,9 +33,11 @@ export default {
},
},
created
()
{
eventHub
.
$on
(
EVENT_RESPONSIVE_TOGGLE
,
this
.
onToggle
);
eventHub
.
$on
(
EVENT_RESPONSIVE_TOGGLE
,
this
.
updateResponsiveOpen
);
this
.
$root
.
$on
(
BV_DROPDOWN_SHOW
,
this
.
showMobileOverlay
);
this
.
$root
.
$on
(
BV_DROPDOWN_HIDE
,
this
.
hideMobileOverlay
);
this
.
updateResponsiveOpen
();
},
beforeDestroy
()
{
eventHub
.
$off
(
EVENT_RESPONSIVE_TOGGLE
,
this
.
onToggle
);
...
...
@@ -43,8 +45,12 @@ export default {
this
.
$root
.
$off
(
BV_DROPDOWN_HIDE
,
this
.
hideMobileOverlay
);
},
methods
:
{
onToggle
()
{
document
.
body
.
classList
.
toggle
(
'
top-nav-responsive-open
'
);
updateResponsiveOpen
()
{
if
(
hasMenuExpanded
())
{
document
.
body
.
classList
.
add
(
'
top-nav-responsive-open
'
);
}
else
{
document
.
body
.
classList
.
remove
(
'
top-nav-responsive-open
'
);
}
},
onMenuItemClick
({
view
})
{
if
(
view
)
{
...
...
app/assets/javascripts/nav/utils/has_menu_expanded.js
0 → 100644
View file @
45c750b2
export
const
hasMenuExpanded
=
()
=>
{
const
header
=
document
.
querySelector
(
'
.header-content
'
);
return
Boolean
(
header
?.
classList
.
contains
(
'
menu-expanded
'
));
};
app/assets/javascripts/nav/utils/index.js
0 → 100644
View file @
45c750b2
export
*
from
'
./has_menu_expanded
'
;
export
*
from
'
./reset_menu_items_active
'
;
spec/frontend/nav/components/responsive_app_spec.js
View file @
45c750b2
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
range
}
from
'
lodash
'
;
import
ResponsiveApp
from
'
~/nav/components/responsive_app.vue
'
;
import
ResponsiveHeader
from
'
~/nav/components/responsive_header.vue
'
;
import
ResponsiveHome
from
'
~/nav/components/responsive_home.vue
'
;
...
...
@@ -32,6 +31,7 @@ describe('~/nav/components/responsive_app.vue', () => {
const
hasMobileOverlayVisible
=
()
=>
findMobileOverlay
().
classes
(
'
mobile-nav-open
'
);
beforeEach
(()
=>
{
document
.
body
.
innerHTML
=
''
;
// Add test class to reset state + assert that we're adding classes correctly
document
.
body
.
className
=
'
test-class
'
;
});
...
...
@@ -53,14 +53,17 @@ describe('~/nav/components/responsive_app.vue', () => {
});
it
.
each
`
times | expectation
${
0
}
|
${
false
}
${
1
}
|
${
true
}
${
2
}
|
${
false
}
bodyHtml | expectation
${
''
}
|
${
false
}
${
'
<div class="header-content"></div>
'
}
|
${
false
}
${
'
<div class="menu-expanded"></div>
'
}
|
${
false
}
${
'
<div></div><div class="header-content menu-expanded"></div>}
'
}
|
${
true
}
`
(
'
with responsive toggle event triggered $times, body responsive open = $expectation
'
,
({
times
,
expectation
})
=>
{
range
(
times
).
forEach
(
triggerResponsiveToggle
);
'
with responsive toggle event and html set to $bodyHtml, responsive open = $expectation
'
,
({
bodyHtml
,
expectation
})
=>
{
document
.
body
.
innerHTML
=
bodyHtml
;
triggerResponsiveToggle
();
expect
(
hasBodyResponsiveOpen
()).
toBe
(
expectation
);
},
...
...
@@ -88,6 +91,17 @@ describe('~/nav/components/responsive_app.vue', () => {
);
});
describe
(
'
with menu expanded in body
'
,
()
=>
{
beforeEach
(()
=>
{
document
.
body
.
innerHTML
=
'
<div></div><div class="header-content menu-expanded"></div>
'
;
createComponent
();
});
it
(
'
sets the body responsive open
'
,
()
=>
{
expect
(
hasBodyResponsiveOpen
()).
toBe
(
true
);
});
});
const
projectsContainerProps
=
{
containerClass
:
'
gl-px-3
'
,
frequentItemsDropdownType
:
ResponsiveApp
.
FREQUENT_ITEMS_PROJECTS
.
namespace
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment