Skip to content

Commit

Permalink
allow passing href to a dropdown item
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Mar 29, 2024
1 parent f397363 commit f051ecb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions components/src/components/molecules/Dropdown/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,25 @@ describe('<Dropdown />', () => {
})
expect(screen.getByTestId('scrollbox-bottom-intersect')).toBeVisible()
})
it('should allow having items as links', async () => {
render(
<DropdownHelper
items={[
{
as: 'button',
href: 'https://example.com',
label: 'Example',
},
]}
label="menu"
/>,
)

userEvent.click(screen.getByText('menu'))

expect(screen.getByText('Example')).toHaveAttribute(
'href',
'https://example.com',
)
})
})
3 changes: 3 additions & 0 deletions components/src/components/molecules/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type DropdownItemObject = {
color?: Colors
disabled?: boolean
showIndicator?: boolean | Colors
href?: string
}

export type DropdownItem =
Expand Down Expand Up @@ -298,6 +299,7 @@ const DropdownMenu = React.forwardRef<HTMLDivElement, DropdownMenuProps>(
as,
wrapper,
showIndicator,
href,
} = item as DropdownItemObject

const props: React.ComponentProps<any> = {
Expand All @@ -316,6 +318,7 @@ const DropdownMenu = React.forwardRef<HTMLDivElement, DropdownMenuProps>(
{label}
</>
),
href,
}

if (wrapper) {
Expand Down

0 comments on commit f051ecb

Please sign in to comment.