Add screen reader labels to table headers which are not buttons

This commit is contained in:
Albert Juhé Lluveras 2018-12-10 16:45:15 +01:00
parent 4cd01a3b3b
commit e8e67e8a76
1 changed files with 11 additions and 5 deletions

View File

@ -161,6 +161,15 @@ class Table extends Component {
? sprintf( __( 'Sort by %s in ascending order', 'wc-admin' ), screenReaderLabel )
: sprintf( __( 'Sort by %s in descending order', 'wc-admin' ), screenReaderLabel );
const textLabel = (
<Fragment>
<span aria-hidden={ Boolean( screenReaderLabel ) }>{ label }</span>
{ screenReaderLabel && (
<span className="screen-reader-text">{ screenReaderLabel }</span>
) }
</Fragment>
);
return (
<th role="columnheader" scope="col" key={ i } { ...thProps }>
{ isSortable ? (
@ -177,17 +186,14 @@ class Table extends Component {
onClick={ this.sortBy( key ) }
isDefault
>
<span aria-hidden={ Boolean( screenReaderLabel ) }>{ label }</span>
{ screenReaderLabel && (
<span className="screen-reader-text">{ screenReaderLabel }</span>
) }
{ textLabel }
</IconButton>
<span className="screen-reader-text" id={ labelId }>
{ iconLabel }
</span>
</Fragment>
) : (
label
textLabel
) }
</th>
);