}
>
diff --git a/packages/gamut/src/Tip/shared/FloatingTip.tsx b/packages/gamut/src/Tip/shared/FloatingTip.tsx
index c251d1570c..c301366154 100644
--- a/packages/gamut/src/Tip/shared/FloatingTip.tsx
+++ b/packages/gamut/src/Tip/shared/FloatingTip.tsx
@@ -31,7 +31,7 @@ export const FloatingTip: React.FC = ({
loading,
narrow,
overline,
- popoverContentRef,
+ contentRef,
truncateLines,
type,
username,
@@ -152,9 +152,7 @@ export const FloatingTip: React.FC = ({
width={inheritDims ? 'inherit' : undefined}
onBlur={toolOnlyEventFunc}
onFocus={toolOnlyEventFunc}
- onKeyDown={
- escapeKeyPressHandler ? (e) => escapeKeyPressHandler(e) : undefined
- }
+ onKeyDown={escapeKeyPressHandler}
onMouseDown={(e) => e.preventDefault()}
onMouseEnter={toolOnlyEventFunc}
>
@@ -167,7 +165,7 @@ export const FloatingTip: React.FC = ({
horizontalOffset={offset}
isOpen={isPopoverOpen}
outline
- popoverContainerRef={popoverContentRef}
+ popoverContainerRef={contentRef}
skipFocusTrap
targetRef={ref}
variant="secondary"
diff --git a/packages/gamut/src/Tip/shared/InlineTip.tsx b/packages/gamut/src/Tip/shared/InlineTip.tsx
index dec57516fa..871cfaac1a 100644
--- a/packages/gamut/src/Tip/shared/InlineTip.tsx
+++ b/packages/gamut/src/Tip/shared/InlineTip.tsx
@@ -23,6 +23,7 @@ export const InlineTip: React.FC = ({
loading,
narrow,
overline,
+ contentRef,
truncateLines,
type,
username,
@@ -45,9 +46,7 @@ export const InlineTip: React.FC = ({
height={inheritDims ? 'inherit' : undefined}
ref={wrapperRef}
width={inheritDims ? 'inherit' : undefined}
- onKeyDown={
- escapeKeyPressHandler ? (e) => escapeKeyPressHandler(e) : undefined
- }
+ onKeyDown={escapeKeyPressHandler}
>
{children}
@@ -65,7 +64,9 @@ export const InlineTip: React.FC = ({
color="currentColor"
horizNarrow={narrow && isHorizontalCenter}
id={id}
+ ref={contentRef}
role={type === 'tool' ? 'tooltip' : undefined}
+ tabIndex={type === 'info' ? -1 : undefined}
width={narrow && !isHorizontalCenter ? narrowWidth : 'max-content'}
zIndex="auto"
>
diff --git a/packages/gamut/src/Tip/shared/types.tsx b/packages/gamut/src/Tip/shared/types.tsx
index a91c5e6a6f..164ed1aaf3 100644
--- a/packages/gamut/src/Tip/shared/types.tsx
+++ b/packages/gamut/src/Tip/shared/types.tsx
@@ -78,7 +78,7 @@ export type TipPlacementComponentProps = Omit<
escapeKeyPressHandler?: (event: React.KeyboardEvent) => void;
id?: string;
isTipHidden?: boolean;
- popoverContentRef?:
+ contentRef?:
| React.RefObject
| ((node: HTMLDivElement | null) => void);
type: 'info' | 'tool' | 'preview';
diff --git a/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx b/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx
index bafb0f40f6..6690273240 100644
--- a/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx
+++ b/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx
@@ -69,6 +69,12 @@ A field can include our existing `InfoTip`<
+#### Accessibility
+
+InfoTip buttons are automatically labelled by string field labels for accessibility.
+
+
+
## Playground
diff --git a/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx b/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx
index 09faa218a1..c8ce0e0781 100644
--- a/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx
+++ b/packages/styleguide/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx
@@ -97,3 +97,14 @@ export const HighEmphasisInfoTip: Story = {
children: ,
},
};
+
+export const InfoTipAutoLabelling: Story = {
+ args: {
+ label: 'Email address',
+ htmlFor: 'auto-label-input',
+ infotip: {
+ info: 'We will never share your email with third parties.',
+ },
+ children: ,
+ },
+};
diff --git a/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx b/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx
index 15b440bf55..d8123beb1f 100644
--- a/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx
+++ b/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx
@@ -28,8 +28,7 @@ export const parameters = {
A tip is triggered by clicking on an information icon button and can be closed by clicking outside, pressing Esc, or clicking the info button again.
Use an infotip to provide additional info about a nearby element or content.
-
-Infotip consists of an icon button and the .tip-bg subcomponent. The info button has low and high emphasis variants and the `.tip` has 4 alignment variants.
+The info button has low and high emphasis variants and the `Tip` has 4 alignment variants.
## Variants
@@ -57,16 +56,18 @@ This `floating` variant should only be used as needed.
### InfoTips with links or buttons
-Links or buttons within InfoTips should be used sparingly and only when the information is critical to the user's understanding of the content. If an infotip _absolutely requires_ a link or button, it needs to provide a programmatic focus by way of the `onClick` prop. The `onClick` prop accepts a function that can accept an `{isTipHidden}` argument and using that you can set programmatic focus as needed.
+Links or buttons within InfoTips should be used sparingly and only when the information is critical to the user's understanding of the content. When an InfoTip opens, focus automatically moves to the tip content, allowing keyboard users to immediately interact with any links or buttons inside.
-### Floating placement
+### Automatic Focus Management
-When using `placement="floating"`, InfoTips implements focus management for easier navigation:
+InfoTips automatically manage focus for optimal keyboard accessibility:
-- **Tab**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button for convenience
-- **Shift+Tab**: Navigate backward naturally through the page
+- **Opening**: Focus automatically moves to the tip content when opened
+- **Tab (Floating)**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button
+- **Shift+Tab (Floating)**: Navigate backward naturally - from the button, exits to the previous page element
+- **Tab/Shift+Tab (Inline)**: Follows normal document flow
- **Escape**: Closes the tip and returns focus to the InfoTip button
@@ -82,6 +83,21 @@ InfoTips have intelligent Escape key handling that works correctly both inside a
+## Custom Accessible Labeling
+
+Provide either `ariaLabel` or `ariaLabelledby` to ensure screen reader users understand the purpose of the InfoTip button.
+
+The InfoTip button's accessible label can be customized using either prop:
+
+- **`ariaLabel`**: Directly sets the accessible label text. Useful when you want to provide a custom label without referencing another element.
+- **`ariaLabelledby`**: References the ID of another element to use as the label. Useful when you want the InfoTip button to be labeled by visible text elsewhere on the page. This is useful for when the `InfoTip` is beside text that contextualizes it.
+
+### Custom Role Description
+
+The `InfoTipButton` uses [`aria-roledescription`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-roledescription) to provide additional context to screen reader users about the button's specific purpose. This defaults to `"More information button"` but can be customized via the `ariaRoleDescription` prop for translation or other accessibility needs.
+
+
+
## InfoTips and zIndex
You can change the zIndex of your `InfoTip` with the zIndex property.
diff --git a/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx b/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx
index 66807b72d2..5fa267cfd9 100644
--- a/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx
+++ b/packages/styleguide/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx
@@ -4,17 +4,20 @@ import {
FillButton,
FlexBox,
GridBox,
+ IconButton,
InfoTip,
Modal,
Text,
} from '@codecademy/gamut';
+import { SparkleIcon } from '@codecademy/gamut-icons';
import type { Meta, StoryObj } from '@storybook/react';
-import { useRef, useState } from 'react';
+import { useState } from 'react';
const meta: Meta = {
component: InfoTip,
args: {
alignment: 'top-left',
+ ariaLabel: 'More information',
info: `I am additional information about a nearby element or content.`,
},
};
@@ -28,7 +31,10 @@ export const Emphasis: Story = {
},
render: (args) => (
- Some text that needs info
+
+ Some text that needs info
+
+
),
};
@@ -38,10 +44,15 @@ export const Alignments: Story = {
{(['top-right', 'top-left', 'bottom-right', 'bottom-left'] as const).map(
(alignment) => {
+ const labelId = `alignment-${alignment}`;
return (
- {alignment}
-
+ {alignment}
+
);
}
@@ -56,10 +67,51 @@ export const Placement: Story = {
},
render: (args) => (
-
+
This text is in a small space and needs floating placement
{' '}
-
+
+
+ ),
+};
+
+export const AriaLabel: Story = {
+ render: (args) => (
+
+
+
+ Using ariaLabel (no visible label text):
+
+
+
+ null}
+ />
+
+
+
+
+
+ Using ariaLabelledby (references visible text):
+
+
+
+
+ I am some helpful yet concise text that needs more explanation
+
+
+
),
};
@@ -69,19 +121,16 @@ export const WithLinksOrButtons: Story = {
placement: 'floating',
},
render: function WithLinksOrButtons(args) {
- const ref = useRef(null);
-
- const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
- if (!isTipHidden) ref.current?.focus();
- };
-
return (
- This text is in a small space and needs info {' '}
+
+ This text is in a small space and needs info
+ {' '}
+
Hey! Here is a{' '}
cool link
@@ -93,7 +142,6 @@ export const WithLinksOrButtons: Story = {
that is also super important.
}
- onClick={onClick}
/>
);
@@ -102,42 +150,35 @@ export const WithLinksOrButtons: Story = {
export const KeyboardNavigation: Story = {
render: function KeyboardNavigation() {
- const floatingRef = useRef(null);
- const inlineRef = useRef(null);
-
const examples = [
{
title: 'Floating Placement',
placement: 'floating' as const,
- ref: floatingRef,
links: ['Link 1', 'Link 2', 'Link 3'],
},
{
title: 'Inline Placement',
placement: 'inline' as const,
alignment: 'bottom-right' as const,
- ref: inlineRef,
links: ['Link A', 'Link B'],
},
];
return (
-
+
- {examples.map(({ title, placement, alignment, ref, links }) => {
- const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
- if (!isTipHidden) ref.current?.focus();
- };
-
+ {examples.map(({ title, placement, alignment, links }) => {
+ const labelId = `keyboard-nav-${placement}`;
return (
-
+
{title}
+
{links.map((label, idx) => (
<>
{idx > 0 && ', '}
@@ -150,7 +191,6 @@ export const KeyboardNavigation: Story = {
}
placement={placement}
- onClick={onClick}
/>
);
@@ -162,6 +202,10 @@ export const KeyboardNavigation: Story = {
Keyboard Navigation:
+
+ Opening: Focus automatically moves to the tip
+ content when opened
+
Floating - Tab: Navigates forward through links,
then wraps to button (contained)
@@ -224,8 +268,10 @@ export const InfoTipInsideModal: Story = {
This modal contains an InfoTip below:
- Some text that needs explanation
-
+
+ Some text that needs explanation
+
+
@@ -253,11 +299,14 @@ export const ZIndex: Story = {
I will not be behind the infotip, sad + unreadable
-
+
I will be behind the infotip, nice + great
-
+
),
};
@@ -265,7 +314,10 @@ export const ZIndex: Story = {
export const Default: Story = {
render: (args) => (
- Some text that needs info
+
+ Some text that needs info
+
+
),
};
diff --git a/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx b/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx
index f150a0955e..5214d35cbf 100644
--- a/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx
+++ b/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx
@@ -61,6 +61,26 @@ A `ConnectedFormGroup` can be in one of three states: `default`, `error`, or `di
+## InfoTip
+
+A `ConnectedFormGroup` can include an `infotip` prop to provide additional context.
+
+### Automatic labelling
+
+InfoTip buttons are automatically labelled by string field labels for accessibility.
+
+
+
+### ReactNode labels
+
+For ReactNode labels (e.g., styled text or icons), you have three options:
+
+- `labelledByFieldLabel: true` - opt into automatic labelling by the field label
+- `ariaLabel` - provide a custom accessible name
+- `ariaLabelledby` - reference another element on the page, such as a section heading
+
+
+
## Playground
To see how a `ConnectedFormGroup` can be used in a `ConnectedForm`, check out the ConnectedForm page.
diff --git a/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx b/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx
index 716e2ecf22..375c91e32d 100644
--- a/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx
+++ b/packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx
@@ -2,7 +2,9 @@ import {
ConnectedForm,
ConnectedFormGroup,
ConnectedFormGroupProps,
+ ConnectedInput,
ConnectedRadioGroupInput,
+ Text,
useConnectedForm,
} from '@codecademy/gamut';
import { action } from '@storybook/addon-actions';
@@ -119,3 +121,85 @@ export const States = () => {
);
};
+
+/**
+ * InfoTip buttons are automatically labelled by string field labels for accessibility.
+ * Screen readers will announce "Field Label, button" when focusing the InfoTip.
+ */
+export const InfoTipAutoLabelling: Story = {
+ render: () => (
+ action('Form Submitted')(values)}
+ >
+
+
+ ),
+};
+
+/**
+ * For ReactNode labels, you have three options for accessible InfoTip labelling:
+ * - `labelledByFieldLabel: true` - uses the field label
+ * - `ariaLabel` - provides a custom accessible name
+ * - `ariaLabelledby` - references another element on the page
+ */
+export const InfoTipWithReactNodeLabel: Story = {
+ render: () => (
+ action('Form Submitted')(values)}
+ >
+
+ API Configuration
+
+
+ Username (labelledByFieldLabel)
+
+ }
+ name="username"
+ />
+
+ Password (ariaLabel)
+
+ }
+ name="password"
+ />
+
+ API Key (ariaLabelledby)
+
+ }
+ name="apiKey"
+ />
+
+ ),
+};
diff --git a/packages/styleguide/src/lib/Organisms/GridForm/Fields.mdx b/packages/styleguide/src/lib/Organisms/GridForm/Fields.mdx
index 84f408b073..7385423a85 100644
--- a/packages/styleguide/src/lib/Organisms/GridForm/Fields.mdx
+++ b/packages/styleguide/src/lib/Organisms/GridForm/Fields.mdx
@@ -95,3 +95,23 @@ Hidden inputs can be used to include data that users can't see or modify with th
We call it a "sweet container" so that bots do not immediately detect it as a honeypot input.
+
+## InfoTip
+
+Any field can include an `infotip` prop to provide additional context to users.
+
+### Automatic labelling
+
+InfoTip buttons are automatically labelled by string field labels for accessibility.
+
+
+
+### ReactNode labels
+
+For ReactNode labels, you have three options:
+
+- `labelledByFieldLabel: true` - opt into automatic labelling by the field label
+- `ariaLabel` - provide a custom accessible name
+- `ariaLabelledby` - reference another element on the page, such as a section heading
+
+
diff --git a/packages/styleguide/src/lib/Organisms/GridForm/Fields.stories.tsx b/packages/styleguide/src/lib/Organisms/GridForm/Fields.stories.tsx
index 40ecc134b0..03c2a4e73f 100644
--- a/packages/styleguide/src/lib/Organisms/GridForm/Fields.stories.tsx
+++ b/packages/styleguide/src/lib/Organisms/GridForm/Fields.stories.tsx
@@ -1,4 +1,4 @@
-import { FormGroup, GridForm, Input } from '@codecademy/gamut';
+import { FormGroup, GridForm, Input, Text } from '@codecademy/gamut';
import { action } from '@storybook/addon-actions';
import type { Meta, StoryObj } from '@storybook/react';
@@ -328,3 +328,75 @@ export const SweetContainer: Story = {
],
},
};
+
+/**
+ * InfoTip buttons are automatically labelled by string field labels for accessibility.
+ * Screen readers will announce "Field Label, button" when focusing the InfoTip.
+ */
+export const InfoTipAutoLabelling: Story = {
+ args: {
+ fields: [
+ {
+ label: 'Email address',
+ name: 'email',
+ size: 9,
+ type: 'email',
+ infotip: {
+ info: 'We will never share your email with third parties.',
+ placement: 'floating',
+ },
+ },
+ ],
+ },
+};
+
+/**
+ * For ReactNode labels, you have three options for accessible InfoTip labelling:
+ * - `labelledByFieldLabel: true` - uses the field label
+ * - `ariaLabel` - provides a custom accessible name
+ * - `ariaLabelledby` - references another element on the page
+ */
+export const InfoTipWithReactNodeLabel: Story = {
+ render: (args) => (
+ <>
+
+ API Configuration
+
+
+ >
+ ),
+ args: {
+ fields: [
+ {
+ label: Username (labelledByFieldLabel),
+ name: 'username',
+ size: 9,
+ type: 'text',
+ infotip: {
+ info: 'Choose a unique username between 3-20 characters.',
+ labelledByFieldLabel: true,
+ },
+ },
+ {
+ label: Password (ariaLabel),
+ name: 'password',
+ size: 9,
+ type: 'password',
+ infotip: {
+ info: 'Password must be at least 8 characters with one uppercase letter and one number.',
+ ariaLabel: 'Password requirements',
+ },
+ },
+ {
+ label: API Key (ariaLabelledby),
+ name: 'apiKey',
+ size: 9,
+ type: 'text',
+ infotip: {
+ info: 'You can find your API key in the developer settings dashboard.',
+ ariaLabelledby: 'api-section-heading',
+ },
+ },
+ ],
+ },
+};
diff --git a/packages/styleguide/src/lib/Organisms/GridForm/Layout.mdx b/packages/styleguide/src/lib/Organisms/GridForm/Layout.mdx
index 0c1ac337c0..44f9aba287 100644
--- a/packages/styleguide/src/lib/Organisms/GridForm/Layout.mdx
+++ b/packages/styleguide/src/lib/Organisms/GridForm/Layout.mdx
@@ -34,7 +34,7 @@ Solo field form should always have their solo input be required. They should aut
## InfoTips
-A field can include our existing `InfoTip`. See the InfoTip story for more information on what props are available.
+A field can include our existing `InfoTip`. See the Fields story for specific accessibility tooling and InfoTip story for more information on what props are available.
See the Radio story for an example of how to add a infotip to a radio option.