1111 */
1212
1313import { AriaButtonProps } from '@react-types/button' ;
14- import { chain , filterDOMProps , mergeProps , useId } from '@react-aria/utils' ;
14+ import { chain , filterDOMProps , mergeProps , useDescription , useId } from '@react-aria/utils' ;
1515import { DOMAttributes , FocusableElement } from '@react-types/shared' ;
1616// @ts -ignore
1717import intlMessages from '../intl/*.json' ;
1818import { KeyboardEvent , RefObject } from 'react' ;
1919import type { TagGroupState } from '@react-stately/tag' ;
2020import { TagProps } from '@react-types/tag' ;
2121import { useGridListItem } from '@react-aria/gridlist' ;
22+ import { useInteractionModality } from '@react-aria/interactions' ;
2223import { useLocalizedStringFormatter } from '@react-aria/i18n' ;
2324
2425
@@ -46,7 +47,6 @@ export function useTag<T>(props: TagProps<T>, state: TagGroupState<T>, ref: RefO
4647 item
4748 } = props ;
4849 let stringFormatter = useLocalizedStringFormatter ( intlMessages ) ;
49- let removeString = stringFormatter . format ( 'remove' ) ;
5050 let labelId = useId ( ) ;
5151 let buttonId = useId ( ) ;
5252
@@ -66,11 +66,18 @@ export function useTag<T>(props: TagProps<T>, state: TagGroupState<T>, ref: RefO
6666 }
6767 } ;
6868
69+ let modality : string = useInteractionModality ( ) ;
70+ if ( modality === 'virtual' && ( typeof window !== 'undefined' && 'ontouchstart' in window ) ) {
71+ modality = 'touch' ;
72+ }
73+ let description = allowsRemoving && ( modality === 'keyboard' || modality === 'virtual' ) ? stringFormatter . format ( 'removeDescription' ) : '' ;
74+ let descProps = useDescription ( description ) ;
75+
6976 isFocused = isFocused || state . selectionManager . focusedKey === item . key ;
7077 let domProps = filterDOMProps ( props ) ;
7178 return {
7279 clearButtonProps : {
73- 'aria-label' : removeString ,
80+ 'aria-label' : stringFormatter . format ( 'removeButtonLabel' , { label : item . textValue } ) ,
7481 'aria-labelledby' : `${ buttonId } ${ labelId } ` ,
7582 id : buttonId ,
7683 onPress : ( ) => allowsRemoving && onRemove ? onRemove ( item . key ) : null ,
@@ -82,7 +89,8 @@ export function useTag<T>(props: TagProps<T>, state: TagGroupState<T>, ref: RefO
8289 rowProps : {
8390 ...rowProps ,
8491 tabIndex : ( isFocused || state . selectionManager . focusedKey == null ) ? 0 : - 1 ,
85- onKeyDown : allowsRemoving ? onKeyDown : null
92+ onKeyDown : allowsRemoving ? onKeyDown : null ,
93+ 'aria-describedby' : descProps [ 'aria-describedby' ]
8694 } ,
8795 gridCellProps : mergeProps ( domProps , gridCellProps , {
8896 'aria-errormessage' : props [ 'aria-errormessage' ] ,
0 commit comments