Make WordPress Core


Ignore:
Timestamp:
07/12/2016 11:18:00 AM (8 years ago)
Author:
ocean90
Message:

Toolbar: Allow 0 as a value for the tabindex property of a menu item.

To enhance accessibility for items without a link you can now define tabindex="0", which makes descendant dropdowns accessible.

Props joedolson, afercia, ocean90.
Fixes #32495.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-admin-bar.php

    r37985 r38035  
    478478        $has_link  = ! empty( $node->href );
    479479
    480         $tabindex = isset( $node->meta['tabindex'] ) ? (int) $node->meta['tabindex'] : '';
    481         $aria_attributes = $tabindex ? 'tabindex="' . $tabindex . '"' : '';
     480        // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y.
     481        $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
     482        $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';
    482483
    483484        $menuclass = '';
     
    498499        <li id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>"<?php echo $menuclass; ?>><?php
    499500            if ( $has_link ):
    500                 ?><a class="ab-item" <?php echo $aria_attributes; ?> href="<?php echo esc_url( $node->href ) ?>"<?php
     501                ?><a class="ab-item"<?php echo $aria_attributes; ?> href="<?php echo esc_url( $node->href ) ?>"<?php
    501502                    if ( ! empty( $node->meta['onclick'] ) ) :
    502503                        ?> onclick="<?php echo esc_js( $node->meta['onclick'] ); ?>"<?php
     
    519520                ?>><?php
    520521            else:
    521                 ?><div class="ab-item ab-empty-item" <?php echo $aria_attributes;
     522                ?><div class="ab-item ab-empty-item"<?php echo $aria_attributes;
    522523                if ( ! empty( $node->meta['title'] ) ) :
    523524                    ?> title="<?php echo esc_attr( $node->meta['title'] ); ?>"<?php
Note: See TracChangeset for help on using the changeset viewer.