Skip to content

Commit 01ff383

Browse files
authored
Add disabled states to all input components (#3030)
Add `disabled` state to all input-related Snaps UI components. Related task: MetaMask/metamask-extension#29669 Extension integration PR: MetaMask/metamask-extension#29896 ![Screenshot 2025-01-24 at 16 35 56](https://github.com/user-attachments/assets/2a968c13-77a7-4dc9-8390-24666401323c) https://github.com/user-attachments/assets/cb9eee52-31d6-4b3b-b83d-ac4ba136a2d8
1 parent c348998 commit 01ff383

22 files changed

+324
-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": "hqhKyin2aEwIBEINbyp58fba1ey8216iP25qGL6EEZ4=",
10+
"shasum": "R4WjwqkDLNMUtU07n8AGq0WZKjsqjTjQXlASF++J4ws=",
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": "nnIVqIGRhj27zj2pHhpg9RN8HRiEH/o9EIBzhOhEhVs=",
10+
"shasum": "06xWu+ehUlNMpbJQxTZi2mlnAJId3cLHEK6fWD2Z9rc=",
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.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,41 @@ describe('Dropdown', () => {
6666
key: null,
6767
});
6868
});
69+
70+
it('renders disabled dropdown with options', () => {
71+
const result = (
72+
<Dropdown name="dropdown" value="foo" disabled={true}>
73+
<Option value="foo">Foo</Option>
74+
<Option value="bar">Bar</Option>
75+
</Dropdown>
76+
);
77+
78+
expect(result).toStrictEqual({
79+
type: 'Dropdown',
80+
props: {
81+
name: 'dropdown',
82+
value: 'foo',
83+
disabled: true,
84+
children: [
85+
{
86+
type: 'Option',
87+
props: {
88+
value: 'foo',
89+
children: 'Foo',
90+
},
91+
key: null,
92+
},
93+
{
94+
type: 'Option',
95+
props: {
96+
value: 'bar',
97+
children: 'Bar',
98+
},
99+
key: null,
100+
},
101+
],
102+
},
103+
key: null,
104+
});
105+
});
69106
});

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" />

0 commit comments

Comments
 (0)