From 6d67282a2c462dde968bebf6384b2337a5cad878 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 19 Nov 2024 16:30:32 +0000 Subject: [PATCH] Improve tooltip using aria-label --- lang/ui.en.json | 16 ++++++++++++++++ src/components/ClickableTooltip.tsx | 10 ++++++++++ src/components/InfoToolTip.tsx | 3 ++- src/messages/ui.en.json | 24 ++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lang/ui.en.json b/lang/ui.en.json index 834cc927c..98f621703 100644 --- a/lang/ui.en.json +++ b/lang/ui.en.json @@ -23,6 +23,10 @@ "defaultMessage": "Action", "description": "Label for a movement-related action, e.g. clapping" }, + "action-label-tooltip-aria": { + "defaultMessage": "Action tooltip", + "description": "Aria label for action tooltip icon" + }, "action-length-error": { "defaultMessage": "Action names cannot be longer than {maxLen} characters.", "description": "Error message shown when an action name is too long" @@ -403,6 +407,10 @@ "defaultMessage": "Data samples", "description": "Heading for data samples column" }, + "data-samples-label-tooltip-aria": { + "defaultMessage": "Data samples tooltip", + "description": "Aria label for data samples tooltip icon" + }, "data-samples-status-count": { "defaultMessage": "{numSamples} samples recorded", "description": "Data samples status text" @@ -555,6 +563,10 @@ "defaultMessage": "Estimated action", "description": "Heading for estimated action area next to the live graph" }, + "estimated-action-label-tooltip-aria": { + "defaultMessage": "Estimated action tooltip", + "description": "Aria label for estimated action tooltip icon" + }, "estimated-action-tooltip": { "defaultMessage": "This is the action the model thinks you are currently doing.", "description": "Tooltip for the estimated action heading" @@ -979,6 +991,10 @@ "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.", "description": "Tooltip for live graph heading" }, + "live-graph-tooltip-aria": { + "defaultMessage": "Live graph tooltip", + "description": "Aria label for live graph tooltip icon" + }, "loading": { "defaultMessage": "Loading", "description": "Aria label for loading spinner" diff --git a/src/components/ClickableTooltip.tsx b/src/components/ClickableTooltip.tsx index 4b210dc52..1ab775913 100644 --- a/src/components/ClickableTooltip.tsx +++ b/src/components/ClickableTooltip.tsx @@ -1,9 +1,11 @@ import { Flex, Tooltip, TooltipProps, useDisclosure } from "@chakra-ui/react"; import { ReactNode, useCallback, useRef } from "react"; +import { useIntl } from "react-intl"; interface ClickableTooltipProps extends TooltipProps { children: ReactNode; isFocusable?: boolean; + titleId?: string; } // Chakra Tooltip doesn't support triggering on mobile/tablets: @@ -12,10 +14,12 @@ interface ClickableTooltipProps extends TooltipProps { const ClickableTooltip = ({ children, isFocusable = false, + titleId, isDisabled, ...rest }: ClickableTooltipProps) => { const label = useDisclosure(); + const intl = useIntl(); const ref = useRef(null); const handleMouseEnter = useCallback(() => { const focussedTooltips = Array.from( @@ -46,6 +50,12 @@ const ClickableTooltip = ({ return ( { titleId: string; @@ -13,6 +13,7 @@ const InfoToolTip = ({ titleId, descriptionId, ...rest }: InfoToolTipProps) => { return (