Skip to content

Commit 6235244

Browse files
(CDPE-4655) Add tooltip to Sidebar.Footer
Prior to this commit, if the Sidebar Footer was used and the sign-out 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 tooltip will appear above the sign-out button when hovered over.
1 parent 6023820 commit 6235244

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
## react-components 5.33.1 (2022-03-04)
2+
3+
- [SidebarFooter] Add tooltip option (by [@chrisleicester](https://github.com/chrisleicester) in [#552](https://github.com/puppetlabs/design-system/pull/552))
4+
15
## react-components 5.33.0 (2022-02-28)
26

37
- [Breadcrumb] Add Back type (by [@Lukeaber](https://github.com/Lukeaber) in [#549](https://github.com/puppetlabs/design-system/pull/549))
48

59
## react-components 5.32.5 (2022-02-24)
610

711
- [Icon] Add change and change warning icon
12+
813
## react-components 5.32.4 (2022-02-11)
914

1015
- [Icon] Add exception icon

packages/react-components/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@puppet/react-components",
3-
"version": "5.33.0",
3+
"version": "5.33.1",
44
"author": "Puppet, Inc.",
55
"license": "Apache-2.0",
66
"main": "build/library.js",
@@ -90,4 +90,4 @@
9090
"regenerator-runtime": "^0.13.7",
9191
"scroll-into-view-if-needed": "^2.2.25"
9292
}
93-
}
93+
}

packages/react-components/source/react/library/sidebar/Sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Badge from '../badge';
6868
onClick={console.log}
6969
enableSignout
7070
onSignout={console.log}
71+
tooltip="Sign out!"
7172
/>
7273
</Sidebar>
7374
</div>;

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)