Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
e0cfebdd
Commit
e0cfebdd
authored
Jun 18, 2019
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render submenu item icons on the right as per mocks
parent
1dfc3b91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
9 deletions
+56
-9
menu-item.js
src/sidebar/components/menu-item.js
+19
-9
menu-item-test.js
src/sidebar/components/test/menu-item-test.js
+37
-0
No files found.
src/sidebar/components/menu-item.js
View file @
e0cfebdd
...
...
@@ -43,6 +43,20 @@ function MenuItem({
'menu-item__label--submenu'
:
isSubmenuItem
,
});
const
leftIconSpace
=
icon
!==
undefined
||
isSubmenuItem
;
const
rightIconSpace
=
icon
!==
undefined
&&
isSubmenuItem
;
let
renderedIcon
=
null
;
if
(
icon
)
{
renderedIcon
=
iconIsUrl
?
(
<
img
className
=
{
iconClass
}
alt
=
{
iconAlt
}
src
=
{
icon
}
/
>
)
:
(
<
SvgIcon
name
=
{
icon
}
className
=
"menu-item__icon"
/>
);
}
const
leftIcon
=
isSubmenuItem
?
null
:
renderedIcon
;
const
rightIcon
=
isSubmenuItem
?
renderedIcon
:
null
;
return
(
<
div
aria
-
checked
=
{
isSelected
}
...
...
@@ -55,15 +69,8 @@ function MenuItem({
role
=
"menuitem"
{...(
onClick
&&
onActivate
(
'menuitem'
,
onClick
))}
>
{
icon
!==
undefined
&&
(
<
div
className
=
"menu-item__icon-container"
>
{
icon
&&
(
iconIsUrl
?
(
<
img
className
=
{
iconClass
}
alt
=
{
iconAlt
}
src
=
{
icon
}
/
>
)
:
(
<
SvgIcon
name
=
{
icon
}
className
=
"menu-item__icon"
/>
))}
<
/div
>
{
leftIconSpace
&&
(
<
div
className
=
"menu-item__icon-container"
>
{
leftIcon
}
<
/div
>
)}
{
href
&&
(
<
a
...
...
@@ -76,6 +83,9 @@ function MenuItem({
<
/a
>
)}
{
!
href
&&
<
span
className
=
{
labelClass
}
>
{
label
}
<
/span>
}
{
rightIconSpace
&&
(
<
div
className
=
"menu-item__icon-container"
>
{
rightIcon
}
<
/div
>
)}
{
typeof
isSubmenuVisible
===
'boolean'
&&
(
<
div
className
=
"menu-item__toggle"
...
...
src/sidebar/components/test/menu-item-test.js
View file @
e0cfebdd
...
...
@@ -42,6 +42,19 @@ describe('MenuItem', () => {
assert
.
isTrue
(
wrapper
.
exists
(
'SvgIcon[name="an-svg-icon"]'
));
});
it
(
'renders a blank space for an icon if `icon` is `null`'
,
()
=>
{
const
wrapper
=
createMenuItem
({
icon
:
null
});
const
iconSpace
=
wrapper
.
find
(
'.menu-item__icon-container'
);
assert
.
equal
(
iconSpace
.
length
,
1
);
assert
.
equal
(
iconSpace
.
children
().
length
,
0
);
});
it
(
'does not render a space for an icon if `icon` is missing'
,
()
=>
{
const
wrapper
=
createMenuItem
();
const
iconSpace
=
wrapper
.
find
(
'.menu-item__icon-container'
);
assert
.
equal
(
iconSpace
.
length
,
0
);
});
it
(
'shows the submenu indicator if `isSubmenuVisible` is a boolean'
,
()
=>
{
const
wrapper
=
createMenuItem
({
isSubmenuVisible
:
true
});
assert
.
isTrue
(
wrapper
.
exists
(
'SvgIcon[name="collapse-menu"]'
));
...
...
@@ -61,4 +74,28 @@ describe('MenuItem', () => {
wrapper
.
find
(
'.menu-item__toggle'
).
simulate
(
'click'
);
assert
.
called
(
onToggleSubmenu
);
});
it
(
'renders top-level menu item icons on the left'
,
()
=>
{
const
wrapper
=
createMenuItem
({
icon
:
'an-svg-icon'
});
const
iconSpaces
=
wrapper
.
find
(
'.menu-item__icon-container'
);
// There should be only one icon space, on the left.
assert
.
equal
(
iconSpaces
.
length
,
1
);
assert
.
equal
(
iconSpaces
.
at
(
0
).
children
().
length
,
1
);
});
it
(
'renders submenu item icons on the right'
,
()
=>
{
const
wrapper
=
createMenuItem
({
icon
:
'an-svg-icon'
,
isSubmenuItem
:
true
,
});
const
iconSpaces
=
wrapper
.
find
(
'.menu-item__icon-container'
);
assert
.
equal
(
iconSpaces
.
length
,
2
);
// There should be a space for the parent item's icon.
assert
.
equal
(
iconSpaces
.
at
(
0
).
children
().
length
,
0
);
// The actual icon for the submenu should be shown on the right.
assert
.
equal
(
iconSpaces
.
at
(
1
).
children
().
length
,
1
);
});
});
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