Skip to content

Commit 8059216

Browse files
authored
Accessibility changes in Tooltip and Checkbox component
2 parents 145107c + 80183a3 commit 8059216

File tree

3 files changed

+48
-56
lines changed

3 files changed

+48
-56
lines changed

src/lib/components/Tooltip/Tooltip.js

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ import positionTooltip from "../../helpers/positionTooltip.js";
77
/*
88
Renders an accessible element that displays a tooltip.
99
Element can either be a link or not.
10-
10+
1111
Usage:
1212
1313
<Tooltip
1414
tooltipBody="This is some helper text to display in a tooltip"
1515
id="forgot-tooltip"
1616
text="Forgot something?"
1717
/>
18-
19-
Props:
2018
19+
Props:
2120
--REQUIRED--
22-
text [String] - The text to display. Hovering over it will reveal the tooltip.
23-
tooltipBody [String] - The text to be displayed in the tooltip
21+
text [String] - Visible text (also acts as accessible label)
22+
tooltipBody [String] - Tooltip content
2423
2524
--OPTIONAL--
2625
classes [String] - Additional CSS classes that will be added to the control container div element.
@@ -49,67 +48,59 @@ const Tooltip = (props) => {
4948
const tooltipRef = useRef(null);
5049
const triggerClass = classnames("dfn-tooltip-trigger", classes);
5150

52-
const handleMouseEnter = (event) => {
51+
const handleMouseEnter = () => {
5352
const currentTooltip = tooltipRef.current;
54-
positionTooltip(currentTooltip, position);
55-
};
56-
57-
const renderTriggerElement = () => {
58-
if (link) {
59-
return renderLink();
60-
} else if (url) {
61-
return renderAnchor();
62-
} else {
63-
return renderButton();
53+
if (currentTooltip) {
54+
positionTooltip(currentTooltip, position);
6455
}
6556
};
6657

67-
const renderAnchor = () => {
68-
return (
69-
<a
70-
aria-labelledby={tooltipElementId}
71-
className={triggerClass}
72-
href={url}
73-
onMouseEnter={handleMouseEnter}
74-
>
75-
{text}
76-
</a>
77-
);
78-
};
58+
const renderAnchor = () => (
59+
<a
60+
aria-describedby={tooltipElementId}
61+
className={triggerClass}
62+
href={url}
63+
onMouseEnter={handleMouseEnter}
64+
>
65+
{text}
66+
</a>
67+
);
7968

80-
const renderButton = () => {
81-
return (
82-
<button
83-
aria-labelledby={tooltipElementId}
84-
className={triggerClass}
85-
onClick={onClick}
86-
onMouseEnter={handleMouseEnter}
87-
type={buttonType}
88-
>
89-
{text}
90-
</button>
91-
);
92-
};
69+
const renderButton = () => (
70+
<button
71+
aria-describedby={tooltipElementId}
72+
className={triggerClass}
73+
onClick={onClick}
74+
onMouseEnter={handleMouseEnter}
75+
type={buttonType}
76+
>
77+
{text}
78+
</button>
79+
);
9380

94-
const renderLink = () => {
95-
return (
96-
<Link
97-
aria-labelledby={tooltipElementId}
98-
className={triggerClass}
99-
onMouseEnter={handleMouseEnter}
100-
to={link}
101-
>
102-
{text}
103-
</Link>
104-
);
81+
const renderLink = () => (
82+
<Link
83+
aria-describedby={tooltipElementId}
84+
className={triggerClass}
85+
onMouseEnter={handleMouseEnter}
86+
to={link}
87+
>
88+
{text}
89+
</Link>
90+
);
91+
92+
const renderTriggerElement = () => {
93+
if (link) return renderLink();
94+
if (url) return renderAnchor();
95+
return renderButton();
10596
};
10697

10798
return (
10899
<div className="dfn-tooltip">
109100
{renderTriggerElement()}
110101
<div
111102
className={classnames("dfn-tooltip-bubble", `tooltip-${position}`)}
112-
id={`${id}-desc`}
103+
id={tooltipElementId}
113104
ref={tooltipRef}
114105
role="tooltip"
115106
>

src/scss/styles.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ a {
217217

218218
&:focus ~ .control-indicator,
219219
&:hover ~ .control-indicator {
220-
border-color: $blue;
220+
border-color: $green-dark;
221221
}
222222

223223
&:focus ~ .control-label,
224224
&:hover ~ .control-label {
225-
color: $blue;
225+
color: $green-dark;
226226
}
227227

228228
&:checked:focus ~ .control-indicator,
229229
&:checked:hover ~ .control-indicator {
230-
background-color: $blue;
230+
background-color: $green-dark;
231231
}
232232

233233
&.invalid ~ .control-indicator,

src/scss/variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ $black: #000 !default;
33
$blue: blue !default;
44
$gray-light: #eee !default;
55
$green: green !default;
6+
$green-dark: #397600;
67
$muted: #767676 !default;
78
$red: #ee0000 !default;
89
$white: #fff !default;

0 commit comments

Comments
 (0)