@codecademy/styleguide 78.5.6-alpha.abebfb.0 → 78.5.6-alpha.ce723a.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.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ### [78.5.6-alpha.abebfb.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.5...@codecademy/styleguide@78.5.6-alpha.abebfb.0) (2026-01-20)
6
+ ### [78.5.6-alpha.ce723a.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.5...@codecademy/styleguide@78.5.6-alpha.ce723a.0) (2026-01-26)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/styleguide
9
9
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@codecademy/styleguide",
3
3
  "description": "Styleguide & Component library for codecademy.com",
4
- "version": "78.5.6-alpha.abebfb.0",
4
+ "version": "78.5.6-alpha.ce723a.0",
5
5
  "author": "Codecademy Engineering",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
10
  "repository": "git@github.com:Codecademy/gamut.git",
11
- "gitHead": "bb48e953c9bd7f75ef8f34e6f61d19b40db48901"
11
+ "gitHead": "94d68b577f706e7cef78c2045545e3350b492526"
12
12
  }
@@ -69,6 +69,12 @@ A field can include <LinkTo id="Molecules/Tips/InfoTip"> our existing `InfoTip`<
69
69
 
70
70
  <Canvas of={FormGroupStories.HighEmphasisInfoTip} />
71
71
 
72
+ #### Accessibility
73
+
74
+ InfoTip buttons are automatically labelled by string field labels for accessibility - you can override this behaviour if needed by passing `ariaLabel` or `ariaLabelledBy` to the field's `InfoTip` via the `infoTipProps` object.
75
+
76
+ <Canvas of={FormGroupStories.InfoTipAutoLabelling} />
77
+
72
78
  ## Playground
73
79
 
74
80
  <Canvas sourceState="shown" of={FormGroupStories.Default} />
@@ -1,4 +1,4 @@
1
- import { FormGroup, Input } from '@codecademy/gamut';
1
+ import { Box, FormGroup, Input } from '@codecademy/gamut';
2
2
  import type { Meta, StoryObj } from '@storybook/react';
3
3
  import type { TypeWithDeepControls } from 'storybook-addon-deep-controls';
4
4
 
@@ -6,9 +6,7 @@ import { infotipNestedArgTypes } from '~styleguide/argTypes';
6
6
 
7
7
  const meta: TypeWithDeepControls<Meta<typeof FormGroup>> = {
8
8
  component: FormGroup,
9
- argTypes: {
10
- ...infotipNestedArgTypes,
11
- },
9
+ argTypes: { ...infotipNestedArgTypes },
12
10
  };
13
11
 
14
12
  export default meta;
@@ -97,3 +95,46 @@ export const HighEmphasisInfoTip: Story = {
97
95
  children: <Input />,
98
96
  },
99
97
  };
98
+
99
+ const InfoTipLabellingExamples = () => {
100
+ return (
101
+ <Box display="flex" flexDirection="column" gap={32}>
102
+ <FormGroup
103
+ htmlFor="auto-label-input"
104
+ infotip={{
105
+ info: 'We will never share your email with third parties.',
106
+ }}
107
+ label="Auto-labelling (default)"
108
+ >
109
+ <Input htmlFor="auto-label-input" type="email" />
110
+ </FormGroup>
111
+
112
+ <FormGroup
113
+ htmlFor="aria-label-input"
114
+ infotip={{
115
+ ariaLabel: 'Email privacy information',
116
+ info: 'We will never share your email with third parties.',
117
+ }}
118
+ label="With ariaLabel"
119
+ >
120
+ <Input htmlFor="aria-label-input" type="email" />
121
+ </FormGroup>
122
+
123
+ <FormGroup
124
+ htmlFor="aria-labelledby-input"
125
+ infotip={{
126
+ ariaLabelledby: 'custom-label-id',
127
+ info: 'We will never share your email with third parties.',
128
+ }}
129
+ label="With ariaLabelledBy"
130
+ >
131
+ <span id="custom-label-id">Custom label for InfoTip button</span>
132
+ <Input htmlFor="aria-labelledby-input" type="email" />
133
+ </FormGroup>
134
+ </Box>
135
+ );
136
+ };
137
+
138
+ export const InfoTipAutoLabelling: Story = {
139
+ render: () => <InfoTipLabellingExamples />,
140
+ };
@@ -58,6 +58,14 @@ The `label` is a `ReactNode`, making it customizable outside of a standard text
58
58
 
