@codecademy/styleguide 78.5.6-alpha.fb9da9.0 → 79.0.1-alpha.2b3284.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.storybook/components/Elements/Markdown.tsx +1 -0
  2. package/CHANGELOG.md +11 -1
  3. package/package.json +2 -2
  4. package/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx +6 -0
  5. package/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx +45 -4
  6. package/src/lib/Atoms/FormInputs/Checkbox/Checkbox.mdx +7 -1
  7. package/src/lib/Atoms/FormInputs/Checkbox/Checkbox.stories.tsx +21 -1
  8. package/src/lib/Atoms/FormInputs/Radio/Radio.mdx +8 -0
  9. package/src/lib/Atoms/FormInputs/Radio/Radio.stories.tsx +38 -4
  10. package/src/lib/Foundations/System/About.mdx +1 -1
  11. package/src/lib/Foundations/System/Props.mdx +230 -0
  12. package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.mdx +3 -3
  13. package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.stories.tsx +0 -1
  14. package/src/lib/Foundations/shared/elements.tsx +4 -16
  15. package/src/lib/Layouts/Boxes/Box/Box.stories.tsx +0 -1
  16. package/src/lib/Molecules/Popover/Popover.stories.tsx +127 -4
  17. package/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx +24 -8
  18. package/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx +86 -34
  19. package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx +19 -0
  20. package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx +73 -0
  21. package/src/lib/Organisms/GridForm/Fields.mdx +19 -0
  22. package/src/lib/Organisms/GridForm/Fields.stories.tsx +62 -1
  23. package/src/lib/Organisms/GridForm/Layout.mdx +1 -1
  24. package/src/lib/Foundations/System/Props/About.mdx +0 -81
  25. package/src/lib/Foundations/System/Props/Background.mdx +0 -30
  26. package/src/lib/Foundations/System/Props/Border.mdx +0 -33
  27. package/src/lib/Foundations/System/Props/Color.mdx +0 -28
  28. package/src/lib/Foundations/System/Props/Flex.mdx +0 -28
  29. package/src/lib/Foundations/System/Props/Grid.mdx +0 -31
  30. package/src/lib/Foundations/System/Props/Layout.mdx +0 -34
  31. package/src/lib/Foundations/System/Props/List.mdx +0 -38
  32. package/src/lib/Foundations/System/Props/Positioning.mdx +0 -29
  33. package/src/lib/Foundations/System/Props/Shadow.mdx +0 -31
  34. package/src/lib/Foundations/System/Props/Space.mdx +0 -28
  35. package/src/lib/Foundations/System/Props/Typography.mdx +0 -28
@@ -8,7 +8,7 @@ import {
8
8
  } from '@codecademy/gamut';
9
9
  import * as patterns from '@codecademy/gamut-patterns';
10
10
  import type { Meta, StoryObj } from '@storybook/react';
11
- import { useRef, useState } from 'react';
11
+ import { useCallback, useEffect, useRef, useState } from 'react';
12
12
 
