@@ -147,11 +147,12 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
147
147
// eslint-disable-next-line react-hooks/exhaustive-deps
148
148
} , [ ref , key , manager . focusedKey , manager . childFocusStrategy , manager . isFocused , shouldUseVirtualFocus ] ) ;
149
149
150
+ isDisabled = isDisabled || manager . isDisabled ( key ) ;
150
151
// Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
151
152
// item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
152
153
// on iOS 14 doesn't try to move real DOM focus to the item anyway.
153
154
let itemProps : SelectableItemAria [ 'itemProps' ] = { } ;
154
- if ( ! shouldUseVirtualFocus ) {
155
+ if ( ! shouldUseVirtualFocus && ! isDisabled ) {
155
156
itemProps = {
156
157
tabIndex : key === manager . focusedKey ? 0 : - 1 ,
157
158
onFocus ( e ) {
@@ -160,14 +161,17 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
160
161
}
161
162
}
162
163
} ;
164
+ } else if ( isDisabled ) {
165
+ itemProps . onMouseDown = ( e ) => {
166
+ // Prevent focus going to the body when clicking on a disabled item.
167
+ e . preventDefault ( ) ;
168
+ } ;
163
169
}
164
170
165
-
166
171
// With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.
167
172
// Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.
168
173
// With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.
169
174
// With touch, onAction occurs on single tap, and long press enters selection mode.
170
- isDisabled = isDisabled || manager . isDisabled ( key ) ;
171
175
let allowsSelection = ! isDisabled && manager . canSelectItem ( key ) ;
172
176
let allowsActions = onAction && ! isDisabled ;
173
177
let hasPrimaryAction = allowsActions && (
0 commit comments