@@ -112,7 +112,11 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
112
112
} = React . useContext ( ListContext )
113
113
const { selectionVariant : groupSelectionVariant } = React . useContext ( GroupContext )
114
114
const inactive = Boolean ( inactiveText )
115
- const showInactiveIndicator = inactive && container === undefined
115
+ // TODO change `menuContext` check to ```listRole !== undefined && ['menu', 'listbox'].includes(listRole)```
116
+ // once we have a better way to handle existing usage in dotcom that incorrectly use ActionList.TrailingAction
117
+ const menuContext = container === 'ActionMenu' || container === 'SelectPanel'
118
+ // TODO: when we change `menuContext` to check `listRole` instead of `container`
119
+ const showInactiveIndicator = inactive && ! ( listRole !== undefined && [ 'menu' , 'listbox' ] . includes ( listRole ) )
116
120
117
121
const onSelect = React . useCallback (
118
122
(
@@ -142,10 +146,12 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
142
146
}
143
147
144
148
const itemRole = role || inferredItemRole
145
- const menuContext = container === 'ActionMenu' || container === 'SelectPanel'
146
149
147
150
if ( slots . trailingAction ) {
148
- invariant ( ! menuContext , `ActionList.TrailingAction can not be used within a ${ container } .` )
151
+ invariant (
152
+ ! menuContext ,
153
+ `ActionList.TrailingAction can not be used within a list with an ARIA role of "menu" or "listbox".` ,
154
+ )
149
155
}
150
156
151
157
/** Infer the proper selection attribute based on the item's role */
@@ -405,7 +411,8 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
405
411
< span id = { labelId } className = { classes . ItemLabel } >
406
412
{ childrenWithoutSlots }
407
413
{ /* Loading message needs to be in here so it is read with the label */ }
408
- { loading === true && < VisuallyHidden > Loading</ VisuallyHidden > }
414
+ { /* If the item is inactive, we do not simultaneously announce that it is loading */ }
415
+ { loading === true && ! inactive && < VisuallyHidden > Loading</ VisuallyHidden > }
409
416
</ span >
410
417
{ slots . description }
411
418
</ ConditionalWrapper >
@@ -422,7 +429,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
422
429
{
423
430
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
424
431
// render the inactive warning message directly in the item.
425
- inactive && container ? (
432
+ ! showInactiveIndicator ? (
426
433
< span className = { classes . InactiveWarning } id = { inactiveWarningId } >
427
434
{ inactiveText }
428
435
</ span >
@@ -477,7 +484,8 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
477
484
< span id = { labelId } className = { classes . ItemLabel } >
478
485
{ childrenWithoutSlots }
479
486
{ /* Loading message needs to be in here so it is read with the label */ }
480
- { loading === true && < VisuallyHidden > Loading</ VisuallyHidden > }
487
+ { /* If the item is inactive, we do not simultaneously announce that it is loading */ }
488
+ { loading === true && ! inactive && < VisuallyHidden > Loading</ VisuallyHidden > }
481
489
</ span >
482
490
{ slots . description }
483
491
</ ConditionalWrapper >
@@ -494,7 +502,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
494
502
{
495
503
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
496
504
// render the inactive warning message directly in the item.
497
- inactive && container ? (
505
+ ! showInactiveIndicator ? (
498
506
< span className = { classes . InactiveWarning } id = { inactiveWarningId } >
499
507
{ inactiveText }
500
508
</ span >
@@ -567,7 +575,8 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
567
575
>
568
576
{ childrenWithoutSlots }
569
577
{ /* Loading message needs to be in here so it is read with the label */ }
570
- { loading === true && < VisuallyHidden > Loading</ VisuallyHidden > }
578
+ { /* If the item is inactive, we do not simultaneously announce that it is loading */ }
579
+ { loading === true && ! inactive && < VisuallyHidden > Loading</ VisuallyHidden > }
571
580
</ Box >
572
581
{ slots . inlineDescription }
573
582
</ ConditionalWrapper >
@@ -584,7 +593,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
584
593
{
585
594
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
586
595
// render the inactive warning message directly in the item.
587
- inactive && container ? (
596
+ ! showInactiveIndicator ? (
588
597
< Box
589
598
as = "span"
590
599
sx = { {
0 commit comments