Skip to content

Commit 1b9d155

Browse files
authored
Textarea should not behave differently inside a flex (#1531)
* Quiet TextArea shouldn't behave different in a Flex * improve story * fix lint
1 parent f6d09d1 commit 1b9d155

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

packages/@react-spectrum/textfield/src/TextArea.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ function TextArea(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
3737
let onHeightChange = useCallback(() => {
3838
if (isQuiet) {
3939
let input = inputRef.current;
40+
let prevAlignment = input.style.alignSelf;
41+
input.style.alignSelf = 'start';
4042
input.style.height = 'auto';
4143
input.style.height = `${input.scrollHeight}px`;
44+
input.style.alignSelf = prevAlignment;
4245
}
4346
}, [isQuiet, inputRef]);
4447

packages/@react-spectrum/textfield/stories/TextArea.stories.js

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import {action} from '@storybook/addon-actions';
1414
import {Button} from '@react-spectrum/button';
15+
import {Flex} from '@react-spectrum/layout';
1516
import {Form} from '@react-spectrum/form';
1617
import Info from '@spectrum-icons/workflow/Info';
1718
import React, {useState} from 'react';
@@ -135,7 +136,8 @@ storiesOf('TextArea', module)
135136
)
136137
.add('controlled interactive',
137138
() => <ControlledTextArea />
138-
);
139+
)
140+
.add('in flex', () => renderInFlexRowAndBlock());
139141

140142
function render(props = {}) {
141143
return (
@@ -159,3 +161,61 @@ function ControlledTextArea(props) {
159161
</>
160162
);
161163
}
164+
165+
function renderInFlexRowAndBlock(props = {}) {
166+
return (
167+
<Flex direction="column" gap="size-300">
168+
Align stretch
169+
<Flex gap="size-100">
170+
<TextArea
171+
label="Default"
172+
placeholder="React"
173+
{...props} />
174+
<TextArea
175+
label="Quiet"
176+
placeholder="React"
177+
isQuiet
178+
{...props} />
179+
<TextArea
180+
label="Quiet"
181+
placeholder="React"
182+
isQuiet
183+
{...props} />
184+
</Flex>
185+
Align end
186+
<Flex gap="size-100" alignItems="end">
187+
<TextArea
188+
label="Default"
189+
placeholder="React"
190+
{...props} />
191+
<TextArea
192+
label="Quiet"
193+
placeholder="React"
194+
isQuiet
195+
{...props} />
196+
<TextArea
197+
label="Quiet"
198+
placeholder="React"
199+
isQuiet
200+
{...props} />
201+
</Flex>
202+
Display block
203+
<div>
204+
<TextArea
205+
label="Default"
206+
placeholder="React"
207+
{...props} />
208+
<TextArea
209+
label="Quiet"
210+
placeholder="React"
211+
isQuiet
212+
{...props} />
213+
<TextArea
214+
label="Quiet"
215+
placeholder="React"
216+
isQuiet
217+
{...props} />
218+
</div>
219+
</Flex>
220+
);
221+
}

0 commit comments

Comments
 (0)