Skip to content

Commit

Permalink
Update ambiguous label names; tooltip fixes (#528)
Browse files Browse the repository at this point in the history
* Update label names so they are less ambiguous
* Fix clickable tooltip tabIndex bug
* Another tooltip fix
  • Loading branch information
microbit-robert authored Nov 19, 2024
1 parent cb43a76 commit d5b5c70
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 20 deletions.
14 changes: 11 additions & 3 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"defaultMessage": "Connect",
"description": "Connect action to connect to data collection micro:bit via Bluetooth or micro:bit radio"
},
"connect-action-aria": {
"defaultMessage": "Connect to micro:bit",
"description": "Connect action to connect to data collection micro:bit via Bluetooth or micro:bit radio"
},
"connect-battery-heading": {
"defaultMessage": "Disconnect USB and connect battery pack",
"description": "Battery connection dialog "
Expand Down Expand Up @@ -444,7 +448,7 @@
"description": "Confirmation dialog text"
},
"delete-recording-aria": {
"defaultMessage": "Delete recording",
"defaultMessage": "Delete recording {sample} of {numSamples}",
"description": "Aria label for data sample delete action"
},
"disconnect-action": {
Expand Down Expand Up @@ -1252,7 +1256,7 @@
"description": "Label for recording graph"
},
"recording-options-aria": {
"defaultMessage": "More recording options",
"defaultMessage": "More recording options for action \"{action}\"",
"description": "Aria label for more recording options button"
},
"reload-action": {
Expand Down Expand Up @@ -1312,7 +1316,11 @@
"description": "Notification after a hex file has been downloaded"
},
"select-icon-action-aria": {
"defaultMessage": "Pick icon",
"defaultMessage": "Pick icon for action \"{action}\"",
"description": "Aria label for pick icon button"
},
"select-icon-action-untitled-aria": {
"defaultMessage": "Pick icon for untitled action",
"description": "Aria label for pick icon button"
},
"select-icon-option-action-aria": {
Expand Down
31 changes: 27 additions & 4 deletions src/components/ActionDataSamplesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ActionDataSamplesCard = ({
newRecordingId,
clearNewRecordingId,
}: ActionDataSamplesCardProps) => {
const intl = useIntl();
const deleteActionRecording = useStore((s) => s.deleteActionRecording);
const view = useStore((s) => s.settings.dataSamplesView);
if (view === DataSamplesView.GraphAndDataFeatures) {
Expand All @@ -76,6 +77,15 @@ const ActionDataSamplesCard = ({
key={recording.ID}
>
<CloseButton
aria-label={intl.formatMessage(
{
id: "delete-recording-aria",
},
{
sample: value.recordings.length - idx,
numSamples: value.recordings.length,
}
)}
position="absolute"
top={-2}
right={-2}
Expand All @@ -88,6 +98,7 @@ const ActionDataSamplesCard = ({
/>
<DataSample
recording={recording}
numRecordings={value.recordings.length}
actionId={value.ID}
recordingIndex={idx}
isNew={newRecordingId === recording.ID}
Expand Down Expand Up @@ -124,6 +135,7 @@ const ActionDataSamplesCard = ({
actionId={value.ID}
recordingIndex={idx}
recording={recording}
numRecordings={value.recordings.length}
isNew={newRecordingId === recording.ID}
onDelete={deleteActionRecording}
onNewAnimationEnd={clearNewRecordingId}
Expand Down Expand Up @@ -199,7 +211,10 @@ const RecordingArea = ({
<MoreMenuButton
minW={8}
variant={selected ? "record" : "recordOutline"}
aria-label={intl.formatMessage({ id: "recording-options-aria" })}
aria-label={intl.formatMessage(
{ id: "recording-options-aria" },
{ action: action.name }
)}
/>
<Portal>
<MenuList>
Expand Down Expand Up @@ -271,6 +286,7 @@ const RecordingArea = ({

const DataSample = ({
recording,
numRecordings,
actionId,
recordingIndex,
isNew,
Expand All @@ -280,6 +296,7 @@ const DataSample = ({
hasClose = true,
}: {
recording: RecordingData;
numRecordings: number;
actionId: number;
recordingIndex: number;
isNew: boolean;
Expand Down Expand Up @@ -307,9 +324,15 @@ const DataSample = ({
right={0}
zIndex={1}
size="sm"
aria-label={intl.formatMessage({
id: "delete-recording-aria",
})}
aria-label={intl.formatMessage(
{
id: "delete-recording-aria",
},
{
sample: numRecordings - recordingIndex,
numSamples: numRecordings,
}
)}
onClick={handleDelete}
/>
)}
Expand Down
7 changes: 6 additions & 1 deletion src/components/ActionNameCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ const ActionNameCard = ({
) : (
<LedIconSvg icon={icon} />
)}
{!readOnly && <LedIconPicker onIconSelected={handleIconSelected} />}
{!readOnly && (
<LedIconPicker
actionName={value.name}
onIconSelected={handleIconSelected}
/>
)}
</HStack>
<Input
autoFocus={localName.length === 0}
Expand Down
11 changes: 7 additions & 4 deletions src/components/ClickableTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const ClickableTooltip = ({
const label = useDisclosure();
const ref = useRef<HTMLDivElement>(null);
const handleMouseEnter = useCallback(() => {
const openTooltips = document.querySelectorAll(
'[role="tooltip"]:not([hidden])'
const focussedTooltips = Array.from(
document.querySelectorAll(".focusable-tooltip")
);
if (!openTooltips.length) {
if (
focussedTooltips.every((tooltip) => tooltip !== document.activeElement)
) {
label.onOpen();
}
}, [label]);
Expand All @@ -44,12 +46,13 @@ const ClickableTooltip = ({
return (
<Tooltip isOpen={label.isOpen} {...rest} closeOnEsc={true}>
<Flex
className={isFocusable ? "focusable-tooltip" : undefined}
onKeyDown={handleKeydown}
ref={ref}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onClick={label.onOpen}
tabIndex={isDisabled ? undefined : 0}
tabIndex={isFocusable && !isDisabled ? 0 : undefined}
onFocus={isFocusable ? label.onOpen : undefined}
onBlur={isFocusable ? label.onClose : undefined}
_focusVisible={{
Expand Down
14 changes: 12 additions & 2 deletions src/components/LedIconPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import { MakeCodeIcon, makecodeIcons } from "../utils/icons";
import LedIconSvg from "./icons/LedIconSvg";

interface LedIconPicker {
actionName: string;
onIconSelected: (icon: MakeCodeIcon) => void;
}

const LedIconPicker = ({ onIconSelected }: LedIconPicker) => {
const LedIconPicker = ({ actionName, onIconSelected }: LedIconPicker) => {
const intl = useIntl();
const handleClick = useCallback(
(icon: MakeCodeIcon, callback: () => void) => {
Expand All @@ -35,7 +36,16 @@ const LedIconPicker = ({ onIconSelected }: LedIconPicker) => {
<IconButton
variant="ghost"
color="blackAlpha.700"
aria-label={intl.formatMessage({ id: "select-icon-action-aria" })}
aria-label={
actionName
? intl.formatMessage(
{ id: "select-icon-action-aria" },
{ action: actionName }
)
: intl.formatMessage({
id: "select-icon-action-untitled-aria",
})
}
size="sm"
>
<RiArrowDropDownFill size={32} />
Expand Down
10 changes: 7 additions & 3 deletions src/components/LiveGraphPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
VStack,
} from "@chakra-ui/react";
import { useCallback, useRef } from "react";
import { FormattedMessage } from "react-intl";
import { FormattedMessage, useIntl } from "react-intl";
import { ConnectionStatus } from "../connect-status-hooks";
import { useConnectionStage } from "../connection-stage-hooks";
import microbitImage from "../images/stylised-microbit-black.svg";
Expand Down Expand Up @@ -64,7 +64,7 @@ const LiveGraphPanel = ({
});
void actions.disconnect();
}, [actions, logging]);

const intl = useIntl();
return (
<HStack
position="relative"
Expand Down Expand Up @@ -92,7 +92,11 @@ const LiveGraphPanel = ({
<Text>
<FormattedMessage id={disconnectedTextId} />
</Text>
<Button variant="primary" onClick={handleConnectOrReconnect}>
<Button
variant="primary"
onClick={handleConnectOrReconnect}
aria-label={intl.formatMessage({ id: "connect-action-aria" })}
>
<FormattedMessage id="connect-action" />
</Button>
</VStack>
Expand Down
46 changes: 43 additions & 3 deletions src/messages/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@
"value": "Connect"
}
],
"connect-action-aria": [
{
"type": 0,
"value": "Connect to micro:bit"
}
],
"connect-battery-heading": [
{
"type": 0,
Expand Down Expand Up @@ -758,7 +764,19 @@
"delete-recording-aria": [
{
"type": 0,
"value": "Delete recording"
"value": "Delete recording "
},
{
"type": 1,
"value": "sample"
},
{
"type": 0,
"value": " of "
},
{
"type": 1,
"value": "numSamples"
}
],
"disconnect-action": [
Expand Down Expand Up @@ -2204,7 +2222,15 @@
"recording-options-aria": [
{
"type": 0,
"value": "More recording options"
"value": "More recording options for action \""
},
{
"type": 1,
"value": "action"
},
{
"type": 0,
"value": "\""
}
],
"reload-action": [
Expand Down Expand Up @@ -2302,7 +2328,21 @@
"select-icon-action-aria": [
{
"type": 0,
"value": "Pick icon"
"value": "Pick icon for action \""
},
{
"type": 1,
"value": "action"
},
{
"type": 0,
"value": "\""
}
],
"select-icon-action-untitled-aria": [
{
"type": 0,
"value": "Pick icon for untitled action"
}
],
"select-icon-option-action-aria": [
Expand Down

0 comments on commit d5b5c70

Please sign in to comment.