From d2566258ad60f5ffaddcfbda4d5cfffe6f2979dd Mon Sep 17 00:00:00 2001 From: Florian Laabs Date: Mon, 23 Nov 2026 02:59:02 +0100 Subject: [PATCH 1/6] fix(textarea): measure autoResize again once the textarea becomes visible Mounted hidden (an inactive tab, a closed accordion, a popover before it opens) the textarea measured scrollHeight 0 and stayed one line high, also after it became visible. - A measurement of 0 sets no height: the rows stay until it is visible - A ResizeObserver measures again when the textarea gets a width and whenever the width changes (the text wraps differently) - Story "Textarea in Tabs" (Vue, React) and a browser test: the textarea in a tab that was hidden when it mounted is as high as its four lines - React Native measures with onContentSizeChange and has no such case Signed-off-by: Florian Laabs --- .changeset/textarea-autoresize-hidden.md | 8 +++++++ packages/parity/e2e/controls.spec.ts | 14 +++++++++++ .../components/Textarea/Textarea.stories.tsx | 24 +++++++++++++++++++ .../src/components/Textarea/Textarea.tsx | 22 ++++++++++++++++- .../components/Textarea/Textarea.stories.ts | 24 +++++++++++++++++++ .../vue/src/components/Textarea/Textarea.vue | 23 ++++++++++++++++++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .changeset/textarea-autoresize-hidden.md diff --git a/.changeset/textarea-autoresize-hidden.md b/.changeset/textarea-autoresize-hidden.md new file mode 100644 index 00000000..4ec4608a --- /dev/null +++ b/.changeset/textarea-autoresize-hidden.md @@ -0,0 +1,8 @@ +--- +'@wirecore/wirelayer-vue': patch +'@wirecore/wirelayer-react': patch +--- + +Textarea with `autoResize`: measures its height again once it becomes visible and whenever its width changes. Mounted +hidden (an inactive tab, a closed accordion, a popover before it opens) it measured 0 and stayed one line high. A +hidden textarea now keeps its rows until it can be measured. Story _Textarea in Tabs_. diff --git a/packages/parity/e2e/controls.spec.ts b/packages/parity/e2e/controls.spec.ts index bd31a646..e3302942 100644 --- a/packages/parity/e2e/controls.spec.ts +++ b/packages/parity/e2e/controls.spec.ts @@ -118,6 +118,20 @@ test.describe('Textarea', () => { expect(scroll).toBeLessThanOrEqual(1); }); + test('autoResize in a tab that was hidden when it mounted: as high as its text once the tab opens', async ({ + page, + }) => { + await openStory(page, 'forms-textarea--in-tabs'); + await page.getByRole('tab', { name: 'Notes' }).click(); + const area = page.getByRole('textbox', { name: 'Notes' }); + await expect(area).toBeVisible(); + // Four lines, not one: the height was measured again once the tab became visible + const line = await area.evaluate((element) => parseFloat(getComputedStyle(element).lineHeight)); + await expect.poll(async () => (await area.boundingBox())!.height).toBeGreaterThan(3 * line); + const scroll = await area.evaluate((element) => element.scrollHeight - element.clientHeight); + expect(scroll).toBeLessThanOrEqual(1); + }); + test('defaultValue arrives without v-model; the counter counts it', async ({ page }) => { await openStory(page, 'forms-textarea--initial-value'); const area = page.getByRole('textbox', { name: 'Comment' }); diff --git a/packages/react/src/components/Textarea/Textarea.stories.tsx b/packages/react/src/components/Textarea/Textarea.stories.tsx index fb9176a3..1fd9c05b 100644 --- a/packages/react/src/components/Textarea/Textarea.stories.tsx +++ b/packages/react/src/components/Textarea/Textarea.stories.tsx @@ -1,6 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite'; import { useState } from 'react'; import { Field } from '../Field/Field.js'; +import { Tabs, TabsContent, TabsList, TabsTrigger } from '../Tabs/Tabs.js'; import { Textarea, type TextareaProps } from './Textarea.js'; function Demo(args: TextareaProps) { @@ -89,3 +90,26 @@ export const SizesAndStates: Story = { ), }; + +function InTabsDemo() { + const [text, setText] = useState('Line 1\nLine 2\nLine 3\nLine 4'); + return ( + + + General + Notes + + + Name and e-mail address. + + + +