Skip to content

Commit 1f7f585

Browse files
authored
fix(AnchorButton) Fix missing default tab index (#7116)
1 parent c3cf203 commit 1f7f585

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/core/src/accessibility/useInteractiveAttributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface InteractiveAttributes<E extends HTMLElement> extends InteractiveHTMLAt
1919
ref: React.Ref<E>;
2020
}
2121

22-
interface UseInteractiveAttributesOptions {
22+
export interface UseInteractiveAttributesOptions {
2323
defaultTabIndex: number | undefined;
2424
disabledTabIndex: number | undefined;
2525
}

packages/core/src/components/button/buttons.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import classNames from "classnames";
1818
import * as React from "react";
1919

20-
import { useInteractiveAttributes } from "../../accessibility/useInteractiveAttributes";
20+
import {
21+
useInteractiveAttributes,
22+
type UseInteractiveAttributesOptions,
23+
} from "../../accessibility/useInteractiveAttributes";
2124
import { Classes, Utils } from "../../common";
2225
import { DISPLAYNAME_PREFIX, removeNonHTMLProps } from "../../common/props";
2326
import { Icon } from "../icon/icon";
@@ -50,7 +53,10 @@ Button.displayName = `${DISPLAYNAME_PREFIX}.Button`;
5053
export const AnchorButton: React.FC<AnchorButtonProps> = React.forwardRef<HTMLAnchorElement, AnchorButtonProps>(
5154
(props, ref) => {
5255
const { href } = props;
53-
const commonProps = useSharedButtonAttributes(props, ref);
56+
const commonProps = useSharedButtonAttributes(props, ref, {
57+
defaultTabIndex: 0,
58+
disabledTabIndex: -1,
59+
});
5460

5561
return (
5662
<a
@@ -73,11 +79,12 @@ AnchorButton.displayName = `${DISPLAYNAME_PREFIX}.AnchorButton`;
7379
function useSharedButtonAttributes<E extends HTMLAnchorElement | HTMLButtonElement>(
7480
props: E extends HTMLAnchorElement ? AnchorButtonProps : ButtonProps,
7581
ref: React.Ref<E>,
82+
options?: UseInteractiveAttributesOptions,
7683
) {
7784
const { alignText, fill, large, loading = false, minimal, outlined, small } = props;
7885
const disabled = props.disabled || loading;
7986

80-
const [active, interactiveProps] = useInteractiveAttributes(!disabled, props, ref);
87+
const [active, interactiveProps] = useInteractiveAttributes(!disabled, props, ref, options);
8188

8289
const className = classNames(
8390
Classes.BUTTON,

0 commit comments

Comments
 (0)