Skip to content

Commit

Permalink
Add Dropdown options disable feature
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Jan 27, 2025
1 parent fa9a467 commit b0c4e5e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/snaps-sdk/src/jsx/components/form/Option.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ describe('Option', () => {
key: null,
});
});

it('renders disabled dropdown option', () => {
const result = (
<Option value="foo" disabled={true}>
Foo
</Option>
);

expect(result).toStrictEqual({
type: 'Option',
props: {
value: 'foo',
children: 'Foo',
disabled: true,
},
key: null,
});
});
});
3 changes: 3 additions & 0 deletions packages/snaps-sdk/src/jsx/components/form/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { Dropdown } from './Dropdown';
* @property value - The value of the dropdown option. This is used to populate the
* state in the form data.
* @property children - The text to display.
* @property disabled - Whether the option is disabled.
*/
type OptionProps = {
value: string;
children: string;
disabled?: boolean;
};

const TYPE = 'Option';
Expand All @@ -24,6 +26,7 @@ const TYPE = 'Option';
* @param props.value - The value of the dropdown option. This is used to populate the
* state in the form data.
* @param props.children - The text to display.
* @param props.disabled - Whether the option is disabled.
* @returns A dropdown option element.
* @example
* <Dropdown name="dropdown">
Expand Down
6 changes: 6 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,12 @@ describe('DropdownStruct', () => {
<Option value="option1">Option 1</Option>
<Option value="option2">Option 2</Option>
</Dropdown>,
<Dropdown name="foo">
<Option value="option1">Option 1</Option>
<Option value="option2" disabled={true}>
Option 2
</Option>
</Dropdown>,
])('validates a dropdown element', (value) => {
expect(is(value, DropdownStruct)).toBe(true);
});
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export const InputStruct: Describe<InputElement> = elementWithSelectiveProps(
export const OptionStruct: Describe<OptionElement> = element('Option', {
value: string(),
children: string(),
disabled: optional(boolean()),
});

/**
Expand Down

0 comments on commit b0c4e5e

Please sign in to comment.