Skip to content

Commit

Permalink
Merge pull request #919 from equinor/feat/option-drawer-disabled
Browse files Browse the repository at this point in the history
✨ Add 'disabled' prop to OptionDrawer
  • Loading branch information
mariush2 authored Dec 20, 2024
2 parents 8cff552 + ae3710f commit bcec666
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/molecules/OptionDrawer/OptionDrawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,16 @@ test('chevron toggler works as expected', async () => {
expect(screen.queryByText(label)).not.toBeInTheDocument()
);
});

test("Doesn't call onToggle if disabled", async () => {
const user = userEvent.setup();

const props = fakeProps();
const onToggle = vi.fn();

render(<OptionDrawer {...props} onToggle={onToggle} disabled />);

await user.click(screen.getByText(props.item.label));

expect(onToggle).not.toHaveBeenCalled();
});
6 changes: 5 additions & 1 deletion src/molecules/OptionDrawer/OptionDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface OptionDrawerProps<
openAll?: boolean;
showIntermediateParent?: boolean;
parentHasNestedItems?: boolean;
disabled?: boolean;
}

export const OptionDrawer = <
Expand All @@ -105,6 +106,7 @@ export const OptionDrawer = <
openAll,
showIntermediateParent = false,
parentHasNestedItems = false,
disabled = false,
}: OptionDrawerProps<T>) => {
const [open, setOpen] = useState(false);
const [status, setStatus] = useState<StatusType>(
Expand All @@ -127,6 +129,8 @@ export const OptionDrawer = <
}, [openAll]);

const handleClick = (e: MouseEvent) => {
if (disabled) return;

if (item.children && item.children.length !== 0) {
setOpen((o) => !o);
}
Expand Down Expand Up @@ -233,7 +237,6 @@ export const OptionDrawer = <
indeterminate={status === 'INTERMEDIATE'}
checked={status === 'CHECKED'}
color="secondary"
onChange={() => null}
/>
{item.label}
</StyledOption>
Expand All @@ -254,6 +257,7 @@ export const OptionDrawer = <
openAll={openAll}
showIntermediateParent={showIntermediateParent}
parentHasNestedItems
disabled={disabled}
/>
))}
</StyledOptionWrapper>
Expand Down

0 comments on commit bcec666

Please sign in to comment.