Skip to content

Commit e440869

Browse files
authored
fix: enable textarea autosize only on focus (#676)
1 parent 4c86827 commit e440869

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

.changeset/blue-frogs-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@blinkk/root-cms': patch
3+
---
4+
5+
fix: enable textarea autosize only on focus (#676)

packages/root-cms/ui/components/DocEditor/fields/StringField.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import {TextInput, Textarea} from '@mantine/core';
22
import {ChangeEvent} from 'preact/compat';
33
import {useEffect, useState} from 'preact/hooks';
44
import * as schema from '../../../../core/schema.js';
5-
import {testHasExperimentParam} from '../../../utils/url-params.js';
65
import {FieldProps} from './FieldProps.js';
76

8-
const DISABLE_AUTOSIZE = testHasExperimentParam('DisableTextareaAutosize');
9-
107
export function StringField(props: FieldProps) {
118
const field = props.field as schema.StringField;
129
const [value, setValue] = useState('');
10+
const [autosize, setAutosize] = useState(false);
1311

1412
function onChange(newValue: string) {
1513
setValue(newValue);
@@ -31,13 +29,18 @@ export function StringField(props: FieldProps) {
3129
<Textarea
3230
size="xs"
3331
radius={0}
34-
autosize={!DISABLE_AUTOSIZE}
35-
minRows={DISABLE_AUTOSIZE ? 4 : 2}
32+
autosize={autosize}
33+
minRows={3}
3634
maxRows={field.maxRows || 12}
3735
value={value}
3836
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
3937
onChange(e.currentTarget.value);
4038
}}
39+
onFocus={() => {
40+
if (!autosize) {
41+
setAutosize(true);
42+
}
43+
}}
4144
/>
4245
);
4346
}

0 commit comments

Comments
 (0)