Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "4yLB19XYAdGgHBPFlVOzCkb/JUZCjSajPRSQWs+a3uE=",
"shasum": "d1js9Y4zJwk7n/e47V5fdMreo1FBtVKl4GtPhfckZrs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "+0hxp1uhfCqe9KR+4RPDSPGHFTgRyGULKLn9XWwCmsY=",
"shasum": "VvMm+Zet1+q467UNweIuLLtYVoHoJdTeNjZn0xnEwO8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
15 changes: 15 additions & 0 deletions packages/snaps-controllers/src/interface/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ describe('constructState', () => {
});
});

it('handles root level Field', () => {
const element = (
<Box>
<Field label="foo">
<Input name="foo" type="text" value="bar" />
</Field>
</Box>
);

const result = constructState({}, element);
expect(result).toStrictEqual({
foo: 'bar',
});
});

it('handles root level inputs with value', () => {
const element = (
<Box>
Expand Down
3 changes: 1 addition & 2 deletions packages/snaps-sdk/src/jsx/components/form/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export type FieldProps = {
const TYPE = 'Field';

/**
* A field component, which is used to create a form field. This component can
* only be used as a child of the {@link Form} component.
* A field component, which is used to create a form field.
*
* @param props - The props of the component.
* @param props.label - The label of the field.
Expand Down
10 changes: 5 additions & 5 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ describe('BoxStruct', () => {
<Text>foo</Text>
<Text>bar</Text>
</Box>,
<Box>
<Field label="foo">
<Input name="foo" />
</Field>
</Box>,
<Box>
<Text>foo</Text>
<Row label="label">
Expand Down Expand Up @@ -620,11 +625,6 @@ describe('BoxStruct', () => {
<Image src="<svg />" alt="alt" />
</Row>
</Box>,
<Box>
<Field label="foo">
<Input name="foo" />
</Field>
</Box>,
<Box>
<Value extra="foo" value="bar" />
</Box>,
Expand Down
30 changes: 14 additions & 16 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,22 +507,6 @@ export const FieldStruct: Describe<FieldElement> = element('Field', {
children: FieldChildStruct,
});

/**
* A subset of JSX elements that are allowed as children of the Form component.
*/
export const FormChildStruct = children(
// eslint-disable-next-line @typescript-eslint/no-use-before-define
[FieldStruct, lazy(() => BoxChildStruct)],
) as unknown as Struct<SnapsChildren<GenericSnapElement>, null>;

/**
* A struct for the {@link FormElement} type.
*/
export const FormStruct: Describe<FormElement> = element('Form', {
children: FormChildStruct,
name: string(),
});

/**
* A struct for the {@link BoldElement} type.
*/
Expand Down Expand Up @@ -584,6 +568,19 @@ export const BoxStruct: Describe<BoxElement> = element('Box', {
center: optional(boolean()),
});

/**
* A subset of JSX elements that are allowed as children of the Form component.
*/
export const FormChildStruct = BoxChildrenStruct;

/**
* A struct for the {@link FormElement} type.
*/
export const FormStruct: Describe<FormElement> = element('Form', {
children: FormChildStruct,
name: string(),
});

const FooterButtonStruct = refine(ButtonStruct, 'FooterButton', (value) => {
if (
typeof value.props.children === 'string' ||
Expand Down Expand Up @@ -796,6 +793,7 @@ export const BoxChildStruct = typedUnion([
DividerStruct,
DropdownStruct,
RadioGroupStruct,
FieldStruct,
FileInputStruct,
FormStruct,
HeadingStruct,
Expand Down
Loading