Skip to content

Commit

Permalink
feat(BoemlyFormControl): Add disabled option to select options
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbals committed Aug 31, 2022
1 parent a804ef5 commit c7b8fec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/components/BoemlyFormControl/BoemlyFormControl.stories.tsx
Expand Up @@ -102,6 +102,16 @@ Select.args = {
],
};

export const SelectWithDisabledOption = Template.bind({});
SelectWithDisabledOption.args = {
id: 'select',
inputType: 'Select',
selectOptions: [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2', disabled: true },
],
};

export const Checkbox = Template.bind({});
Checkbox.args = {
id: 'checkbox',
Expand Down
10 changes: 8 additions & 2 deletions src/components/BoemlyFormControl/BoemlyFormControl.test.tsx
Expand Up @@ -30,11 +30,17 @@ describe('The BoemlyFormControl component', () => {
it('displays a select field if inputType select is given', () => {
setup({
inputType: 'Select',
selectOptions: [{ value: 'value', label: 'Label' }],
selectOptions: [
{ value: 'value-1', label: 'Label 1' },
{ value: 'value-2', label: 'Label 2', disabled: true },
],
});

expect(screen.getByRole('combobox')).toBeInTheDocument();
expect(screen.getByRole('option')).toHaveAttribute('value', 'value');
expect(screen.getAllByRole('option')[0]).toHaveAttribute('value', 'value-1');
expect(screen.getAllByRole('option')[0]).not.toHaveAttribute('disabled');
expect(screen.getAllByRole('option')[1]).toHaveAttribute('value', 'value-2');
expect(screen.getAllByRole('option')[1]).toHaveAttribute('disabled');
});

it('displays a checkbox field if the inputType checkbox is given', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/components/BoemlyFormControl/BoemlyFormControl.tsx
Expand Up @@ -36,7 +36,7 @@ export interface BoemlyFormControlProps extends StyleProps {
inputProps?: InputProps;
numberInputProps?: NumberInputProps;
selectProps?: SelectProps;
selectOptions?: { value: string; label: string }[];
selectOptions?: { value: string; label: string; disabled?: boolean }[];
checkboxProps?: CheckboxProps;

// Inner input elements
Expand Down Expand Up @@ -96,7 +96,11 @@ export const BoemlyFormControl: React.FC<BoemlyFormControlProps> = ({
return (
<Select bgColor="white" {...selectProps}>
{selectOptions.map((selectOption) => (
<option key={selectOption.value} value={selectOption.value}>
<option
key={selectOption.value}
value={selectOption.value}
disabled={selectOption.disabled}
>
{selectOption.label}
</option>
))}
Expand Down

1 comment on commit c7b8fec

@vercel
Copy link

@vercel vercel bot commented on c7b8fec Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.