Make WordPress Core

Ticket #34668: 34668.4.patch

File 34668.4.patch, 6.8 KB (added by joedolson, 15 months ago)

Refresh patch & collapse profile links

  • src/js/_enqueues/lib/admin-bar.js

     
    3131
    3232                topMenuItems = adminBar.querySelectorAll( 'li.menupop' );
    3333                allMenuItems = adminBar.querySelectorAll( '.ab-item' );
    34                 adminBarLogout = document.getElementById( 'wp-admin-bar-logout' );
     34                adminBarLogout = document.querySelector( '#wp-admin-bar-logout a' );
    3535                adminBarSearchForm = document.getElementById( 'adminbarsearch' );
    3636                shortlink = document.getElementById( 'wp-admin-bar-get-shortlink' );
    3737                skipLink = adminBar.querySelector( '.screen-reader-shortcut' );
     
    149149        function toggleHoverIfEnter( event ) {
    150150                var wrapper;
    151151
    152                 if ( event.which !== 13 ) {
     152                // Follow link if pressing Ctrl and/or Shift with Enter (opening in a new tab or window).
     153                if ( event.which !== 13 || event.ctrlKey || event.shiftKey ) {
    153154                        return;
    154155                }
    155156
     
    336337
    337338                        element.className += className;
    338339                }
     340
     341                var menuItemToggle = element.querySelector( 'a' );
     342                if ( className === 'hover' && menuItemToggle && menuItemToggle.hasAttribute( 'aria-expanded' ) ) {
     343                        menuItemToggle.setAttribute( 'aria-expanded', 'true' );
     344                }
    339345        }
    340346
    341347        /**
     
    366372
    367373                        element.className = classes.replace( /^[\s]+|[\s]+$/g, '' );
    368374                }
     375
     376                var menuItemToggle = element.querySelector( 'a' );
     377                if ( className === 'hover' && menuItemToggle && menuItemToggle.hasAttribute( 'aria-expanded' ) ) {
     378                        menuItemToggle.setAttribute( 'aria-expanded', 'false' );
     379                }
    369380        }
    370381
    371382        /**
  • src/wp-includes/admin-bar.php

     
    139139                                __( 'About WordPress' ) .
    140140                        '</span>',
    141141                'href'  => $about_url,
     142                'meta' => array(
     143                        'menu_title' => __( 'About WordPress' ),
     144                ),
    142145        );
    143146
    144147        // Set tabindex="0" to make sub menus accessible when no URL is available.
     
    283286                        'href'   => $profile_url,
    284287                        'meta'   => array(
    285288                                'class' => $class,
     289                                'menu_title' => sprintf( __( 'Howdy, %s' ), $current_user->display_name ),
    286290                        ),
    287291                )
    288292        );
     
    325329                $user_info .= "<span class='username'>{$current_user->user_login}</span>";
    326330        }
    327331
     332        $user_info .= "<span class='edit-profile'>" . __( 'Edit Profile' ) . '</span>';
     333
    328334        $wp_admin_bar->add_node(
    329335                array(
    330336                        'parent' => 'user-actions',
     
    331337                        'id'     => 'user-info',
    332338                        'title'  => $user_info,
    333339                        'href'   => $profile_url,
    334                         'meta'   => array(
    335                                 'tabindex' => -1,
    336                         ),
    337340                )
    338341        );
    339342
    340         if ( false !== $profile_url ) {
    341                 $wp_admin_bar->add_node(
    342                         array(
    343                                 'parent' => 'user-actions',
    344                                 'id'     => 'edit-profile',
    345                                 'title'  => __( 'Edit Profile' ),
    346                                 'href'   => $profile_url,
    347                         )
    348                 );
    349         }
    350 
    351343        $wp_admin_bar->add_node(
    352344                array(
    353345                        'parent' => 'user-actions',
     
    397389                        'id'    => 'site-name',
    398390                        'title' => $title,
    399391                        'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
     392                        'meta' => array(
     393                                'menu_title' => $title,
     394                        ),
    400395                )
    401396        );
    402397
     
    993988                        'id'    => 'new-content',
    994989                        'title' => $title,
    995990                        'href'  => admin_url( current( array_keys( $actions ) ) ),
     991                        'meta' => array(
     992                                'menu_title' => _x( 'New', 'admin bar menu group label' ),
     993                        ),
    996994                )
    997995        );
    998996
  • src/wp-includes/class-wp-admin-bar.php

     
    117117         *     @type string $href   Optional. Link for the item.
    118118         *     @type bool   $group  Optional. Whether or not the node is a group. Default false.
    119119         *     @type array  $meta   Meta data including the following keys: 'html', 'class', 'rel', 'lang', 'dir',
    120          *                          'onclick', 'target', 'title', 'tabindex'. Default empty.
     120         *                          'onclick', 'target', 'title', 'tabindex', 'menu_title. Default empty.
    121121         * }
    122122         */
    123123        public function add_node( $args ) {
     
    478478                                }
    479479                                ?>
    480480                        </div>
    481                         <?php if ( is_user_logged_in() ) : ?>
    482                         <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e( 'Log Out' ); ?></a>
    483                         <?php endif; ?>
    484481                </div>
    485482
    486483                <?php
     
    507504         * @since 3.3.0
    508505         *
    509506         * @param object $node
     507         * @param string $menu_title
    510508         */
    511         final protected function _render_group( $node ) {
     509        final protected function _render_group( $node, $menu_title = false ) {
    512510                if ( 'container' === $node->type ) {
    513511                        $this->_render_container( $node );
    514512                        return;
     
    523521                        $class = '';
    524522                }
    525523
    526                 echo "<ul id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>";
     524                if ( empty( $menu_title ) ) {
     525                                echo "<ul role='menu' id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>";
     526                        } else {
     527                                echo "<ul role='menu' aria-label='" . esc_attr( $menu_title ) . "' id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>";
     528                        }
    527529                foreach ( $node->children as $item ) {
    528530                        $this->_render_item( $item );
    529531                }
    530                 echo '</ul>';
     532                        echo "</ul>";
    531533        }
    532534
    533535        /**
     
    548550                // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y.
    549551                $tabindex        = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
    550552                $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';
     553                $aria_attributes .= ' role="menuitem"';
    551554
    552555                $menuclass = '';
    553556                $arrow     = '';
     
    554557
    555558                if ( $is_parent ) {
    556559                        $menuclass        = 'menupop ';
    557                         $aria_attributes .= ' aria-haspopup="true"';
     560                        $aria_attributes .= ' aria-expanded="false"';
    558561                }
    559562
    560563                if ( ! empty( $node->meta['class'] ) ) {
     
    603606                if ( $is_parent ) {
    604607                        echo '<div class="ab-sub-wrapper">';
    605608                        foreach ( $node->children as $group ) {
    606                                 $this->_render_group( $group );
     609                                if ( empty( $node->meta[ 'menu_title' ] ) ) {
     610                                        $this->_render_group( $group, false );
     611                                } else {
     612                                        $this->_render_group( $group, $node->meta[ 'menu_title' ] );
     613                                }
    607614                        }
    608615                        echo '</div>';
    609616                }
  • src/wp-includes/css/admin-bar.css

     
    447447        background: none;
    448448}
    449449
     450#wpadminbar #wp-admin-bar-user-info a {
     451        display: grid;
     452        row-gap: 12px;
     453}
     454
    450455#wp-admin-bar-user-info .avatar {
    451456        position: absolute;
    452457        left: -72px;