@@ -61,8 +61,13 @@ export function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefO
61
61
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62
62
let { descriptionProps : _ , ...stateWithoutDescription } = states ;
63
63
64
+ let isDisabled = state . disabledKeys . has ( item . key ) || item . props . isDisabled ;
64
65
let onKeyDown = ( e : KeyboardEvent ) => {
65
66
if ( e . key === 'Delete' || e . key === 'Backspace' ) {
67
+ if ( isDisabled ) {
68
+ return ;
69
+ }
70
+
66
71
e . preventDefault ( ) ;
67
72
if ( state . selectionManager . isSelected ( item . key ) ) {
68
73
onRemove ?.( new Set ( state . selectionManager . selectedKeys ) ) ;
@@ -79,20 +84,26 @@ export function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefO
79
84
let description = onRemove && ( modality === 'keyboard' || modality === 'virtual' ) ? stringFormatter . format ( 'removeDescription' ) : '' ;
80
85
let descProps = useDescription ( description ) ;
81
86
82
- let isFocused = item . key === state . selectionManager . focusedKey ;
87
+ let isItemFocused = item . key === state . selectionManager . focusedKey ;
88
+ let isFocused = state . selectionManager . focusedKey != null ;
89
+ let tabIndex = - 1 ;
90
+ if ( ! isDisabled && ( isItemFocused || ! isFocused ) ) {
91
+ tabIndex = 0 ;
92
+ }
93
+
83
94
let domProps = filterDOMProps ( item . props ) ;
84
95
let linkProps = useSyntheticLinkProps ( item . props ) ;
85
96
return {
86
97
removeButtonProps : {
87
98
'aria-label' : stringFormatter . format ( 'removeButtonLabel' ) ,
88
99
'aria-labelledby' : `${ buttonId } ${ rowProps . id } ` ,
89
- isDisabled : state . disabledKeys . has ( item . key ) || item . props . isDisabled ,
100
+ isDisabled,
90
101
id : buttonId ,
91
102
onPress : ( ) => onRemove ? onRemove ( new Set ( [ item . key ] ) ) : null ,
92
103
excludeFromTabOrder : true
93
104
} ,
94
105
rowProps : mergeProps ( rowProps , domProps , linkProps , {
95
- tabIndex : ( isFocused || state . selectionManager . focusedKey == null ) ? 0 : - 1 ,
106
+ tabIndex,
96
107
onKeyDown : onRemove ? onKeyDown : undefined ,
97
108
'aria-describedby' : descProps [ 'aria-describedby' ]
98
109
} ) ,
0 commit comments