Skip to content

Commit 2e322a3

Browse files
authored
feat: add experiment param to disable textarea autosize (#646)
1 parent 479316a commit 2e322a3

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ 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';
56
import {FieldProps} from './FieldProps.js';
67

8+
const DISABLE_AUTOSIZE = testHasExperimentParam('DisableTextareaAutosize');
9+
710
export function StringField(props: FieldProps) {
811
const field = props.field as schema.StringField;
912
const [value, setValue] = useState('');
@@ -28,8 +31,8 @@ export function StringField(props: FieldProps) {
2831
<Textarea
2932
size="xs"
3033
radius={0}
31-
autosize
32-
minRows={2}
34+
autosize={!DISABLE_AUTOSIZE}
35+
minRows={DISABLE_AUTOSIZE ? 4 : 2}
3336
maxRows={field.maxRows || 12}
3437
value={value}
3538
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {

packages/root-cms/ui/components/FileUploadField/FileUploadField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from '../../utils/gcs.js';
4343

4444
import './FileUploadField.css';
45+
import {testHasExperimentParam} from '../../utils/url-params.js';
4546

4647
/** Mimetypes accepted by the image input field. */
4748
const IMAGE_MIMETYPES = [
@@ -72,6 +73,8 @@ const PLACEHOLDER_COLORS = [
7273

7374
type FileUploadFieldVariant = 'file' | 'image';
7475

76+
const DISABLE_AUTOSIZE = testHasExperimentParam('DisableTextareaAutosize');
77+
7578
interface FileUploadFieldProps {
7679
children?: preact.ComponentChildren;
7780
file?: UploadedFile | null;
@@ -611,7 +614,7 @@ FileUploadField.Preview = () => {
611614
readOnly
612615
value={uploadedFile.src}
613616
size="xs"
614-
autosize
617+
autosize={!DISABLE_AUTOSIZE}
615618
radius={0}
616619
/>
617620
</td>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* A tests whether e=<name> is in the URL. For multiple experiment names, use a
3+
* comma-separated list in the URL.
4+
*/
5+
export function testHasExperimentParam(name: string) {
6+
const searchParams = new URLSearchParams(window.location.search);
7+
const e = searchParams.get('e');
8+
if (!e) {
9+
return false;
10+
}
11+
const values = e.split(',');
12+
return values.includes(name);
13+
}

0 commit comments

Comments
 (0)