Skip to content

Commit cb58aae

Browse files
(CDPE-4655) Add tooltip to Sidebar.Footer
Prior to this commit, if the Sidebar Footer was used and the signout button was present, there was no way to add a tooltip to explain the usage of this button. This makes it difficult for someone using a screen reader to find this button and use it. With this commit, we add an optional parameter to the Sidebar Footer to specify tooltip text. If specified, the tooptip will appear above the sign-out button when hovered over.
1 parent 6023820 commit cb58aae

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/react-components/source/react/library/sidebar/SidebarFooter.js

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Heading from '../heading';
66
import Text from '../text';
77
import Avatar from '../avatar';
88
import Button from '../button';
9+
import TooltipHoverArea from '../tooltips/TooltipHoverArea';
910

1011
const propTypes = {
1112
/** The root HTML element */
@@ -20,6 +21,8 @@ const propTypes = {
2021
profileIcon: PropTypes.node,
2122
/** Boolean flag to enable or disable (default) signout button */
2223
enableSignout: PropTypes.bool,
24+
/** Sign-out icon tooltip text */
25+
tooltip: PropTypes.string,
2326
/** Signout callback function */
2427
onSignout: PropTypes.func,
2528
};
@@ -31,6 +34,7 @@ const defaultProps = {
3134
minimized: false,
3235
profileIcon: null,
3336
enableSignout: false,
37+
tooltip: null,
3438
onSignout: () => {},
3539
};
3640

@@ -41,6 +45,7 @@ const SidebarFooter = ({
4145
minimized,
4246
profileIcon: profileIconProp,
4347
enableSignout,
48+
tooltip,
4449
onSignout,
4550
...rest
4651
}) => {
@@ -72,6 +77,13 @@ const SidebarFooter = ({
7277
<Icon type="sign-out" className="rc-sidebar-footer-signout-icon" />
7378
</Button>
7479
);
80+
if (tooltip) {
81+
signout = (
82+
<TooltipHoverArea anchor="top" tooltip={tooltip}>
83+
{signout}
84+
</TooltipHoverArea>
85+
);
86+
}
7587
}
7688
}
7789

packages/react-components/test/sidebar/Sidebar.js

+31
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,36 @@ describe('<Sidebar />', () => {
130130
wrapper.find('.rc-sidebar-footer-button-signout').simulate('click');
131131
expect(callback.calledOnce).to.be.true;
132132
});
133+
134+
it('should not render tooltip when no tooltip is specified', () => {
135+
const callback = sinon.fake();
136+
const wrapper = shallow(
137+
<Sidebar.Footer enableSignout onSignout={callback} />,
138+
);
139+
140+
expect(wrapper.find('TooltipHoverArea').length).to.eql(0);
141+
});
142+
143+
it('should not render tooltip when sigout is disabled', () => {
144+
const callback = sinon.fake();
145+
const wrapper = shallow(
146+
<Sidebar.Footer tooltip="I love being a tooltip" />,
147+
);
148+
149+
expect(wrapper.find('TooltipHoverArea').length).to.eql(0);
150+
});
151+
152+
it('should render a tooltip with signout is enabled and tooltip is specified', () => {
153+
const callback = sinon.fake();
154+
const wrapper = shallow(
155+
<Sidebar.Footer
156+
enableSignout
157+
onSignout={callback}
158+
tooltip="I love being a tooltip"
159+
/>,
160+
);
161+
162+
expect(wrapper.find('TooltipHoverArea').length).to.eql(1);
163+
});
133164
});
134165
});

0 commit comments

Comments
 (0)