59
59
  <Canvas of={RadioStories.CustomLabel} />
60
60
 
61
+ ## RadioGroup with InfoTip
62
+
63
+ You can add an InfoTip to a RadioGroup label by wrapping the `RadioGroup` with a `FormGroup` and passing the `infotip` prop. The InfoTip will be automatically linked to the RadioGroup label via `aria-labelledby` for accessibility.
64
+
65
+ Individual Radio options can also have their own InfoTips, which are automatically linked to their respective labels.
66
+
67
+ <Canvas of={RadioStories.RadioGroupWithInfoTips} />
68
+
61
69
  ## Playground
62
70
 
63
71
  <Canvas sourceState="shown" of={RadioStories.Default} />
@@ -1,4 +1,4 @@
1
- import { Radio, RadioGroup } from '@codecademy/gamut';
1
+ import { FormGroup, Radio, RadioGroup } from '@codecademy/gamut';
2
2
  import type { Meta, StoryObj } from '@storybook/react';
3
3
  import type { TypeWithDeepControls } from 'storybook-addon-deep-controls';
4
4
 
@@ -25,13 +25,47 @@ export const Default: Story = {
25
25
 
26
26
  export const RadioGroupComponent: Story = {
27
27
  render: () => (
28
- <RadioGroup htmlForPrefix="example-radio">
29
- <Radio htmlFor="example-radio" label="Radio 1" name="example-radio-1" />
30
- <Radio htmlFor="example-radio" label="Radio 2" name="example-radio-2" />
28
+ <RadioGroup htmlForPrefix="example-radio" name="example-radio">
29
+ <Radio label="Radio 1" />
30
+ <Radio label="Radio 2" />
31
31
  </RadioGroup>
32
32
  ),
33
33
  };
34
34
 
35
+ export const RadioGroupWithInfoTips: Story = {
36
+ render: () => (
37
+ <FormGroup
38
+ htmlFor="example-radio-infotip"
39
+ infotip={{
40
+ info: 'This InfoTip is linked to the RadioGroup label. Individual options can also have their own InfoTips.',
41
+ placement: 'floating',
42
+ }}
43
+ label="Select an option"
44
+ width="fit-content"
45
+ >
46
+ <RadioGroup
47
+ htmlForPrefix="example-radio-infotip"
48
+ name="example-radio-infotip"
49
+ >
50
+ <Radio
51
+ infotip={{
52
+ info: 'This option includes additional information about the choice.',
53
+ placement: 'floating',
54
+ }}
55
+ label="Option with InfoTip"
56
+ />
57
+ <Radio
58
+ infotip={{
59
+ info: 'Each radio option can have its own InfoTip for context.',
60
+ }}
61
+ label="Another option"
62
+ />
63
+ <Radio label="Option without InfoTip" />
64
+ </RadioGroup>
65
+ </FormGroup>
66
+ ),
67
+ };
68
+
35
69
  export const Checked: Story = {
36
70
  args: {
37
71
  htmlFor: 'example-checked',
@@ -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
  };
@@ -1,9 +1,7 @@
1
- import { DetailedCode } from '@codecademy/gamut';
2
1
  import { Canvas, Controls, Meta } from '@storybook/blocks';
3
2
 
4
3
  import { ComponentHeader, LinkTo } from '~styleguide/blocks';
5
4
 
6
- import { codeExample } from './codeExample';
7
5
  import * as ConnectedFormStories from './ConnectedForm.stories';
8
6
 
9
7
  export const parameters = {
@@ -42,7 +40,75 @@ This hook also returns the `FormRequiredText` component - include this before yo
42
40
 
43
41
  ### Example code
44
42
 
45
- <DetailedCode language="tsx" code={codeExample} preview />
43
+ ```tsx
44
+ import {
45
+ ConnectedCheckbox,
46
+ ConnectedInput,
47
+ ConnectedSelect,
48
+ useConnectedForm,
49
+ } from '@codecademy/gamut';
50
+
51
+ import { TerminalIcon } from '@codecademy/gamut-icons';
52
+
53
+ export const GoodForm = () => {
54
+ const {
55
+ ConnectedFormGroup,
56
+ ConnectedForm,
57
+ connectedFormProps,
58
+ FormRequiredText,
59
+ } = useConnectedForm({
60
+ defaultValues: {
61
+ thisField: true,
62
+ thatField: 'zero',
63
+ anotherField: 'state your name.',
64
+ },
65
+ validationRules: {
66
+ thisField: { required: 'you need to check this.' },
67
+ thatField: {
68
+ pattern: {
69
+ value: /^(?:(?!zero).)*$/,
70
+ message: 'literally anything but zero',
71
+ },
72
+ },
73
+ },
74
+ });
75
+
76
+ return (
77
+ <ConnectedForm
78
+ onSubmit={({ thisField }) => console.log(thisField)}
79
+ resetOnSubmit
80
+ {...connectedFormProps}
81
+ >
82
+ <SubmitButton>submit this form.</SubmitButton>
83
+ <ConnectedFormGroup
84
+ name="thisField"
85
+ label="cool checkbox bruh"
86
+ field={{
87
+ component: ConnectedCheckbox,
88
+ label: 'check it ouuut',
89
+ }}
90
+ />
91
+ <ConnectedFormGroup
92
+ name="thatField"
93
+ label="cool select dude"
94
+ field={{
95
+ component: ConnectedSelect,
96
+ options: ['one', 'two', 'zero'],
97
+ }}
98
+ />
99
+ <ConnectedFormGroup
100
+ name="anotherField"
101
+ label="cool input"
102
+ field={{
103
+ component: ConnectedInput,
104
+ icon: TerminalIcon,
105
+ }}
106
+ />
107
+ <FormRequiredText />
108
+ </ConnectedForm>
109
+ );
110
+ };
111
+ ```
46
112
 
47
113
  ## Variants
48
114
 
@@ -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
 
@@ -1,67 +0,0 @@
1
- export const codeExample = `import {
2
- ConnectedCheckbox,
3
- ConnectedInput,
4
- ConnectedSelect,
5
- useConnectedForm,
6
- } from '@codecademy/gamut';
7
-
8
- import { TerminalIcon } from '@codecademy/gamut-icons';
9
-
10
- export const GoodForm = () => {
11
- const {
12
- ConnectedFormGroup,
13
- ConnectedForm,
14
- connectedFormProps,
15
- FormRequiredText,
16
- } = useConnectedForm({
17
- defaultValues: {
18
- thisField: true,
19
- thatField: 'zero',
20
- anotherField: 'state your name.',
21
- },
22
- validationRules: {
23
- thisField: { required: 'you need to check this.' },
24
- thatField: {
25
- pattern: {
26
- value: /^(?:(?!zero).)*$/,
27
- message: 'literally anything but zero',
28
- },
29
- },
30
- },
31
- });
32
-
33
- return (
34
- <ConnectedForm
35
- onSubmit={({ thisField }) => console.log(thisField)}
36
- resetOnSubmit
37
- {...connectedFormProps}
38
- >
39
- <SubmitButton>submit this form.</SubmitButton>
40
- <ConnectedFormGroup
41
- name="thisField"
42
- label="cool checkbox bruh"
43
- field={{
44
- component: ConnectedCheckbox,
45
- label: 'check it ouuut',
46
- }}
47
- />
48
- <ConnectedFormGroup
49
- name="thatField"
50
- label="cool select dude"
51
- field={{
52
- component: ConnectedSelect,
53
- options: ['one', 'two', 'zero'],
54
- }}
55
- />
56
- <ConnectedFormGroup
57
- name="anotherField"
58
- label="cool input"
59
- field={{
60
- component: ConnectedInput,
61
- icon: TerminalIcon,
62
- }}
63
- />
64
- <FormRequiredText />
65
- </ConnectedForm>
66
- );
67
- };`;