From f051ecb573a1695ba3f0c6833b84dafb86db9dfb Mon Sep 17 00:00:00 2001 From: v1rtl Date: Fri, 29 Mar 2024 02:15:17 +0200 Subject: [PATCH] allow passing href to a dropdown item --- .../molecules/Dropdown/Dropdown.test.tsx | 21 +++++++++++++++++++ .../molecules/Dropdown/Dropdown.tsx | 3 +++ 2 files changed, 24 insertions(+) diff --git a/components/src/components/molecules/Dropdown/Dropdown.test.tsx b/components/src/components/molecules/Dropdown/Dropdown.test.tsx index 1da9c20c..5b49e273 100644 --- a/components/src/components/molecules/Dropdown/Dropdown.test.tsx +++ b/components/src/components/molecules/Dropdown/Dropdown.test.tsx @@ -139,4 +139,25 @@ describe('', () => { }) expect(screen.getByTestId('scrollbox-bottom-intersect')).toBeVisible() }) + it('should allow having items as links', async () => { + render( + , + ) + + userEvent.click(screen.getByText('menu')) + + expect(screen.getByText('Example')).toHaveAttribute( + 'href', + 'https://example.com', + ) + }) }) diff --git a/components/src/components/molecules/Dropdown/Dropdown.tsx b/components/src/components/molecules/Dropdown/Dropdown.tsx index 5ed64ddd..6536806f 100644 --- a/components/src/components/molecules/Dropdown/Dropdown.tsx +++ b/components/src/components/molecules/Dropdown/Dropdown.tsx @@ -25,6 +25,7 @@ export type DropdownItemObject = { color?: Colors disabled?: boolean showIndicator?: boolean | Colors + href?: string } export type DropdownItem = @@ -298,6 +299,7 @@ const DropdownMenu = React.forwardRef( as, wrapper, showIndicator, + href, } = item as DropdownItemObject const props: React.ComponentProps = { @@ -316,6 +318,7 @@ const DropdownMenu = React.forwardRef( {label} ), + href, } if (wrapper) {