Skip to content

Commit a18e665

Browse files
authored
fix(Anchor): don't check role when applying button props (#62)
1 parent 96cc91c commit a18e665

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Anchor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Anchor = React.forwardRef<HTMLAnchorElement, AnchorProps>(
3232
},
3333
);
3434

35-
if ((isTrivialHref(props.href) && !props.role) || props.role === 'button') {
35+
if (isTrivialHref(props.href) || props.role === 'button') {
3636
return (
3737
<a ref={ref} {...props} {...buttonProps} onKeyDown={handleKeyDown} />
3838
);

src/Button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface UseButtonPropsOptions extends AnchorOptions {
1414
onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
1515
tabIndex?: number;
1616
tagName?: keyof JSX.IntrinsicElements;
17+
role?: React.AriaRole | undefined;
1718
}
1819

1920
export function isTrivialHref(href?: string) {
@@ -23,7 +24,7 @@ export function isTrivialHref(href?: string) {
2324
export interface AriaButtonProps {
2425
type?: ButtonType | undefined;
2526
disabled: boolean | undefined;
26-
role?: 'button';
27+
role?: React.AriaRole;
2728
tabIndex?: number | undefined;
2829
href?: string | undefined;
2930
target?: string | undefined;
@@ -43,6 +44,7 @@ export function useButtonProps({
4344
href,
4445
target,
4546
rel,
47+
role,
4648
onClick,
4749
tabIndex = 0,
4850
type,
@@ -90,7 +92,7 @@ export function useButtonProps({
9092

9193
return [
9294
{
93-
role: 'button',
95+
role: role ?? 'button',
9496
// explicitly undefined so that it overrides the props disabled in a spread
9597
// e.g. <Tag {...props} {...hookProps} />
9698
disabled: undefined,

0 commit comments

Comments
 (0)