@@ -61,8 +61,13 @@ export function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefO
6161 // eslint-disable-next-line @typescript-eslint/no-unused-vars
6262 let { descriptionProps : _ , ...stateWithoutDescription } = states ;
6363
64+ let isDisabled = state . disabledKeys . has ( item . key ) || item . props . isDisabled ;
6465 let onKeyDown = ( e : KeyboardEvent ) => {
6566 if ( e . key === 'Delete' || e . key === 'Backspace' ) {
67+ if ( isDisabled ) {
68+ return ;
69+ }
70+
6671 e . preventDefault ( ) ;
6772 if ( state . selectionManager . isSelected ( item . key ) ) {
6873 onRemove ?.( new Set ( state . selectionManager . selectedKeys ) ) ;
@@ -79,20 +84,26 @@ export function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefO
7984 let description = onRemove && ( modality === 'keyboard' || modality === 'virtual' ) ? stringFormatter . format ( 'removeDescription' ) : '' ;
8085 let descProps = useDescription ( description ) ;
8186
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+
8394 let domProps = filterDOMProps ( item . props ) ;
8495 let linkProps = useSyntheticLinkProps ( item . props ) ;
8596 return {
8697 removeButtonProps : {
8798 'aria-label' : stringFormatter . format ( 'removeButtonLabel' ) ,
8899 'aria-labelledby' : `${ buttonId } ${ rowProps . id } ` ,
89- isDisabled : state . disabledKeys . has ( item . key ) || item . props . isDisabled ,
100+ isDisabled,
90101 id : buttonId ,
91102 onPress : ( ) => onRemove ? onRemove ( new Set ( [ item . key ] ) ) : null ,
92103 excludeFromTabOrder : true
93104 } ,
94105 rowProps : mergeProps ( rowProps , domProps , linkProps , {
95- tabIndex : ( isFocused || state . selectionManager . focusedKey == null ) ? 0 : - 1 ,
106+ tabIndex,
96107 onKeyDown : onRemove ? onKeyDown : undefined ,
97108 'aria-describedby' : descProps [ 'aria-describedby' ]
98109 } ) ,
0 commit comments