Make WordPress Core


Ignore:
Timestamp:
06/21/2023 09:45:52 PM (17 months ago)
Author:
joedolson
Message:

Administration: Set accessible state for list table headers.

Implement aria-sort and change icon states to indicate current sort for list tables. Allow screen reader users to get context about the current sort and allow sighted users to know how the table is currently sorted.

Props afercia, rianrietveld, joedolson, alexstine, johnjamesjacoby.
Fixes #32170.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r55954 r55971  
    761761     */
    762762    protected function get_sortable_columns() {
    763         return array(
    764             'title'    => 'title',
    765             'parent'   => 'parent',
    766             'comments' => 'comment_count',
    767             'date'     => array( 'date', true ),
    768         );
     763
     764        $post_type = $this->screen->post_type;
     765
     766        if ( 'page' === $post_type ) {
     767            $title_orderby_text = isset( $_GET['orderby'] ) ? __( 'Table ordered by Title.' ) : __( 'Table ordered by Hierarchical Menu Order and Title.' );
     768            $sortables = array(
     769                'title'    => array( 'title', false, __( 'Title' ), $title_orderby_text, 'asc' ),
     770                'parent'   => array( 'parent', false ),
     771                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     772                'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ),
     773            );
     774        } else {
     775            $sortables = array(
     776                'title'    => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ),
     777                'parent'   => array( 'parent', false ),
     778                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     779                'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ),
     780            );
     781        }
     782        // Custom Post Types: there's a filter for that, see get_column_info().
     783
     784        return $sortables;
    769785    }
    770786
Note: See TracChangeset for help on using the changeset viewer.