Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tooltip using aria-label #533

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/components/ClickableTooltip.tsx
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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<HTMLDivElement>(null);
const handleMouseEnter = useCallback(() => {
const focussedTooltips = Array.from(
Expand Down Expand Up @@ -46,6 +50,12 @@ const ClickableTooltip = ({
return (
<Tooltip isOpen={label.isOpen} {...rest} closeOnEsc={true}>
<Flex
as="span"
aria-label={
titleId
? intl.formatMessage({ id: `${titleId}-tooltip-aria` })
: undefined
}
className={isFocusable ? "focusable-tooltip" : undefined}
onKeyDown={handleKeydown}
ref={ref}
Expand Down
3 changes: 2 additions & 1 deletion src/components/InfoToolTip.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Icon, Text, TooltipProps, VStack } from "@chakra-ui/react";
import { RiInformationLine } from "react-icons/ri";
import { FormattedMessage } from "react-intl";
import ClickableTooltip from "./ClickableTooltip";
import { useDeployment } from "../deployment";
import ClickableTooltip from "./ClickableTooltip";

export interface InfoToolTipProps extends Omit<TooltipProps, "children"> {
titleId: string;
Expand All @@ -13,6 +13,7 @@ const InfoToolTip = ({ titleId, descriptionId, ...rest }: InfoToolTipProps) => {
return (
<ClickableTooltip
isFocusable
titleId={titleId}
hasArrow
placement="right"
{...rest}
Expand Down
24 changes: 24 additions & 0 deletions src/messages/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"value": "Action"
}
],
"action-label-tooltip-aria": [
{
"type": 0,
"value": "Action tooltip"
}
],
"action-length-error": [
{
"type": 0,
Expand Down Expand Up @@ -675,6 +681,12 @@
"value": "Data samples"
}
],
"data-samples-label-tooltip-aria": [
{
"type": 0,
"value": "Data samples tooltip"
}
],
"data-samples-status-count": [
{
"type": 1,
Expand Down Expand Up @@ -951,6 +963,12 @@
"value": "Estimated action"
}
],
"estimated-action-label-tooltip-aria": [
{
"type": 0,
"value": "Estimated action tooltip"
}
],
"estimated-action-tooltip": [
{
"type": 0,
Expand Down Expand Up @@ -1675,6 +1693,12 @@
"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."
}
],
"live-graph-tooltip-aria": [
{
"type": 0,
"value": "Live graph tooltip"
}
],
"loading": [
{
"type": 0,
Expand Down
Loading