@codecademy/styleguide 79.3.0 → 79.3.1-alpha.b86be7.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,6 +3,10 @@
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
+ ### [79.3.1-alpha.b86be7.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.3.0...@codecademy/styleguide@79.3.1-alpha.b86be7.0) (2026-03-26)
7
+
8
+ **Note:** Version bump only for package @codecademy/styleguide
9
+
6
10
  ## [79.3.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.2.4...@codecademy/styleguide@79.3.0) (2026-03-25)
7
11
 
8
12
  ### Features
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": "79.3.0",
4
+ "version": "79.3.1-alpha.b86be7.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": "502f9c61b71cb0479cbe5ff3bcd7301041a3c3bd"
11
+ "gitHead": "aa78e52978cd3015734650b0fca3848081cbd742"
12
12
  }
@@ -23,6 +23,8 @@ export const parameters = {
23
23
 
24
24
  <ComponentHeader {...parameters} />
25
25
 
26
+ <Canvas sourceState="shown" of={TextAreaStories.AutoGrow} />
27
+
26
28
  ## Usage
27
29
 
28
30
  Use TextArea to handle long form text entry within forms.
@@ -31,7 +33,6 @@ Use TextArea to handle long form text entry within forms.
31
33
 
32
34
  ### Disabled
33
35
 
34
- <Canvas of={TextAreaStories.Disabled} />
35
36
 
36
37
  ### Error
37
38
 
@@ -1,5 +1,66 @@
1
- import { TextArea } from '@codecademy/gamut';
1
+ import { Box, TextArea } from '@codecademy/gamut';
2
+ import { css } from '@codecademy/gamut-styles';
3
+ import styled from '@emotion/styled';
2
4
  import type { Meta, StoryObj } from '@storybook/react';
5
+ import {
6
+ type ChangeEvent,
7
+ type ComponentProps,
8
+ useCallback,
9
+ useLayoutEffect,
10
+ useRef,
11
+ } from 'react';
12
+
13
+ /**
14
+ * `field-sizing: content` lets the textarea grow with its value in Chromium and Safari.
15
+ * Firefox does not support it yet; we mirror that behavior by syncing height to scrollHeight.
16
+ *
17
+ * Note: A single-line `<input>` cannot expand vertically—use `<textarea>` for multi-line text.
18
+ */
19
+ const fieldSizingContentSupported =
20
+ typeof CSS !== 'undefined' && CSS.supports('field-sizing', 'content');
21
+
22
+ const AutoGrowTextAreaBase = styled(TextArea)(
23
+ css({
24
+ resize: 'none',
25
+ overflow: 'hidden',
26
+ // Static CSS — not a Gamut system prop; merged by variance `css()` as passthrough.
27
+ fieldSizing: 'content',
28
+ })
29
+ );
30
+
31
+ const AutoGrowTextArea = (props: ComponentProps<typeof TextArea>) => {
32
+ const ref = useRef<HTMLTextAreaElement>(null);
33
+ const { onChange, value, ...rest } = props;
34
+
35
+ const syncHeight = useCallback(() => {
36
+ if (fieldSizingContentSupported) return;
37
+ const el = ref.current;
38
+ if (!el) return;
39
+ el.style.height = 'auto';
40
+ el.style.height = `${el.scrollHeight}px`;
41
+ }, []);
42
+
43
+ useLayoutEffect(() => {
44
+ syncHeight();
45
+ }, [syncHeight, value]);
46
+
47
+ const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
48
+ onChange?.(event);
49
+ requestAnimationFrame(syncHeight);
50
+ };
51
+
52
+ return (
53
+ <Box height="1000px">
54
+ <AutoGrowTextAreaBase
55
+ {...rest}
56
+ ref={ref}
57
+ rows={rest.rows ?? 1}
58
+ {...(value !== undefined ? { value } : {})}
59
+ onChange={handleChange}
60
+ />
61
+ </Box>
62
+ );
63
+ };
3
64
 
4
65
  const meta: Meta<typeof TextArea> = {
5
66
  component: TextArea,
@@ -38,3 +99,15 @@ export const Placeholder: Story = {
38
99
  defaultValue: undefined,
39
100
  },
40
101
  };
102
+
103
+ export const AutoGrow: Story = {
104
+ args: {
105
+ htmlFor: 'example-autogrow',
106
+ name: 'example-autogrow',
107
+ placeholder: 'Type multiple lines — the field grows vertically',
108
+ defaultValue:
109
+ 'Line one\nLine two\nLine three\n\nFirefox uses scrollHeight; Chromium/Safari use field-sizing: content.',
110
+ rows: 1,
111
+ },
112
+ render: (args) => <AutoGrowTextArea {...args} />,
113
+ };