From e6185ef8d72d481dcfd6119c121ed59186373bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 15 Aug 2024 10:30:46 +0200 Subject: [PATCH] fix(form): fix issue where FormInput was not rendering field when passed 'includeField' (#7350) * chore(test-studio): add example schema + custom FormInput example/playground * fix(form): fix issue where FormInput was not rendering field when passed 'includeField' --- .../formBuilder/FormInputExample.tsx | 82 +++++++++++++++++++ .../v3/form-components-api/formInputTest.tsx | 46 +++++++++++ .../docs/v3/form-components-api/index.ts | 1 + dev/test-studio/schema/docs/v3/index.ts | 4 +- .../src/core/form/components/FormInput.tsx | 59 +++++++------ 5 files changed, 164 insertions(+), 28 deletions(-) create mode 100644 dev/test-studio/components/formBuilder/FormInputExample.tsx create mode 100644 dev/test-studio/schema/docs/v3/form-components-api/formInputTest.tsx diff --git a/dev/test-studio/components/formBuilder/FormInputExample.tsx b/dev/test-studio/components/formBuilder/FormInputExample.tsx new file mode 100644 index 00000000000..04368015979 --- /dev/null +++ b/dev/test-studio/components/formBuilder/FormInputExample.tsx @@ -0,0 +1,82 @@ +import {CloseIcon, EyeOpenIcon} from '@sanity/icons' +import {Box, Button, Card, Checkbox, Flex, Inline, Stack, Text} from '@sanity/ui' +import {useState} from 'react' +import { + FormInput, + type ObjectInputProps, + type Path, + pathToString, + type RenderInputCallback, +} from 'sanity' + +export function FormInputExample(props: ObjectInputProps) { + const [path, setPath] = useState([]) + + const [includeField, setIncludeField] = useState(false) + const [includeItem, setIncludeItem] = useState(false) + + const renderDefaultForm = path.length === 0 + + const renderInput: RenderInputCallback = (inputProps) => { + // wraps each input with a button that allows rendering only the selected input + const selected = inputProps.path === path + return ( + + {props.renderInput(inputProps)} + +