Skip to content

Commit 63a219c

Browse files
Improve tooltip using aria-label (#533)
1 parent 5dbf9e6 commit 63a219c

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

lang/ui.en.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"defaultMessage": "Action",
2424
"description": "Label for a movement-related action, e.g. clapping"
2525
},
26+
"action-label-tooltip-aria": {
27+
"defaultMessage": "Action tooltip",
28+
"description": "Aria label for action tooltip icon"
29+
},
2630
"action-length-error": {
2731
"defaultMessage": "Action names cannot be longer than {maxLen} characters.",
2832
"description": "Error message shown when an action name is too long"
@@ -403,6 +407,10 @@
403407
"defaultMessage": "Data samples",
404408
"description": "Heading for data samples column"
405409
},
410+
"data-samples-label-tooltip-aria": {
411+
"defaultMessage": "Data samples tooltip",
412+
"description": "Aria label for data samples tooltip icon"
413+
},
406414
"data-samples-status-count": {
407415
"defaultMessage": "{numSamples} samples recorded",
408416
"description": "Data samples status text"
@@ -555,6 +563,10 @@
555563
"defaultMessage": "Estimated action",
556564
"description": "Heading for estimated action area next to the live graph"
557565
},
566+
"estimated-action-label-tooltip-aria": {
567+
"defaultMessage": "Estimated action tooltip",
568+
"description": "Aria label for estimated action tooltip icon"
569+
},
558570
"estimated-action-tooltip": {
559571
"defaultMessage": "This is the action the model thinks you are currently doing.",
560572
"description": "Tooltip for the estimated action heading"
@@ -979,6 +991,10 @@
979991
"defaultMessage": "This graph shows movement data from the micro:bit's accelerometer in real time. Try moving your data collection micro:bit to see the X, Y and Z axes change. Each coloured line represents a different direction (dimension) you are moving the micro:bit in.",
980992
"description": "Tooltip for live graph heading"
981993
},
994+
"live-graph-tooltip-aria": {
995+
"defaultMessage": "Live graph tooltip",
996+
"description": "Aria label for live graph tooltip icon"
997+
},
982998
"loading": {
983999
"defaultMessage": "Loading",
9841000
"description": "Aria label for loading spinner"

src/components/ClickableTooltip.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Flex, Tooltip, TooltipProps, useDisclosure } from "@chakra-ui/react";
22
import { ReactNode, useCallback, useRef } from "react";
3+
import { useIntl } from "react-intl";
34

45
interface ClickableTooltipProps extends TooltipProps {
56
children: ReactNode;
67
isFocusable?: boolean;
8+
titleId?: string;
79
}
810

911
// Chakra Tooltip doesn't support triggering on mobile/tablets:
@@ -12,10 +14,12 @@ interface ClickableTooltipProps extends TooltipProps {
1214
const ClickableTooltip = ({
1315
children,
1416
isFocusable = false,
17+
titleId,
1518
isDisabled,
1619
...rest
1720
}: ClickableTooltipProps) => {
1821
const label = useDisclosure();
22+
const intl = useIntl();
1923
const ref = useRef<HTMLDivElement>(null);
2024
const handleMouseEnter = useCallback(() => {
2125
const focussedTooltips = Array.from(
@@ -46,6 +50,12 @@ const ClickableTooltip = ({
4650
return (
4751
<Tooltip isOpen={label.isOpen} {...rest} closeOnEsc={true}>
4852
<Flex
53+
as="span"
54+
aria-label={
55+
titleId
56+
? intl.formatMessage({ id: `${titleId}-tooltip-aria` })
57+
: undefined
58+
}
4959
className={isFocusable ? "focusable-tooltip" : undefined}
5060
onKeyDown={handleKeydown}
5161
ref={ref}

src/components/InfoToolTip.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Icon, Text, TooltipProps, VStack } from "@chakra-ui/react";
22
import { RiInformationLine } from "react-icons/ri";
33
import { FormattedMessage } from "react-intl";
4-
import ClickableTooltip from "./ClickableTooltip";
54
import { useDeployment } from "../deployment";
5+
import ClickableTooltip from "./ClickableTooltip";
66

77
export interface InfoToolTipProps extends Omit<TooltipProps, "children"> {
88
titleId: string;
@@ -13,6 +13,7 @@ const InfoToolTip = ({ titleId, descriptionId, ...rest }: InfoToolTipProps) => {
1313
return (
1414
<ClickableTooltip
1515
isFocusable
16+
titleId={titleId}
1617
hasArrow
1718
placement="right"
1819
{...rest}

src/messages/ui.en.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
"value": "Action"
4646
}
4747
],
48+
"action-label-tooltip-aria": [
49+
{
50+
"type": 0,
51+
"value": "Action tooltip"
52+
}
53+
],
4854
"action-length-error": [
4955
{
5056
"type": 0,
@@ -675,6 +681,12 @@
675681
"value": "Data samples"
676682
}
677683
],
684+
"data-samples-label-tooltip-aria": [
685+
{
686+
"type": 0,
687+
"value": "Data samples tooltip"
688+
}
689+
],
678690
"data-samples-status-count": [
679691
{
680692
"type": 1,
@@ -951,6 +963,12 @@
951963
"value": "Estimated action"
952964
}
953965
],
966+
"estimated-action-label-tooltip-aria": [
967+
{
968+
"type": 0,
969+
"value": "Estimated action tooltip"
970+
}
971+
],
954972
"estimated-action-tooltip": [
955973
{
956974
"type": 0,
@@ -1675,6 +1693,12 @@
16751693
"value": "This graph shows movement data from the micro:bit's accelerometer in real time. Try moving your data collection micro:bit to see the X, Y and Z axes change. Each coloured line represents a different direction (dimension) you are moving the micro:bit in."
16761694
}
16771695
],
1696+
"live-graph-tooltip-aria": [
1697+
{
1698+
"type": 0,
1699+
"value": "Live graph tooltip"
1700+
}
1701+
],
16781702
"loading": [
16791703
{
16801704
"type": 0,

0 commit comments

Comments
 (0)