Skip to content

Commit

Permalink
Merge pull request #143 from ensdomains/dropdown-href
Browse files Browse the repository at this point in the history
allow passing href to a dropdown item
  • Loading branch information
talentlessguy authored Mar 29, 2024
2 parents f397363 + f051ecb commit 6a3d740
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 6a3d740

Please sign in to comment.