Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Field in Box #2926

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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": "5Jms4CVyGrXp46D7/zaU+Dst9AGCZk7mHLOSB2UlmnQ=",
"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": "KgWNba9gUKLZQ/XNfFXPuWzjP3VKi5Wb2jnzN8FJWzc=",
"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
3 changes: 2 additions & 1 deletion packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export const FieldStruct: Describe<FieldElement> = element('Field', {
*/
export const FormChildStruct = children(
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/no-use-before-define
[FieldStruct, lazy(() => BoxChildStruct)],
[lazy(() => BoxChildStruct)],
) as unknown as Struct<SnapsChildren<GenericSnapElement>, null>;

/**
Expand Down Expand Up @@ -796,6 +796,7 @@ export const BoxChildStruct = typedUnion([
DividerStruct,
DropdownStruct,
RadioGroupStruct,
FieldStruct,
FileInputStruct,
FormStruct,
HeadingStruct,
Expand Down
Loading