Skip to content

StepListItem: stepStateText should be included as part of the accessible name for the item #9881

@majornista

Description

@majornista

In order to conform with WCAG SC 2.5.3 Label in Name (Level A), the VisuallyHidden but still rendered stepStateText should be included as part of the accessibility name for the rendered link of each StepListItem.

Update the following code to include an id, stateId for the stepStateText VisuallyHidden element in the aria-labelledby for the link:

let stepStateText = '';
const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/steplist');
const numberFormatter = useNumberFormatter();
if (isSelected) {
stepStateText = stringFormatter.format('current');
} else if (isCompleted) {
stepStateText = stringFormatter.format('completed');
} else {
stepStateText = stringFormatter.format('notCompleted');
}
let markerId = useId();
let labelId = useId();
return (
<li
className={
classNames(
styles,
'spectrum-Steplist-item'
)
}>
<FocusRing within focusRingClass={classNames(styles, 'focus-ring')}>
<a
{...mergeProps(hoverProps, stepProps)}
aria-labelledby={`${markerId} ${labelId}`}
ref={ref}
className={classNames(
styles,
'spectrum-Steplist-link',
{
'is-selected': isSelected && !isItemDisabled,
'is-disabled': isItemDisabled,
'is-hovered': isHovered,
'is-completed': isCompleted,
'is-selectable': state.isSelectable(key) && !isSelected
}
)}>
<VisuallyHidden {...stepStateProps}>{stepStateText}</VisuallyHidden>

As follows:

 let stepStateText = ''; 
 const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/steplist'); 
 const numberFormatter = useNumberFormatter(); 
  
 if (isSelected) { 
   stepStateText = stringFormatter.format('current'); 
 } else if (isCompleted) { 
   stepStateText = stringFormatter.format('completed'); 
 } else { 
   stepStateText = stringFormatter.format('notCompleted'); 
 } 
  
 let markerId = useId();
 let stateId = useId();
 let labelId = useId();

 return ( 
   <li 
     className={ 
       classNames( 
         styles, 
         'spectrum-Steplist-item' 
       ) 
     }> 
     <FocusRing within focusRingClass={classNames(styles, 'focus-ring')}> 
       <a 
         {...mergeProps(hoverProps, stepProps)} 
         aria-labelledby={`${markerId} ${stateId} ${labelId}`} 
         ref={ref} 
         className={classNames( 
           styles, 
           'spectrum-Steplist-link', 
           { 
             'is-selected': isSelected && !isItemDisabled, 
             'is-disabled': isItemDisabled, 
             'is-hovered': isHovered, 
             'is-completed': isCompleted, 
             'is-selectable': state.isSelectable(key) && !isSelected 
           } 
         )}> 
         <VisuallyHidden id={stateId} {...stepStateProps}>{stepStateText}</VisuallyHidden>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions