Skip to content

Commit

Permalink
refactor(DropdownItem): make wrapping of children with anchor tag opt…
Browse files Browse the repository at this point in the history
…ional (#386)

* refactor(DropdownItem): make wrapping of children with anchor tag optional

* fix(DropdownItem): improved prop type check
  • Loading branch information
kodjunkie committed Jul 21, 2023
1 parent 2e3e354 commit 1c4aa85
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Dropdown/DropdownItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react'

export type DropdownItemProps = React.AnchorHTMLAttributes<HTMLAnchorElement>
type Anchor = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
anchor?: true
}

type NoAnchor = Pick<Anchor, 'children'> & { anchor?: false }

export type DropdownItemProps = Anchor | NoAnchor

const DropdownItem = React.forwardRef<HTMLAnchorElement, DropdownItemProps>(
({ className, ...props }, ref) => {
({ anchor = true, ...props }, ref) => {
return (
<li className={className} role="menuitem">
<a ref={ref} {...props}></a>
<li role="menuitem">
{anchor ? <a ref={ref} {...props}></a> : props.children}
</li>
)
}
Expand Down

0 comments on commit 1c4aa85

Please sign in to comment.