Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-2584 migrate FormTextArea (#77089)

Egor Grushinb9bba24cfdcb
diff --git a/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx b/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx
index fbe037422ca..28343b2ce01 100644
--- a/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx
+++ b/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx
@@ -4,13 +4,13 @@ import { forwardRef } from "react";
import type { ActionFormFieldProps } from "metabase/actions/types";
import { FormInput as FormInputWidget } from "metabase/common/components/FormInput";
import { FormNumericInput as FormNumericInputWidget } from "metabase/common/components/FormNumericInput";
-import { FormTextArea as FormTextAreaWidget } from "metabase/common/components/FormTextArea";
import { FormToggle as FormBooleanWidget } from "metabase/common/components/FormToggle";
import { FormRadioGroup, type FormRadioGroupProps } from "metabase/forms";
import { Radio, Stack } from "metabase/ui";
import type { InputComponentType } from "metabase-types/api";
import { FormSelectWidget } from "./FormSelectWidget";
+import { FormTextareaWidget } from "./FormTextareaWidget";
type RadioOption = {
name: string;
@@ -48,7 +48,7 @@ const WIDGETS: Record<InputComponentType, FunctionComponent<any>> = {
date: FormInputWidget,
time: FormInputWidget,
"datetime-local": FormInputWidget,
- textarea: FormTextAreaWidget,
+ textarea: FormTextareaWidget,
number: FormNumericInputWidget,
boolean: FormBooleanWidget,
radio: VerticalRadio,
diff --git a/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormTextareaWidget.tsx b/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormTextareaWidget.tsx
new file mode 100644
index 00000000000..60cba48b3c4
--- /dev/null
+++ b/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormTextareaWidget.tsx
@@ -0,0 +1,49 @@
+import type { ReactNode, Ref } from "react";
+import { forwardRef } from "react";
+
+import type { ActionFormFieldProps } from "metabase/actions/types";
+import { useUniqueId } from "metabase/common/hooks/use-unique-id";
+import { FormField, FormTextarea } from "metabase/forms";
+
+type FormTextareaWidgetProps = ActionFormFieldProps & {
+ actions?: ReactNode;
+ disabled?: boolean;
+ nullable?: boolean;
+};
+
+export const FormTextareaWidget = forwardRef(function FormTextareaWidget(
+ {
+ name,
+ title,
+ description,
+ actions,
+ optional,
+ options,
+ type,
+ field,
+ nullable,
+ ...props
+ }: FormTextareaWidgetProps,
+ ref: Ref<HTMLTextAreaElement>,
+) {
+ const id = useUniqueId();
+
+ return (
+ <FormField
+ title={title}
+ actions={actions}
+ description={description}
+ optional={optional}
+ htmlFor={id}
+ >
+ <FormTextarea
+ {...props}
+ ref={ref}
+ id={id}
+ name={name}
+ nullable={nullable}
+ minRows={5}
+ />
+ </FormField>
+ );
+});
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
index bfc770adfd3..88f1a95d7ca 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
@@ -7,8 +7,12 @@ import type { CreateQueryActionParams } from "metabase/actions/types";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormFooter } from "metabase/common/components/FormFooter";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import { Button } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
@@ -61,10 +65,12 @@ function CreateActionForm({
placeholder={t`My new fantastic action`}
data-autofocus
/>
- <FormTextArea
+ <FormTextarea
name="description"
- title={t`Description`}
+ label={t`Description`}
placeholder={t`It's optional but oh, so helpful`}
+ minRows={5}
+ mb="md"
nullable
/>
<FormModelPicker name="model_id" title={t`Model it's saved in`} />
diff --git a/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx b/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
index a87f90537e1..25871843e98 100644
--- a/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
+++ b/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
@@ -8,13 +8,17 @@ import { useInitialCollectionId } from "metabase/common/collections/hooks";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormFooter } from "metabase/common/components/FormFooter";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
import type {
EntityPickerOptions,
FilterItemsInPersonalCollection,
OmniPickerItem,
} from "metabase/common/components/Pickers";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import { PLUGIN_TENANTS } from "metabase/plugins";
import type { WithRouterProps } from "metabase/router";
import { withRouter } from "metabase/router";
@@ -131,12 +135,13 @@ function CreateCollectionForm({
placeholder={t`My new fantastic collection`}
data-autofocus
/>
- <FormTextArea
+ <FormTextarea
name="description"
- title={t`Description`}
+ label={t`Description`}
placeholder={t`It's optional but oh, so helpful`}
+ minRows={5}
+ mb="md"
nullable
- optional
/>
{showCollectionPicker && (
<FormCollectionPicker
diff --git a/frontend/src/metabase/common/components/ErrorPages/BugReportModal.tsx b/frontend/src/metabase/common/components/ErrorPages/BugReportModal.tsx
index 5e891e667a4..2c5ed5dff7c 100644
--- a/frontend/src/metabase/common/components/ErrorPages/BugReportModal.tsx
+++ b/frontend/src/metabase/common/components/ErrorPages/BugReportModal.tsx
@@ -1,8 +1,12 @@
import { useState } from "react";
import { c, t } from "ttag";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import {
Box,
Button,
@@ -62,10 +66,12 @@ export const BugReportModal = ({
{(formik) => (
<Form>
<Text py="md">{t`Could you provide us with a little context?`}</Text>
- <FormTextArea
+ <FormTextarea
name="description"
- autoFocus
+ data-autofocus
placeholder={t`What were you trying to do, and what steps did you take? What was the expected result, and what happened instead?`}
+ minRows={5}
+ mb="md"
/>
<Box
bg={"accent-gray-light"}
diff --git a/frontend/src/metabase/common/components/ErrorPages/DownloadDiagnosticModal.tsx b/frontend/src/metabase/common/components/ErrorPages/DownloadDiagnosticModal.tsx
index cfff2639fc7..4774c1698ad 100644
--- a/frontend/src/metabase/common/components/ErrorPages/DownloadDiagnosticModal.tsx
+++ b/frontend/src/metabase/common/components/ErrorPages/DownloadDiagnosticModal.tsx
@@ -1,7 +1,11 @@
import { c, t } from "ttag";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import { Modal, Text } from "metabase/ui";
import { DiagnosticCheckboxes } from "./DiagnosticCheckboxes";
@@ -49,10 +53,12 @@ export const DownloadDiagnosticModal = ({
>
<Form>
<Text py="md">{t`Could you provide us with a little context?`}</Text>
- <FormTextArea
+ <FormTextarea
name="description"
- autoFocus
+ data-autofocus
placeholder={t`What were you trying to do, and what steps did you take? What was the expected result, and what happened instead?`}
+ minRows={5}
+ mb="md"
/>
<Text>
{/* eslint-disable-next-line metabase/no-literal-metabase-strings -- this is a translation context string, not shown to users */}
diff --git a/frontend/src/metabase/common/components/FormTextArea/FormTextArea.stories.tsx b/frontend/src/metabase/common/components/FormTextArea/FormTextArea.stories.tsx
deleted file mode 100644
index 7d5da72214d..00000000000
--- a/frontend/src/metabase/common/components/FormTextArea/FormTextArea.stories.tsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import type { StoryFn } from "@storybook/react";
-
-import { Form, FormProvider } from "metabase/forms";
-
-import { FormTextArea } from "./FormTextArea";
-
-export default {
- title: "Components/Ask Before Using/FormTextArea",
- component: FormTextArea,
-};
-
-const Template: StoryFn<typeof FormTextArea> = (args) => {
- const initialValues = { value: false };
- const handleSubmit = () => undefined;
-
- return (
- <FormProvider initialValues={initialValues} onSubmit={handleSubmit}>
- <Form>
- <FormTextArea {...args} name="value" />
- </Form>
- </FormProvider>
- );
-};
-
-export const Default = {
- render: Template,
-
- args: {
- title: "Title",
- },
-};
-
-export const WithDescription = {
- render: Template,
-
- args: {
- title: "Title",
- description: "Description",
- },
-};
diff --git a/frontend/src/metabase/common/components/FormTextArea/FormTextArea.tsx b/frontend/src/metabase/common/components/FormTextArea/FormTextArea.tsx
deleted file mode 100644
index 78e7df18a68..00000000000
--- a/frontend/src/metabase/common/components/FormTextArea/FormTextArea.tsx
+++ /dev/null
@@ -1,86 +0,0 @@
-import { useField } from "formik";
-import type { ChangeEvent, ReactNode, Ref } from "react";
-import { forwardRef, useCallback } from "react";
-
-import { FormField } from "metabase/common/components/FormField";
-import type { TextAreaProps } from "metabase/common/components/TextArea";
-import { TextArea } from "metabase/common/components/TextArea";
-import { useUniqueId } from "metabase/common/hooks/use-unique-id";
-
-export interface FormTextAreaProps extends Omit<
- TextAreaProps,
- "value" | "error" | "fullWidth" | "onChange" | "onBlur"
-> {
- name: string;
- title?: string;
- actions?: ReactNode;
- description?: ReactNode;
- nullable?: boolean;
- infoLabel?: string;
- infoTooltip?: string;
- optional?: boolean;
- inputClassName?: string;
-}
-
-/**
- * @deprecated: use FormTextArea from "metabase/forms"
- */
-const FormTextAreaInner = forwardRef(function FormTextArea(
- {
- name,
- className,
- inputClassName,
- style,
- title,
- actions,
- description,
- nullable,
- infoLabel,
- infoTooltip,
- optional,
- ...props
- }: FormTextAreaProps,
- ref: Ref<HTMLDivElement>,
-) {
- const id = useUniqueId();
- const [{ value, onBlur }, { error, touched }, { setValue }] = useField(name);
-
- const handleChange = useCallback(
- ({ target: { value } }: ChangeEvent<HTMLTextAreaElement>) => {
- setValue(value === "" && nullable ? null : value);
- },
- [nullable, setValue],
- );
-
- return (
- <FormField
- ref={ref}
- className={className}
- style={style}
- title={title}
- actions={actions}
- description={description}
- htmlFor={id}
- error={touched ? error : undefined}
- infoLabel={infoLabel}
- infoTooltip={infoTooltip}
- optional={optional}
- >
- <TextArea
- {...props}
- className={inputClassName}
- id={id}
- name={name}
- value={value ?? ""}
- error={touched && error != null}
- fullWidth
- onChange={handleChange}
- onBlur={onBlur}
- />
- </FormField>
- );
-});
-
-export const FormTextArea = Object.assign(FormTextAreaInner, {
- Root: TextArea.Root,
-});
diff --git a/frontend/src/metabase/common/components/FormTextArea/index.ts b/frontend/src/metabase/common/components/FormTextArea/index.ts
deleted file mode 100644
index 4bf17375571..00000000000
--- a/frontend/src/metabase/common/components/FormTextArea/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { FormTextArea } from "./FormTextArea";
-export type { FormTextAreaProps } from "./FormTextArea";
diff --git a/frontend/src/metabase/querying/components/NativeQueryEditor/SnippetForm/SnippetForm.tsx b/frontend/src/metabase/querying/components/NativeQueryEditor/SnippetForm/SnippetForm.tsx
index dcd596fd88b..9dccdb6d61d 100644
--- a/frontend/src/metabase/querying/components/NativeQueryEditor/SnippetForm/SnippetForm.tsx
+++ b/frontend/src/metabase/querying/components/NativeQueryEditor/SnippetForm/SnippetForm.tsx
@@ -6,9 +6,13 @@ import { useListCollectionsQuery } from "metabase/api";
import FormCollectionPicker from "metabase/common/collections/containers/FormCollectionPicker";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import { Button, Flex, Icon } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import type { Collection, NativeQuerySnippet } from "metabase-types/api";
@@ -78,12 +82,15 @@ function SnippetFormInner({
>
{({ dirty }) => (
<Form disabled={!dirty && !isInitiallyDirty} className={S.SnippetForm}>
- <FormTextArea
- inputClassName={S.FormSnippetTextArea}
+ <FormTextarea
+ classNames={{ input: S.FormSnippetTextArea }}
name="content"
- title={t`Enter some SQL here so you can reuse it later`}
+ label={t`Enter some SQL here so you can reuse it later`}
placeholder="AND canceled_at IS null\nAND account_type = 'PAID'"
- rows={4}
+ autosize={false}
+ resize="vertical"
+ rows={5}
+ mb="md"
/>
<FormInput
name="name"
diff --git a/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx b/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
index aa1d7b4e95b..23c4cbcf3e1 100644
--- a/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
+++ b/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
@@ -4,9 +4,13 @@ import * as Yup from "yup";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormTextArea } from "metabase/common/components/FormTextArea";
import { getTimelineIcons } from "metabase/common/utils/timelines";
-import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSubmitButton,
+ FormTextarea,
+} from "metabase/forms";
import { Button } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import type { TimelineData } from "metabase-types/api";
@@ -52,7 +56,13 @@ const TimelineForm = ({
placeholder={t`Product releases`}
autoFocus
/>
- <FormTextArea name="description" title={t`Description`} nullable />
+ <FormTextarea
+ name="description"
+ label={t`Description`}
+ minRows={5}
+ mb="md"
+ nullable
+ />
<IconField name="icon" title={t`Default icon`} options={icons} />
<TimelineFormFooter>
<FormErrorMessage inline />