Skip to content

Commit b0c4e5e

Browse files
committed
Add Dropdown options disable feature
1 parent fa9a467 commit b0c4e5e

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

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

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { Dropdown } from './Dropdown';
88
* @property value - The value of the dropdown option. This is used to populate the
99
* state in the form data.
1010
* @property children - The text to display.
11+
* @property disabled - Whether the option is disabled.
1112
*/
1213
type OptionProps = {
1314
value: string;
1415
children: string;
16+
disabled?: boolean;
1517
};
1618

1719
const TYPE = 'Option';
@@ -24,6 +26,7 @@ const TYPE = 'Option';
2426
* @param props.value - The value of the dropdown option. This is used to populate the
2527
* state in the form data.
2628
* @param props.children - The text to display.
29+
* @param props.disabled - Whether the option is disabled.
2730
* @returns A dropdown option element.
2831
* @example
2932
* <Dropdown name="dropdown">

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,12 @@ describe('DropdownStruct', () => {
907907
<Option value="option1">Option 1</Option>
908908
<Option value="option2">Option 2</Option>
909909
</Dropdown>,
910+
<Dropdown name="foo">
911+
<Option value="option1">Option 1</Option>
912+
<Option value="option2" disabled={true}>
913+
Option 2
914+
</Option>
915+
</Dropdown>,
910916
])('validates a dropdown element', (value) => {
911917
expect(is(value, DropdownStruct)).toBe(true);
912918
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export const InputStruct: Describe<InputElement> = elementWithSelectiveProps(
344344
export const OptionStruct: Describe<OptionElement> = element('Option', {
345345
value: string(),
346346
children: string(),
347+
disabled: optional(boolean()),
347348
});
348349

349350
/**

0 commit comments

Comments
 (0)