@@ -18,12 +18,14 @@ interface BreadcrumbItemWithPopoverProps<T extends BreadcrumbGroupProps.Item> {
18
18
isLast : boolean ;
19
19
anchorAttributes : React . AnchorHTMLAttributes < HTMLAnchorElement > ;
20
20
children : React . ReactNode ;
21
+ itemAttributes : React . HTMLAttributes < HTMLElement > ;
21
22
}
22
23
23
24
const BreadcrumbItemWithPopover = < T extends BreadcrumbGroupProps . Item > ( {
24
25
item,
25
26
isLast,
26
27
anchorAttributes,
28
+ itemAttributes,
27
29
children,
28
30
} : BreadcrumbItemWithPopoverProps < T > ) => {
29
31
const [ showPopover , setShowPopover ] = useState ( false ) ;
@@ -54,7 +56,7 @@ const BreadcrumbItemWithPopover = <T extends BreadcrumbGroupProps.Item>({
54
56
} }
55
57
onMouseLeave = { ( ) => setShowPopover ( false ) }
56
58
anchorAttributes = { anchorAttributes }
57
- { ...( isLast ? { tabIndex : 0 } : { } ) }
59
+ { ...itemAttributes }
58
60
>
59
61
{ children }
60
62
</ Item >
@@ -68,16 +70,17 @@ type ItemProps = React.HTMLAttributes<HTMLElement> & {
68
70
isLast : boolean ;
69
71
} ;
70
72
const Item = React . forwardRef < HTMLElement , ItemProps > (
71
- ( { anchorAttributes, children, isLast, ...itemAttributes } , ref ) =>
72
- isLast ? (
73
+ ( { anchorAttributes, children, isLast, ...itemAttributes } , ref ) => {
74
+ return isLast ? (
73
75
< span ref = { ref } className = { styles . anchor } { ...itemAttributes } >
74
76
{ children }
75
77
</ span >
76
78
) : (
77
79
< a ref = { ref as React . Ref < HTMLAnchorElement > } className = { styles . anchor } { ...itemAttributes } { ...anchorAttributes } >
78
80
{ children }
79
81
</ a >
80
- )
82
+ ) ;
83
+ }
81
84
) ;
82
85
83
86
export function BreadcrumbItem < T extends BreadcrumbGroupProps . Item > ( {
@@ -101,11 +104,21 @@ export function BreadcrumbItem<T extends BreadcrumbGroupProps.Item>({
101
104
const anchorAttributes : React . AnchorHTMLAttributes < HTMLAnchorElement > = {
102
105
href : item . href || '#' ,
103
106
onClick : isLast ? preventDefault : onClickHandler ,
107
+ tabIndex : 0 ,
104
108
} ;
109
+
110
+ const itemAttributes : React . AnchorHTMLAttributes < HTMLAnchorElement > = { } ;
105
111
if ( isGhost ) {
106
112
anchorAttributes . tabIndex = - 1 ;
107
113
}
108
114
115
+ if ( isLast && ! isGhost ) {
116
+ itemAttributes [ 'aria-current' ] = 'page' ;
117
+ itemAttributes [ 'aria-disabled' ] = true ;
118
+ itemAttributes . tabIndex = 0 ;
119
+ itemAttributes . role = 'link' ;
120
+ }
121
+
109
122
const breadcrumbItem = (
110
123
< FunnelBreadcrumbItem
111
124
className = { styles . text }
@@ -119,11 +132,16 @@ export function BreadcrumbItem<T extends BreadcrumbGroupProps.Item>({
119
132
return (
120
133
< div className = { clsx ( ! isGhost && styles . breadcrumb , isGhost && styles [ 'ghost-breadcrumb' ] , isLast && styles . last ) } >
121
134
{ isTruncated && ! isGhost ? (
122
- < BreadcrumbItemWithPopover item = { item } isLast = { isLast } anchorAttributes = { anchorAttributes } >
135
+ < BreadcrumbItemWithPopover
136
+ item = { item }
137
+ isLast = { isLast }
138
+ anchorAttributes = { anchorAttributes }
139
+ itemAttributes = { itemAttributes }
140
+ >
123
141
{ breadcrumbItem }
124
142
</ BreadcrumbItemWithPopover >
125
143
) : (
126
- < Item isLast = { isLast } anchorAttributes = { anchorAttributes } >
144
+ < Item isLast = { isLast } anchorAttributes = { anchorAttributes } { ... itemAttributes } >
127
145
{ breadcrumbItem }
128
146
</ Item >
129
147
) }
0 commit comments