Skip to content

Commit 9a3d1a6

Browse files
committed
Add disabled states to all input components
1 parent 687b582 commit 9a3d1a6

File tree

19 files changed

+254
-4
lines changed

19 files changed

+254
-4
lines changed

packages/examples/packages/browserify-plugin/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "ssGPi4fxyZSvKOMXbVdOa/vnTx0qrq6WZWCUV91dLqo=",
10+
"shasum": "OGd9oaCS1/I80grXQCFf5900ZUH2hpmnyklFTSpTh34=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/browserify/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "+342Ghzfo9UpTxJgqIPOieHvqRTnf4h00s8r0DpbozY=",
10+
"shasum": "EG/2i55Y2f9IV97KMkFS1rgetcZsKrhbTlgoJ07M0zs=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-sdk/src/jsx/components/form/Checkbox.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ describe('Checkbox', () => {
1414
});
1515
});
1616

17-
it('renders a checkbox with a variant and a label', () => {
17+
it('renders a disabled checkbox with a variant and a label', () => {
1818
const result = (
19-
<Checkbox name="foo" label="Foo" checked={true} variant="toggle" />
19+
<Checkbox
20+
name="foo"
21+
label="Foo"
22+
checked={true}
23+
variant="toggle"
24+
disabled={true}
25+
/>
2026
);
2127

2228
expect(result).toStrictEqual({
@@ -26,6 +32,7 @@ describe('Checkbox', () => {
2632
checked: true,
2733
variant: 'toggle',
2834
label: 'Foo',
35+
disabled: true,
2936
},
3037
key: null,
3138
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { createSnapComponent } from '../../component';
88
* @property checked - Whether the checkbox is checked or not.
99
* @property label - An optional label for the checkbox.
1010
* @property variant - An optional variant for the checkbox.
11+
* @property disabled - Whether the Checkbox is disabled.
1112
*/
1213
export type CheckboxProps = {
1314
name: string;
1415
checked?: boolean | undefined;
1516
label?: string | undefined;
1617
variant?: 'default' | 'toggle' | undefined;
18+
disabled?: boolean | undefined;
1719
};
1820

1921
const TYPE = 'Checkbox';
@@ -27,6 +29,7 @@ const TYPE = 'Checkbox';
2729
* @param props.checked - Whether the checkbox is checked or not.
2830
* @param props.label - An optional label for the checkbox.
2931
* @param props.variant - An optional variant for the checkbox.
32+
* @param props.disabled - Whether the Checkbox is disabled.
3033
* @returns A checkbox element.
3134
* @example
3235
* <Checkbox name="accept-terms" />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import type { OptionElement } from './Option';
99
* state in the form data.
1010
* @property value - The selected value of the dropdown.
1111
* @property children - The children of the dropdown.
12+
* @property disabled - Whether the Dropdown is disabled.
1213
*/
1314
export type DropdownProps = {
1415
name: string;
1516
value?: string | undefined;
1617
children: SnapsChildren<OptionElement>;
18+
disabled?: boolean | undefined;
1719
};
1820

1921
const TYPE = 'Dropdown';
@@ -26,6 +28,7 @@ const TYPE = 'Dropdown';
2628
* state in the form data.
2729
* @param props.value - The selected value of the dropdown.
2830
* @param props.children - The children of the dropdown.
31+
* @param props.disabled - Whether the Dropdown is disabled.
2932
* @returns A dropdown element.
3033
* @example
3134
* <Dropdown name="dropdown">

packages/snaps-sdk/src/jsx/components/form/FileInput.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,17 @@ describe('FileInput', () => {
2626
key: null,
2727
});
2828
});
29+
30+
it('renders disabled file input', () => {
31+
const result = <FileInput name="foo" disabled={true} />;
32+
33+
expect(result).toStrictEqual({
34+
type: 'FileInput',
35+
props: {
36+
name: 'foo',
37+
disabled: true,
38+
},
39+
key: null,
40+
});
41+
});
2942
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import { createSnapComponent } from '../../component';
1010
* specified, the file input field accepts all file types.
1111
* @property compact - Whether the file input field is compact. Default is
1212
* `false`.
13+
* @property disabled - whether the file input is disabled.
1314
*/
1415
export type FileInputProps = {
1516
name: string;
1617
accept?: string[] | undefined;
1718
compact?: boolean | undefined;
19+
disabled?: boolean | undefined;
1820
};
1921

2022
const TYPE = 'FileInput';
@@ -33,6 +35,7 @@ const TYPE = 'FileInput';
3335
* valid values, see the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept).
3436
* @param props.compact - Whether the file input field is compact. Default is
3537
* `false`.
38+
* @param props.disabled - Whether the file input is disabled.
3639
* @returns A file input element.
3740
* @example
3841
* <FileInput name="file" accept={['image/*']} />

packages/snaps-sdk/src/jsx/components/form/Input.test.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,58 @@ describe('Input', () => {
4242
key: null,
4343
});
4444
});
45+
46+
it('renders a disabled text input', () => {
47+
const result = <Input name="foo" type="text" disabled={true} />;
48+
49+
expect(result).toStrictEqual({
50+
type: 'Input',
51+
props: {
52+
name: 'foo',
53+
type: 'text',
54+
disabled: true,
55+
},
56+
key: null,
57+
});
58+
});
59+
60+
it('renders a disabled number input', () => {
61+
const result = (
62+
<Input
63+
name="foo"
64+
type="number"
65+
min={0}
66+
max={10}
67+
step={1}
68+
disabled={true}
69+
/>
70+
);
71+
72+
expect(result).toStrictEqual({
73+
type: 'Input',
74+
props: {
75+
name: 'foo',
76+
type: 'number',
77+
min: 0,
78+
max: 10,
79+
step: 1,
80+
disabled: true,
81+
},
82+
key: null,
83+
});
84+
});
85+
86+
it('renders a disabled password input', () => {
87+
const result = <Input name="foo" type="password" disabled={true} />;
88+
89+
expect(result).toStrictEqual({
90+
type: 'Input',
91+
props: {
92+
name: 'foo',
93+
type: 'password',
94+
disabled: true,
95+
},
96+
key: null,
97+
});
98+
});
4599
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type GenericInputProps = {
66
name: string;
77
value?: string | undefined;
88
placeholder?: string | undefined;
9+
disabled?: boolean | undefined;
910
};
1011

1112
export type TextInputProps = { type: 'text' } & GenericInputProps;
@@ -57,6 +58,7 @@ const TYPE = 'Input';
5758
* Only applicable to the type `number` input.
5859
* @param props.step - The step value of the input field.
5960
* Only applicable to the type `number` input.
61+
* @param props.disabled - Whether the input is disabled.
6062
* @returns An input element.
6163
* @example
6264
* <Input name="username" type="text" />

packages/snaps-sdk/src/jsx/components/form/Radio.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,22 @@ describe('Radio', () => {
1313
key: null,
1414
});
1515
});
16+
17+
it('renders a disabled radio option', () => {
18+
const result = (
19+
<Radio value="foo" disabled={true}>
20+
Foo
21+
</Radio>
22+
);
23+
24+
expect(result).toStrictEqual({
25+
type: 'Radio',
26+
props: {
27+
value: 'foo',
28+
disabled: true,
29+
children: 'Foo',
30+
},
31+
key: null,
32+
});
33+
});
1634
});

0 commit comments

Comments
 (0)