13
13
  const meta: Meta<typeof Popover> = {
14
14
  component: Popover,
@@ -27,10 +27,91 @@ type Story = StoryObj<typeof Popover>;
27
27
 
28
28
  type PopoverExampleProps = PopoverProps & Pick<FlexBoxProps, 'p'>;
29
29
 
30
- const PopoverExample = ({ p = 16, ...rest }: PopoverExampleProps) => {
30
+ const POPOVER_HEIGHT_ESTIMATE = 200; // Estimate for flip calculation
31
+ const VIEWPORT_PADDING = 16; // Padding from viewport edge
32
+
33
+ const PopoverExample = ({
34
+ p = 16,
35
+ position: preferredPosition = 'below',
36
+ ...rest
37
+ }: PopoverExampleProps) => {
31
38
  const [open, setOpen] = useState(false);
39
+ const [computedPosition, setComputedPosition] = useState<
40
+ 'above' | 'below' | 'center'
41
+ >(preferredPosition === 'center' ? 'center' : preferredPosition);
42
+ const [availableHeight, setAvailableHeight] = useState<number | undefined>(
43
+ undefined
44
+ );
32
45
  const activeElRef = useRef<HTMLDivElement>(null);
46
+ const popoverRef = useRef<HTMLDivElement>(null);
47
+ const [popoverHeight, setPopoverHeight] = useState(POPOVER_HEIGHT_ESTIMATE);
48
+
49
+ const calculatePosition = useCallback(() => {
50
+ const target = activeElRef.current;
51
+ if (!target || preferredPosition === 'center') return;
52
+
53
+ const targetRect = target.getBoundingClientRect();
54
+ const viewportHeight = window.innerHeight;
55
+
56
+ const spaceBelow = viewportHeight - targetRect.bottom - VIEWPORT_PADDING;
57
+ const spaceAbove = targetRect.top - VIEWPORT_PADDING;
58
+
59
+ // Use measured height if available, otherwise estimate
60
+ const heightToFit = popoverHeight;
61
+
62
+ let newPosition: 'above' | 'below' =
63
+ preferredPosition === 'above' ? 'above' : 'below';
64
+
65
+ if (preferredPosition === 'below') {
66
+ // Prefer below, but flip to above if not enough space below and more space above
67
+ if (spaceBelow < heightToFit && spaceAbove > spaceBelow) {
68
+ newPosition = 'above';
69
+ } else {
70
+ newPosition = 'below';
71
+ }
72
+ } else if (preferredPosition === 'above') {
73
+ // Prefer above, but flip to below if not enough space above and more space below
74
+ if (spaceAbove < heightToFit && spaceBelow > spaceAbove) {
75
+ newPosition = 'below';
76
+ } else {
77
+ newPosition = 'above';
78
+ }
79
+ }
80
+
81
+ setComputedPosition(newPosition);
82
+
83
+ // Set max height based on the available space in the computed direction
84
+ const maxAvailableHeight = newPosition === 'below' ? spaceBelow : spaceAbove;
85
+ setAvailableHeight(Math.max(maxAvailableHeight, 100)); // Minimum 100px
86
+ }, [preferredPosition, popoverHeight]);
87
+
88
+ // Measure popover height when it opens
89
+ useEffect(() => {
90
+ if (open && popoverRef.current) {
91
+ const { height } = popoverRef.current.getBoundingClientRect();
92
+ if (height > 0) {
93
+ setPopoverHeight(height);
94
+ }
95
+ }
96
+ }, [open]);
97
+
98
+ // Recalculate position on open, scroll, or resize
99
+ useEffect(() => {
100
+ if (!open) return;
101
+
102
+ calculatePosition();
103
+
104
+ window.addEventListener('scroll', calculatePosition, true);
105
+ window.addEventListener('resize', calculatePosition);
106
+
107
+ return () => {
108
+ window.removeEventListener('scroll', calculatePosition, true);
109
+ window.removeEventListener('resize', calculatePosition);
110
+ };
111
+ }, [open, calculatePosition]);
112
+
33
113
  const toggleOpen = () => setOpen(!open);
114
+
34
115
  return (
35
116
  <>
36
117
  <Box ref={activeElRef} width="fit-content">
@@ -40,11 +121,53 @@ const PopoverExample = ({ p = 16, ...rest }: PopoverExampleProps) => {
40
121
  <Popover
41
122
  {...(rest as any)}
42
123
  isOpen={open}
124
+ popoverContainerRef={popoverRef}
125
+ position={computedPosition}
43
126
  targetRef={activeElRef}
44
127
  onRequestClose={() => setOpen(false)}
45
128
  >
46
- <FlexBox alignItems="flex-start" flexDirection="column" p={p}>
47
- <Box mb={8}>Hooray!</Box>
129
+ {/*
130
+ Apply maxHeight and overflow to the content wrapper.
131
+ This makes the popover contents scrollable when they exceed
132
+ the available viewport space.
133
+ */}
134
+ <FlexBox
135
+ alignItems="flex-start"
136
+ flexDirection="column"
137
+ p={p}
138
+ maxHeight={availableHeight ? `${availableHeight}px` as any : undefined}
139
+ overflowY="auto"
140
+ >
141
+ <Box mb={8}>
142
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
143
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
144
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
145
+ nisi ut aliquip ex ea commodo consequat.
146
+ </Box>
147
+ <Box mb={8}>
148
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
149
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
150
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
151
+ nisi ut aliquip ex ea commodo consequat.
152
+ </Box>
153
+ <Box mb={8}>
154
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
155
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
156
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
157
+ nisi ut aliquip ex ea commodo consequat.
158
+ </Box>
159
+ <Box mb={8}>
160
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
161
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
162
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
163
+ nisi ut aliquip ex ea commodo consequat.
164
+ </Box>
165
+ <Box mb={8} opacity={0.7}>
166
+ Position: {computedPosition}
167
+ {computedPosition !== preferredPosition && ' (flipped!)'}
168
+ {' | '}
169
+ Max height: {availableHeight ? `${Math.round(availableHeight)}px` : 'auto'}
170
+ </Box>
48
171
  <FillButton size="small" onClick={() => setOpen(false)}>
49
172
  Close Popover
50
173
  </FillButton>
@@ -28,8 +28,7 @@ export const parameters = {
28
28
  A tip is triggered by clicking on an information icon button and can be closed by clicking outside, pressing <KeyboardKey>Esc</KeyboardKey>, or clicking the info button again.
29
29
 
30
30
  Use an infotip to provide additional info about a nearby element or content.
31
-
32
- 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.
31
+ The info button has low and high emphasis variants and the `Tip` has 4 alignment variants.
33
32
 
34
33
  ## Variants
35
34
 
@@ -57,17 +56,19 @@ This `floating` variant should only be used as needed.
57
56
 
58
57
  ### InfoTips with links or buttons
59
58
 
60
- 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.
59
+ 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.
61
60
 
62
61
  <Canvas of={InfoTipStories.WithLinksOrButtons} />
63
62
 
64
- ### Floating placement
63
+ ### Automatic Focus Management
65
64
 
66
- When using `placement="floating"`, InfoTips implements focus management for easier navigation:
65
+ InfoTips automatically manage focus for optimal keyboard accessibility:
67
66
 
68
- - **<KeyboardKey>Tab</KeyboardKey>**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button for convenience
69
- - **<KeyboardKey>Shift</KeyboardKey>+<KeyboardKey>Tab</KeyboardKey>**: Navigate backward naturally through the page
70
- - **<KeyboardKey>Esc</KeyboardKey>**: Closes the tip and returns focus to the InfoTip button
67
+ - **Opening**: Focus automatically moves to the tip content when opened
68
+ - ** <KeyboardKey>Tab</KeyboardKey> (Floating)**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button
69
+ - **<KeyboardKey>Shift </KeyboardKey> + <KeyboardKey>Tab</KeyboardKey> (Floating)**: Navigate backward naturally - from the button, exits to the previous page element
70
+ - **<KeyboardKey>Tab</KeyboardKey> or <KeyboardKey>Shift</KeyboardKey> +<KeyboardKey>Tab</KeyboardKey> (Inline)**: Follows normal document flow
71
+ - **<KeyboardKey>Escape</KeyboardKey>**: Closes the tip and returns focus to the InfoTip button
71
72
 
72
73
  <Canvas of={InfoTipStories.KeyboardNavigation} />
73
74
 
@@ -82,6 +83,21 @@ InfoTips have intelligent Escape key handling that works correctly both inside a
82
83
 
83
84
  <Canvas of={InfoTipStories.InfoTipInsideModal} />
84
85
 
86
+ ## Custom Accessible Labeling
87
+
88
+ Provide either `ariaLabel` or `ariaLabelledby` to ensure screen reader users understand the purpose of the InfoTip button.
89
+
90
+ The InfoTip button's accessible label can be customized using either prop:
91
+
92
+ - **`ariaLabel`**: Directly sets the accessible label text. Useful when you want to provide a custom label without referencing another element.
93
+ - **`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.
94
+
95
+ ### Custom Role Description
96
+
97
+ 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.
98
+
99
+ <Canvas of={InfoTipStories.AriaLabel} />
100
+
85
101
  ## InfoTips and zIndex
86
102
 
87
103
  You can change the zIndex of your `InfoTip` with the zIndex property.
@@ -4,17 +4,20 @@ import {
4
4
  FillButton,
5
5
  FlexBox,
6
6
  GridBox,
7
+ IconButton,
7
8
  InfoTip,
8
9
  Modal,
9
10
  Text,
10
11
  } from '@codecademy/gamut';
12
+ import { SparkleIcon } from '@codecademy/gamut-icons';
11
13
  import type { Meta, StoryObj } from '@storybook/react';
12
- import { useRef, useState } from 'react';
14
+ import { useState } from 'react';
13
15
 
14
16
  const meta: Meta<typeof InfoTip> = {
15
17
  component: InfoTip,
16
18
  args: {
17
19
  alignment: 'top-left',
20
+ ariaLabel: 'More information',
18
21
  info: `I am additional information about a nearby element or content.`,
19
22
  },
20
23
  };
@@ -28,7 +31,10 @@ export const Emphasis: Story = {
28
31
  },
29
32
  render: (args) => (
30
33
  <FlexBox center m={24} py={64}>
31
- <Text mr={4}>Some text that needs info</Text> <InfoTip {...args} />
34
+ <Text id="emphasis-text" mr={4}>
35
+ Some text that needs info
36
+ </Text>
37
+ <InfoTip {...args} ariaLabelledby="emphasis-text" />
32
38
  </FlexBox>
33
39
  ),
34
40
  };
@@ -38,10 +44,15 @@ export const Alignments: Story = {
38
44
  <GridBox gap={24} gridTemplateColumns="1fr 1fr" ml={8} py={64}>
39
45
  {(['top-right', 'top-left', 'bottom-right', 'bottom-left'] as const).map(
40
46
  (alignment) => {
47
+ const labelId = `alignment-${alignment}`;
41
48
  return (
42
49
  <Box key={alignment}>
43
- <Text>{alignment}</Text>
44
- <InfoTip {...args} alignment={alignment} />
50
+ <Text id={labelId}>{alignment}</Text>
51
+ <InfoTip
52
+ {...args}
53
+ alignment={alignment}
54
+ ariaLabelledby={labelId}
55
+ />
45
56
  </Box>
46
57
  );
47
58
  }
@@ -56,10 +67,51 @@ export const Placement: Story = {
56
67
  },
57
68
  render: (args) => (
58
69
  <FlexBox center>
59
- <Text mr={4}>
70
+ <Text id="placement-text" mr={4}>
60
71
  This text is in a small space and needs floating placement
61
72
  </Text>{' '}
62
- <InfoTip {...args} />
73
+ <InfoTip {...args} ariaLabelledby="placement-text" />
74
+ </FlexBox>
75
+ ),
76
+ };
77
+
78
+ export const AriaLabel: Story = {
79
+ render: (args) => (
80
+ <FlexBox center column gap={24} my={48} width={1}>
81
+ <FlexBox alignItems="center" gap={8}>
82
+ <Text fontSize={16} fontWeight="bold">
83
+ Using ariaLabel (no visible label text):
84
+ </Text>
85
+ </FlexBox>
86
+ <FlexBox alignItems="center" gap={8}>
87
+ <IconButton
88
+ icon={SparkleIcon}
89
+ tip="This tool needs to be explained in the InfoTip"
90
+ tipProps={{ placement: 'floating' }}
91
+ onClick={() => null}
92
+ />
93
+ <InfoTip
94
+ {...args}
95
+ ariaLabel="Learn more about this tool"
96
+ info="This is some helpful info about the tool represented by the IconButton"
97
+ />
98
+ </FlexBox>
99
+
100
+ <FlexBox alignItems="center" gap={8}>
101
+ <Text fontSize={16} fontWeight="bold">
102
+ Using ariaLabelledby (references visible text):
103
+ </Text>
104
+ </FlexBox>
105
+ <FlexBox alignItems="center" gap={8}>
106
+ <Text id="custom-info-id">
107
+ I am some helpful yet concise text that needs more explanation
108
+ </Text>
109
+ <InfoTip
110
+ alignment="bottom-left"
111
+ ariaLabelledby="custom-info-id"
112
+ info="I am clarifying information related to the concise text."
113
+ />
114
+ </FlexBox>
63
115
  </FlexBox>
64
116
  ),
65
117
  };
@@ -69,19 +121,16 @@ export const WithLinksOrButtons: Story = {
69
121
  placement: 'floating',
70
122
  },
71
123
  render: function WithLinksOrButtons(args) {
72
- const ref = useRef<HTMLDivElement>(null);
73
-
74
- const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
75
- if (!isTipHidden) ref.current?.focus();
76
- };
77
-
78
124
  return (
79
125
  <FlexBox center py={64}>
80
- <Text mr={4}>This text is in a small space and needs info </Text>{' '}
126
+ <Text id="links-text" mr={4}>
127
+ This text is in a small space and needs info
128
+ </Text>{' '}
81
129
  <InfoTip
82
130
  {...args}
131
+ ariaLabelledby="links-text"
83
132
  info={
84
- <Text ref={ref} tabIndex={-1}>
133
+ <Text tabIndex={-1}>
85
134
  Hey! Here is a{' '}
86
135
  <Anchor href="https://giphy.com/search/nichijou">
87
136
  cool link
@@ -93,7 +142,6 @@ export const WithLinksOrButtons: Story = {
93
142
  that is also super important.
94
143
  </Text>
95
144
  }
96
- onClick={onClick}
97
145
  />
98
146
  </FlexBox>
99
147
  );
@@ -102,42 +150,35 @@ export const WithLinksOrButtons: Story = {
102
150
 
103
151
  export const KeyboardNavigation: Story = {
104
152
  render: function KeyboardNavigation() {
105
- const floatingRef = useRef<HTMLDivElement>(null);
106
- const inlineRef = useRef<HTMLDivElement>(null);
107
-
108
153
  const examples = [
109
154
  {
110
155
  title: 'Floating Placement',
111
156
  placement: 'floating' as const,
112
- ref: floatingRef,
113
157
  links: ['Link 1', 'Link 2', 'Link 3'],
114
158
  },
115
159
  {
116
160
  title: 'Inline Placement',
117
161
  placement: 'inline' as const,
118
162
  alignment: 'bottom-right' as const,
119
- ref: inlineRef,
120
163
  links: ['Link A', 'Link B'],
121
164
  },
122
165
  ];
123
166
 
124
167
  return (
125
- <FlexBox center column gap={24} py={64}>
168
+ <FlexBox center flexDirection="column" gap={24} py={64}>
126
169
  <GridBox gap={16} gridTemplateColumns="1fr 1fr">
127
- {examples.map(({ title, placement, alignment, ref, links }) => {
128
- const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
129
- if (!isTipHidden) ref.current?.focus();
130
- };
131
-
170
+ {examples.map(({ title, placement, alignment, links }) => {
171
+ const labelId = `keyboard-nav-${placement}`;
132
172
  return (
133
173
  <FlexBox gap={8} key={placement}>
134
- <Text fontSize={16} fontWeight="bold">
174
+ <Text fontSize={16} fontWeight="bold" id={labelId}>
135
175
  {title}
136
176
  </Text>
137
177
  <InfoTip
138
178
  alignment={alignment}
179
+ ariaLabelledby={labelId}
139
180
  info={
140
- <Text ref={ref} tabIndex={-1}>
181
+ <Text>
141
182
  {links.map((label, idx) => (
142
183
  <>
143
184
  {idx > 0 && ', '}
@@ -150,7 +191,6 @@ export const KeyboardNavigation: Story = {
150
191
  </Text>
151
192
  }
152
193
  placement={placement}
153
- onClick={onClick}
154
194
  />
155
195
  </FlexBox>
156
196
  );
@@ -162,6 +202,10 @@ export const KeyboardNavigation: Story = {
162
202
  Keyboard Navigation:
163
203
  </Text>
164
204
  <Box as="ul" fontSize={14} pl={16}>
205
+ <li>
206
+ <strong>Opening:</strong> Focus automatically moves to the tip
207
+ content when opened
208
+ </li>
165
209
  <li>
166
210
  <strong>Floating - Tab:</strong> Navigates forward through links,
167
211
  then wraps to button (contained)
@@ -224,8 +268,10 @@ export const InfoTipInsideModal: Story = {
224
268
  <Text>This modal contains an InfoTip below:</Text>
225
269
 
226
270
  <FlexBox alignItems="center" gap={8}>
227
- <Text>Some text that needs explanation</Text>
228
- <InfoTip {...args} />
271
+ <Text id="modal-infotip-text">
272
+ Some text that needs explanation
273
+ </Text>
274
+ <InfoTip {...args} ariaLabelledby="modal-infotip-text" />
229
275
  </FlexBox>
230
276
 
231
277
  <Text color="text-disabled" fontSize={14}>
@@ -253,11 +299,14 @@ export const ZIndex: Story = {
253
299
  <Box bg="paleBlue" zIndex={3}>
254
300
  I will not be behind the infotip, sad + unreadable
255
301
  </Box>
256
- <InfoTip info="I am inline, cool" />
302
+ <InfoTip
303
+ ariaLabel="z-index example without override"
304
+ info="I am inline, cool"
305
+ />
257
306
  <Box bg="paleBlue" zIndex={3}>
258
307
  I will be behind the infotip, nice + great
259
308
  </Box>
260
- <InfoTip {...args} />
309
+ <InfoTip {...args} ariaLabel="z-index example with override" />
261
310
  </FlexBox>
262
311
  ),
263
312
  };
@@ -265,7 +314,10 @@ export const ZIndex: Story = {
265
314
  export const Default: Story = {
266
315
  render: (args) => (
267
316
  <FlexBox center m={24} py={64}>
268
- <Text mr={4}>Some text that needs info</Text> <InfoTip {...args} />
317
+ <Text id="default-text" mr={4}>
318
+ Some text that needs info
319
+ </Text>
320
+ <InfoTip {...args} ariaLabelledby="default-text" />
269
321
  </FlexBox>
270
322
  ),
271
323
  };
@@ -61,6 +61,25 @@ A `ConnectedFormGroup` can be in one of three states: `default`, `error`, or `di
61
61
 
62
62
  <Canvas of={ConnectedFormGroupStories.States} />
63
63
 
64
+ ## InfoTip
65
+
66
+ A `ConnectedFormGroup` can include an `infotip` prop to provide additional context.
67
+
68
+ ### Automatic labelling
69
+
70
+ InfoTip buttons are automatically labelled by string field labels for accessibility.
71
+
72
+ <Canvas of={ConnectedFormGroupStories.InfoTipAutoLabelling} />
73
+
74
+ ### ReactNode labels
75
+
76
+ For ReactNode labels (e.g., styled text or icons), the InfoTip is automatically labelled by the field label. You can override this behavior by providing:
77
+
78
+ - `ariaLabel` - provide a custom accessible name
79
+ - `ariaLabelledby` - reference another element on the page, such as a section heading
80
+
81
+ <Canvas of={ConnectedFormGroupStories.InfoTipWithReactNodeLabel} />
82
+
64
83
  ## Playground
65
84
 
66
85
  To see how a `ConnectedFormGroup` can be used in a `ConnectedForm`, check out the <LinkTo id="Organisms/ConnectedForm/ConnectedForm">ConnectedForm</LinkTo> page.
@@ -2,7 +2,9 @@ import {
2
2
  ConnectedForm,
3
3
  ConnectedFormGroup,
4
4
  ConnectedFormGroupProps,
5
+ ConnectedInput,
5
6
  ConnectedRadioGroupInput,
7
+ Text,
6
8
  useConnectedForm,
7
9
  } from '@codecademy/gamut';
8
10
  import { action } from '@storybook/addon-actions';
@@ -119,3 +121,74 @@ export const States = () => {
119
121
  </ConnectedForm>
120
122
  );
121
123
  };
124
+
125
+ export const InfoTipAutoLabelling: Story = {
126
+ render: () => (
127
+ <ConnectedForm
128
+ defaultValues={{ email: '' }}
129
+ onSubmit={(values) => action('Form Submitted')(values)}
130
+ >
131
+ <ConnectedFormGroup
132
+ field={{ component: ConnectedInput, type: 'email' }}
133
+ infotip={{
134
+ info: 'We will never share your email with third parties.',
135
+ placement: 'floating',
136
+ }}
137
+ label="Email address"
138
+ name="email"
139
+ />
140
+ </ConnectedForm>
141
+ ),
142
+ };
143
+
144
+ export const InfoTipWithReactNodeLabel: Story = {
145
+ render: () => (
146
+ <ConnectedForm
147
+ defaultValues={{ username: '', password: '', apiKey: '' }}
148
+ onSubmit={(values) => action('Form Submitted')(values)}
149
+ >
150
+ <Text as="h3" id="api-section-heading" mb={8}>
151
+ API Configuration
152
+ </Text>
153
+ <ConnectedFormGroup
154
+ field={{ component: ConnectedInput }}
155
+ infotip={{
156
+ alignment: 'bottom-left',
157
+ info: 'Choose a unique username between 3-20 characters.',
158
+ }}
159
+ label={
160
+ <Text as="span" fontWeight="bold">
161
+ Username (automatic label)
162
+ </Text>
163
+ }
164
+ name="username"
165
+ />
166
+ <ConnectedFormGroup
167
+ field={{ component: ConnectedInput, type: 'password' }}
168
+ infotip={{
169
+ info: 'Password must be at least 8 characters with one uppercase letter and one number.',
170
+ ariaLabel: 'Password requirements',
171
+ }}
172
+ label={
173
+ <Text as="span" fontWeight="bold">
174
+ Password (ariaLabel)
175
+ </Text>
176
+ }
177
+ name="password"
178
+ />
179
+ <ConnectedFormGroup
180
+ field={{ component: ConnectedInput }}
181
+ infotip={{
182
+ info: 'You can find your API key in the developer settings dashboard.',
183
+ ariaLabelledby: 'api-section-heading',
184
+ }}
185
+ label={
186
+ <Text as="span" fontWeight="bold">
187
+ API Key (ariaLabelledby)
188
+ </Text>
189
+ }
190
+ name="apiKey"
191
+ />
192
+ </ConnectedForm>
193
+ ),
194
+ };
@@ -95,3 +95,22 @@ Hidden inputs can be used to include data that users can't see or modify with th
95
95
  We call it a "sweet container" so that bots do not immediately detect it as a honeypot input.
96
96
 
97
97
  <Canvas of={FieldsStories.SweetContainer} />
98
+
99
+ ## InfoTip
100
+
101
+ Any field can include an `infotip` prop to provide additional context to users.
102
+
103
+ ### Automatic labelling
104
+
105
+ InfoTip buttons are automatically labelled by string field labels for accessibility.
106
+
107
+ <Canvas of={FieldsStories.InfoTipAutoLabelling} />
108
+
109
+ ### ReactNode labels
110
+
111
+ For ReactNode labels, the InfoTip is automatically labelled by the field label. You can override this behavior by providing:
112
+
113
+ - `ariaLabel` - provide a custom accessible name
114
+ - `ariaLabelledby` - reference another element on the page, such as a section heading
115
+
116
+ <Canvas of={FieldsStories.InfoTipWithReactNodeLabel} />
@@ -1,4 +1,4 @@
1
- import { FormGroup, GridForm, Input } from '@codecademy/gamut';
1
+ import { FormGroup, GridForm, Input, Text } from '@codecademy/gamut';
2
2
  import { action } from '@storybook/addon-actions';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
 
@@ -328,3 +328,64 @@ export const SweetContainer: Story = {
328
328
  ],
329
329
  },
330
330
  };
331
+
332
+ export const InfoTipAutoLabelling: Story = {
333
+ args: {
334
+ fields: [
335
+ {
336
+ label: 'Email address',
337
+ name: 'email',
338
+ size: 9,
339
+ type: 'email',
340
+ infotip: {
341
+ info: 'We will never share your email with third parties.',
342
+ placement: 'floating',
343
+ },
344
+ },
345
+ ],
346
+ },
347
+ };
348
+
349
+ export const InfoTipWithReactNodeLabel: Story = {
350
+ render: (args) => (
351
+ <>
352
+ <Text as="h3" id="api-section-heading" mb={8}>
353
+ API Configuration
354
+ </Text>
355
+ <GridForm {...args} />
356
+ </>
357
+ ),
358
+ args: {
359
+ fields: [
360
+ {
361
+ label: <strong>Username (automatic label)</strong>,
362
+ name: 'username',
363
+ size: 9,
364
+ type: 'text',
365
+ infotip: {
366
+ info: 'Choose a unique username between 3-20 characters.',
367
+ },
368
+ },
369
+ {
370
+ label: <strong>Password (ariaLabel)</strong>,
371
+ name: 'password',
372
+ size: 9,
373
+ type: 'password',
374
+ infotip: {
375
+ info: 'Password must be at least 8 characters with one uppercase letter and one number.',
376
+ ariaLabel: 'Password requirements',
377
+ },
378
+ },
379
+ {
380
+ label: <strong>API Key (ariaLabelledby)</strong>,
381
+ name: 'apiKey',
382
+ size: 9,
383
+ type: 'text',
384
+ infotip: {
385
+ info: 'You can find your API key in the developer settings dashboard.',
386
+ ariaLabelledby: 'api-section-heading',
387
+ },
388
+ },
389
+ ],
390
+ },
391
+ };
@@ -34,7 +34,7 @@ Solo field form should always have their solo input be required. They should aut
34
34
 
35
35
  ## InfoTips
36
36
 
37
- A field can include our existing `InfoTip`. See the <LinkTo id="Molecules/Tips/InfoTip">InfoTip</LinkTo> story for more information on what props are available.
37
+ A field can include our existing `InfoTip`. See the <LinkTo id="Molecules/Tips/InfoTip">Fields</LinkTo> story for specific accessibility tooling and <LinkTo id="Molecules/Tips/InfoTip">InfoTip</LinkTo> story for more information on what props are available.
38
38
 
39
39
  See the <LinkTo id="Atoms/FormInputs/Radio">Radio</LinkTo> story for an example of how to add a infotip to a radio option.
40
40