@@ -22,7 +22,9 @@ export interface BreadcrumbsProps<T> extends Omit<CollectionProps<T>, 'disabledK
22
22
/** Whether the breadcrumbs are disabled. */
23
23
isDisabled ?: boolean ,
24
24
/** Handler that is called when a breadcrumb is clicked. */
25
- onAction ?: ( key : Key ) => void
25
+ onAction ?: ( key : Key ) => void ,
26
+ /** Whether to autoFocus the last Breadcrumb item when the Breadcrumbs render. */
27
+ autoFocusCurrent ?: boolean
26
28
}
27
29
28
30
export const BreadcrumbsContext = createContext < ContextValue < BreadcrumbsProps < any > , HTMLOListElement > > ( null ) ;
@@ -54,14 +56,18 @@ function BreadcrumbsInner<T extends object>({props, collection, breadcrumbsRef:
54
56
slot = { props . slot || undefined }
55
57
style = { props . style }
56
58
className = { props . className ?? 'react-aria-Breadcrumbs' } >
57
- { [ ...collection ] . map ( ( node , i ) => (
58
- < BreadcrumbItem
59
- key = { node . key }
60
- node = { node }
61
- isCurrent = { i === collection . size - 1 }
62
- isDisabled = { props . isDisabled }
63
- onAction = { props . onAction } />
64
- ) ) }
59
+ { [ ...collection ] . map ( ( node , i ) => {
60
+ let isCurrent = i === collection . size - 1 ;
61
+ return (
62
+ < BreadcrumbItem
63
+ key = { node . key }
64
+ node = { node }
65
+ isCurrent = { isCurrent }
66
+ isDisabled = { props . isDisabled }
67
+ onAction = { props . onAction }
68
+ autoFocus = { props . autoFocusCurrent && isCurrent } />
69
+ ) ;
70
+ } ) }
65
71
</ ol >
66
72
) ;
67
73
}
@@ -93,15 +99,17 @@ interface BreadcrumbItemProps {
93
99
node : Node < object > ,
94
100
isCurrent : boolean ,
95
101
isDisabled ?: boolean ,
96
- onAction ?: ( key : Key ) => void
102
+ onAction ?: ( key : Key ) => void ,
103
+ autoFocus ?: boolean
97
104
}
98
105
99
- function BreadcrumbItem ( { node, isCurrent, isDisabled, onAction} : BreadcrumbItemProps ) {
106
+ function BreadcrumbItem ( { node, isCurrent, isDisabled, onAction, autoFocus } : BreadcrumbItemProps ) {
100
107
// Recreating useBreadcrumbItem because we want to use composition instead of having the link builtin.
101
108
let linkProps = {
102
109
'aria-current' : isCurrent ? 'page' : null ,
103
110
isDisabled : isDisabled || isCurrent ,
104
- onPress : ( ) => onAction ?.( node . key )
111
+ onPress : ( ) => onAction ?.( node . key ) ,
112
+ autoFocus : autoFocus
105
113
} ;
106
114
107
115
return (
0 commit comments