Skip to content

Commit

Permalink
fix(component): Remove type="button" when not a <button> (#217)
Browse files Browse the repository at this point in the history
`ListGroup.Item`s currently have `type="button"` always,
even though they can be an anchor (`<a>`) element
instead. That's changed now.

Also adds `props` since they weren't being passed
in for some reason.
  • Loading branch information
tulup-conner authored Jul 1, 2022
1 parent 1baed8e commit 8c7012e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/lib/components/ListGroup/ListGroupItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import type { ComponentProps, FC, PropsWithChildren } from 'react';
import { excludeClassName } from '../../helpers/exclude';
import { useTheme } from '../Flowbite/ThemeContext';

export interface ListGroupItemProps extends PropsWithChildren<Omit<ComponentProps<'a' | 'button'>, 'className'>> {
Expand All @@ -16,22 +17,23 @@ export const ListGroupItem: FC<ListGroupItemProps> = ({
href,
icon: Icon,
onClick,
...props
}): JSX.Element => {
const theme = useTheme().theme.listGroup.item;
const isLink = typeof href !== 'undefined';

const Component = isLink ? 'a' : 'button';
const theirProps = excludeClassName(props);

const Component = typeof href === 'undefined' ? 'button' : 'a';
const theme = useTheme().theme.listGroup.item;

return (
<li>
<Component
className={classNames(
theme.active[isActive ? 'on' : 'off'],
theme.base,
theme.href[typeof href === 'undefined' ? 'off' : 'on'],
)}
className={classNames(theme.active[isActive ? 'on' : 'off'], theme.base, theme.href[isLink ? 'on' : 'off'])}
href={href}
onClick={onClick}
type="button"
type={isLink ? undefined : 'button'}
{...theirProps}
>
{Icon && <Icon aria-hidden className={theme.icon} data-testid="flowbite-list-group-item-icon" />}
{children}
Expand Down

0 comments on commit 8c7012e

Please sign in to comment.