Skip to content

Commit

Permalink
Allow tooltips to be focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Nov 18, 2024
1 parent 3bd481a commit cf8824b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/components/ClickableTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@ import { ReactNode } from "react";

interface ClickableTooltipProps extends TooltipProps {
children: ReactNode;
isFocusable?: boolean;
}

// Chakra Tooltip doesn't support triggering on mobile/tablets:
// https://github.com/chakra-ui/chakra-ui/issues/2691

const ClickableTooltip = ({ children, ...rest }: ClickableTooltipProps) => {
const ClickableTooltip = ({
children,
isFocusable = false,
...rest
}: ClickableTooltipProps) => {
const label = useDisclosure();
return (
<Tooltip isOpen={label.isOpen} {...rest}>
<Flex
onMouseEnter={label.onOpen}
onMouseLeave={label.onClose}
onClick={label.onOpen}
tabIndex={0}
onFocus={isFocusable ? label.onOpen : undefined}
onBlur={isFocusable ? label.onClose : undefined}
_focusVisible={{
boxShadow: "outline",
outline: "none",
}}
borderRadius="50%"
>
{children}
</Flex>
Expand Down
6 changes: 3 additions & 3 deletions src/components/HeadingGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const GridColumnHeadingItem = (props: GridColumnHeadingItemProps) => {
<GridItem>
{props.titleId && props.descriptionId && (
<HStack justifyContent="space-between">
<HStack opacity={0.7}>
<Text>
<HStack>
<Text opacity={0.7}>
<FormattedMessage id={props.titleId} />
</Text>
<InfoToolTip
titleId={props.titleId}
descriptionId={props.descriptionId}
></InfoToolTip>
/>
</HStack>
{props.itemsRight}
</HStack>
Expand Down
3 changes: 2 additions & 1 deletion src/components/InfoToolTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const InfoToolTip = ({ titleId, descriptionId }: InfoToolTipProps) => {
const { appNameFull } = useDeployment();
return (
<ClickableTooltip
isFocusable
hasArrow
placement="right"
label={
Expand All @@ -25,7 +26,7 @@ const InfoToolTip = ({ titleId, descriptionId }: InfoToolTipProps) => {
</VStack>
}
>
<Icon h={5} w={5} as={RiInformationLine} />
<Icon opacity={0.7} h={5} w={5} as={RiInformationLine} />
</ClickableTooltip>
);
};
Expand Down

0 comments on commit cf8824b

Please sign in to comment.