Commit 95b95b52 authored by Kyle Keating's avatar Kyle Keating Committed by Lyza Danger Gardner

Hide menu item toggle button if there are no submenu items

Pass undefined to MenuItem to hide the submenu and its toggle button.
parent 3d0d9330
...@@ -83,7 +83,7 @@ function GroupListItem({ ...@@ -83,7 +83,7 @@ function GroupListItem({
isDisabled={!isSelectable} isDisabled={!isSelectable}
isExpanded={hasActionMenu ? isExpanded : false} isExpanded={hasActionMenu ? isExpanded : false}
isSelected={isSelected} isSelected={isSelected}
isSubmenuVisible={isExpanded} isSubmenuVisible={hasActionMenu ? isExpanded : undefined}
label={group.name} label={group.name}
onClick={isSelectable ? focusGroup : toggleSubmenu} onClick={isSelectable ? focusGroup : toggleSubmenu}
onToggleSubmenu={toggleSubmenu} onToggleSubmenu={toggleSubmenu}
......
...@@ -169,11 +169,13 @@ describe('GroupListItem', () => { ...@@ -169,11 +169,13 @@ describe('GroupListItem', () => {
it('expands submenu if `isExpanded` is `true`', () => { it('expands submenu if `isExpanded` is `true`', () => {
const wrapper = createGroupListItem(fakeGroup, { isExpanded: true }); const wrapper = createGroupListItem(fakeGroup, { isExpanded: true });
assert.isTrue(wrapper.find('MenuItem').prop('isSubmenuVisible'));
assert.isTrue(wrapper.find('MenuItem').first().prop('isExpanded')); assert.isTrue(wrapper.find('MenuItem').first().prop('isExpanded'));
}); });
it('collapses submenu if `isExpanded` is `false`', () => { it('collapses submenu if `isExpanded` is `false`', () => {
const wrapper = createGroupListItem(fakeGroup, { isExpanded: false }); const wrapper = createGroupListItem(fakeGroup, { isExpanded: false });
assert.isFalse(wrapper.find('MenuItem').prop('isSubmenuVisible'));
assert.isFalse(wrapper.find('MenuItem').first().prop('isExpanded')); assert.isFalse(wrapper.find('MenuItem').first().prop('isExpanded'));
}); });
...@@ -197,12 +199,18 @@ describe('GroupListItem', () => { ...@@ -197,12 +199,18 @@ describe('GroupListItem', () => {
assert.calledWith(onExpand, false); assert.calledWith(onExpand, false);
}); });
[true, false].forEach(isExpanded => {
it('does not show submenu toggle if there are no available actions', () => { it('does not show submenu toggle if there are no available actions', () => {
fakeGroup.links.html = null; fakeGroup.links.html = null;
fakeGroup.type = 'open'; fakeGroup.type = 'open';
fakeGroup.canLeave = false; fakeGroup.canLeave = false;
const wrapper = createGroupListItem(fakeGroup); // isExpanded value should not matter
assert.isFalse(wrapper.find('MenuItem').prop('isExpanded')); const wrapper = createGroupListItem(fakeGroup, { isExpanded });
assert.equal(
wrapper.find('MenuItem').prop('isSubmenuVisible'),
undefined
);
});
}); });
function getSubmenu(wrapper) { function getSubmenu(wrapper) {
......
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