Skip to content

Commit 83696c0

Browse files
committed
fix(ui-breadcrumb): fix Breadcrumb accessibility issues
INSTUI-4676
1 parent e66ad32 commit 83696c0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/ui-breadcrumb/src/Breadcrumb/BreadcrumbLink/index.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class BreadcrumbLink extends Component<
6868
this.setState({ isTruncated })
6969
}
7070
}
71+
7172
render() {
7273
const {
7374
children,
@@ -82,8 +83,15 @@ class BreadcrumbLink extends Component<
8283
const { isTruncated } = this.state
8384
const props = omitProps(this.props, BreadcrumbLink.allowedProps)
8485

86+
const isInteractive = onClick || href
8587
return (
86-
<Tooltip renderTip={children} preventTooltip={!isTruncated}>
88+
<Tooltip
89+
renderTip={children}
90+
preventTooltip={!isTruncated}
91+
// this wraps the achor tag in a span and puts the aria-describedby on that instead of the anchor tag
92+
// to avoid SRs reading the text twice when there is already an aria-label
93+
{...(href && { as: 'span' })}
94+
>
8795
<Link
8896
{...props}
8997
href={href}
@@ -95,6 +103,13 @@ class BreadcrumbLink extends Component<
95103
elementRef={this.handleRef}
96104
forceButtonRole={false}
97105
{...(isCurrentPage && { 'aria-current': 'page' })}
106+
{...(isTruncated &&
107+
// put an aria-label on it when it's just a text (e.g. neither a button or a link)
108+
// or when it's a link (to have discernible text see: https://dequeuniversity.com/rules/axe/4.10/link-name)
109+
(!isInteractive || href) && {
110+
...(typeof children === 'string' && { 'aria-label': children }),
111+
...(!isInteractive && { role: 'text' })
112+
})}
98113
>
99114
<TruncateText
100115
onUpdate={(isTruncated) => this.handleTruncation(isTruncated)}

0 commit comments

Comments
 (0)