Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Anchor = React.forwardRef<HTMLAnchorElement, AnchorProps>(
},
);

if ((isTrivialHref(props.href) && !props.role) || props.role === 'button') {
if (isTrivialHref(props.href) || props.role === 'button') {
return (
<a ref={ref} {...props} {...buttonProps} onKeyDown={handleKeyDown} />
);
Expand Down
6 changes: 4 additions & 2 deletions src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface UseButtonPropsOptions extends AnchorOptions {
onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
tabIndex?: number;
tagName?: keyof JSX.IntrinsicElements;
role?: React.AriaRole | undefined;
}

export function isTrivialHref(href?: string) {
Expand All @@ -23,7 +24,7 @@ export function isTrivialHref(href?: string) {
export interface AriaButtonProps {
type?: ButtonType | undefined;
disabled: boolean | undefined;
role?: 'button';
role?: React.AriaRole;
tabIndex?: number | undefined;
href?: string | undefined;
target?: string | undefined;
Expand All @@ -43,6 +44,7 @@ export function useButtonProps({
href,
target,
rel,
role,
onClick,
tabIndex = 0,
type,
Expand Down Expand Up @@ -90,7 +92,7 @@ export function useButtonProps({

return [
{
role: 'button',
role: role ?? 'button',
// explicitly undefined so that it overrides the props disabled in a spread
// e.g. <Tag {...props} {...hookProps} />
disabled: undefined,
Expand Down