Skip to content

Commit f57a9be

Browse files
committed
Allow Field in Box
1 parent 6bd6fd8 commit f57a9be

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

packages/snaps-controllers/src/interface/utils.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,21 @@ describe('constructState', () => {
242242
});
243243
});
244244

245+
it('handles root level Field', () => {
246+
const element = (
247+
<Box>
248+
<Field label="foo">
249+
<Input name="foo" type="text" value="bar" />
250+
</Field>
251+
</Box>
252+
);
253+
254+
const result = constructState({}, element);
255+
expect(result).toStrictEqual({
256+
foo: 'bar',
257+
});
258+
});
259+
245260
it('handles root level inputs with value', () => {
246261
const element = (
247262
<Box>

packages/snaps-sdk/src/jsx/components/form/Field.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export type FieldProps = {
3232
const TYPE = 'Field';
3333

3434
/**
35-
* A field component, which is used to create a form field. This component can
36-
* only be used as a child of the {@link Form} component.
35+
* A field component, which is used to create a form field.
3736
*
3837
* @param props - The props of the component.
3938
* @param props.label - The label of the field.

packages/snaps-sdk/src/jsx/validation.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ describe('BoxStruct', () => {
567567
<Text>foo</Text>
568568
<Text>bar</Text>
569569
</Box>,
570+
<Box>
571+
<Field label="foo">
572+
<Input name="foo" />
573+
</Field>
574+
</Box>,
570575
<Box>
571576
<Text>foo</Text>
572577
<Row label="label">
@@ -620,11 +625,6 @@ describe('BoxStruct', () => {
620625
<Image src="<svg />" alt="alt" />
621626
</Row>
622627
</Box>,
623-
<Box>
624-
<Field label="foo">
625-
<Input name="foo" />
626-
</Field>
627-
</Box>,
628628
<Box>
629629
<Value extra="foo" value="bar" />
630630
</Box>,

packages/snaps-sdk/src/jsx/validation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export const FieldStruct: Describe<FieldElement> = element('Field', {
512512
*/
513513
export const FormChildStruct = children(
514514
// eslint-disable-next-line @typescript-eslint/no-use-before-define
515-
[FieldStruct, lazy(() => BoxChildStruct)],
515+
[lazy(() => BoxChildStruct)],
516516
) as unknown as Struct<SnapsChildren<GenericSnapElement>, null>;
517517

518518
/**
@@ -796,6 +796,7 @@ export const BoxChildStruct = typedUnion([
796796
DividerStruct,
797797
DropdownStruct,
798798
RadioGroupStruct,
799+
FieldStruct,
799800
FileInputStruct,
800801
FormStruct,
801802
HeadingStruct,

0 commit comments

Comments
 (0)