Make WordPress Core

Changeset 38709


Ignore:
Timestamp:
10/03/2016 04:27:55 PM (8 years ago)
Author:
afercia
Message:

Customize: Improve the widgets and menu items search.

  • adds a "search" icon into the search fields
  • adds a hidden description for the widget search field, targeted by aria-describedby
  • adds the "clear-results" button to the widgets search
  • removes the change and search events bound on the widget search, for these "live searches" WordPress should standardize on input (+ keyup when needed)
  • adds property and function to keep track and update the number of the widgets search results
  • the widgets search results are now announced via wp.a11y.speak()
  • adds a visible and audible message when there are no widgets search results
  • moves some CSS to customize-controls.css

Props ryankienstra, melchoyce, afercia.
Fixes #36908.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/customize-controls.css

    r38672 r38709  
    14101410    bottom: 0;
    14111411    width: 100%;
     1412    border-top: 1px solid #ddd;
     1413}
     1414
     1415.no-widgets-found #available-widgets-list {
     1416    border-top: none;
    14121417}
    14131418
     
    14181423    width: 300px;
    14191424    background: #eee;
    1420     border-bottom: 1px solid #e5e5e5;
    14211425}
    14221426
     
    14241428#available-widgets-filter,
    14251429#available-menu-items-search .accordion-section-title {
    1426     padding: 12px 15px;
     1430    padding: 13px 15px;
    14271431    -webkit-box-sizing: border-box;
    14281432    -moz-box-sizing: border-box;
     
    14321436#available-widgets-filter input,
    14331437#available-menu-items-search input {
    1434     padding: 6px 10px;
    1435     width: 100%;
     1438    width: 100%;
     1439    height: 32px;
     1440    margin: 1px 0;
     1441    padding: 6px 30px;
     1442}
     1443
     1444#available-widgets-filter input::-ms-clear,
     1445#available-menu-items-search input::-ms-clear {
     1446    display: none; /* remove the "x" in IE, which conflicts with the "x" icon on button.clear-results */
     1447}
     1448
     1449#available-menu-items-search .search-icon,
     1450#available-widgets-filter .search-icon {
     1451    display: block;
     1452    position: absolute;
     1453    top: 15px; /* 13 container padding +1 input margin +1 input border */
     1454    left: 16px;
     1455    width: 30px;
     1456    height: 30px;
     1457    line-height: 28px;
     1458    text-align: center;
     1459    color: #72777c;
     1460}
     1461
     1462#available-widgets-filter .clear-results,
     1463#available-menu-items-search .clear-results {
     1464    position: absolute;
     1465    top: 15px; /* 13 container padding +1 input margin +1 input border */
     1466    right: 16px;
     1467    width: 30px;
     1468    height: 30px;
     1469    padding: 0;
     1470    border: 0;
     1471    cursor: pointer;
     1472    background: none;
     1473    color: #a00;
     1474    text-decoration: none;
     1475    outline: 0;
     1476}
     1477
     1478#available-widgets-filter .clear-results,
     1479#available-menu-items-search .clear-results,
     1480#available-menu-items-search.loading .clear-results.is-visible {
     1481    display: none;
     1482}
     1483
     1484#available-widgets-filter .clear-results.is-visible,
     1485#available-menu-items-search .clear-results.is-visible {
     1486    display: block;
     1487}
     1488
     1489#available-widgets-filter .clear-results:before,
     1490#available-menu-items-search .clear-results:before {
     1491    content: "\f335";
     1492    font: normal 20px/1 dashicons;
     1493    vertical-align: middle;
     1494    -webkit-font-smoothing: antialiased;
     1495    -moz-osx-font-smoothing: grayscale;
     1496}
     1497
     1498#available-widgets-filter .clear-results:hover,
     1499#available-widgets-filter .clear-results:focus,
     1500#available-menu-items-search .clear-results:hover,
     1501#available-menu-items-search .clear-results:focus {
     1502    color: #dc3232;
     1503}
     1504
     1505#available-widgets-filter .clear-results:focus,
     1506#available-menu-items-search .clear-results:focus {
     1507    -webkit-box-shadow:
     1508        0 0 0 1px #5b9dd9,
     1509        0 0 2px 1px rgba(30, 140, 190, .8);
     1510    box-shadow:
     1511        0 0 0 1px #5b9dd9,
     1512        0 0 2px 1px rgba(30, 140, 190, .8);
     1513}
     1514
     1515#available-menu-items-search .search-icon:after,
     1516#available-widgets-filter .search-icon:after {
     1517    content: "\f179";
     1518    font: normal 20px/1 dashicons;
     1519    vertical-align: middle;
     1520    -webkit-font-smoothing: antialiased;
     1521    -moz-osx-font-smoothing: grayscale;
     1522}
     1523
     1524.no-widgets-found-message {
     1525    display: none;
     1526    margin: 0;
     1527    padding: 0 15px;
     1528    line-height: inherit;
     1529}
     1530
     1531.no-widgets-found .no-widgets-found-message {
     1532    display: block;
    14361533}
    14371534
     
    14511548    padding: 20px 15px 20px 60px;
    14521549    background: #fff;
    1453     border-bottom: 1px solid #e5e5e5;
     1550    border-bottom: 1px solid #ddd;
    14541551    border-left: 4px solid #fff;
    14551552    cursor: pointer;
     
    16291726        position: relative;
    16301727        width: 100%;
    1631         background: #fff;
    16321728        height: auto;
    1633         padding: 10px 15px;
    16341729    }
    16351730
    16361731    #available-widgets-list {
    1637         top: 140px;
    1638     }
    1639 }
     1732        top: 130px;
     1733    }
     1734
     1735    #available-menu-items-search .clear-results,
     1736    #available-menu-items-search .search-icon {
     1737        top: 85px; /* 70 section title height + 13 container padding +1 input margin +1 input border */
     1738    }
     1739}
  • trunk/src/wp-admin/css/customize-nav-menus.css

    r38688 r38709  
    689689}
    690690
    691 #available-menu-items-search .clear-results {
    692     position: absolute;
    693     top: 18px; /* 12 container padding +1 input margin +1 input border +4 ( 4 is ( 28 input height - 20 button height ) / 2 ) */
    694     right: 20px;
    695     width: 20px;
    696     height: 20px;
    697     padding: 0;
    698     border: 0;
    699     cursor: pointer;
    700     background: none;
    701     color: #a00;
    702     text-decoration: none;
    703     outline: 0;
    704 }
    705 
    706 #available-menu-items-search .clear-results,
    707 #available-menu-items-search.loading .clear-results.is-visible {
    708     display: none;
    709 }
    710 
    711 #available-menu-items-search .clear-results.is-visible {
    712     display: block;
    713 }
    714 
    715 .ie8 #available-menu-items-search.loading .clear-results:before {
    716     content: ""; /* help IE8 redraw the pseudo element */
    717 }
    718 
    719 #available-menu-items-search .clear-results:before {
    720     content: "\f335";
    721     font: normal 20px/1 dashicons;
    722     vertical-align: middle;
    723     -webkit-font-smoothing: antialiased;
    724     -moz-osx-font-smoothing: grayscale;
    725 }
    726 
    727 #available-menu-items-search .clear-results:hover,
    728 #available-menu-items-search .clear-results:focus {
    729     color: #f00;
    730 }
    731 
    732691#available-menu-items-search .spinner {
    733692    position: absolute;
    734     top: 18px; /* 12 container padding +1 input margin +1 input border +4 ( ( 28 input height - 20 button height ) / 2 ) */
    735     right: 20px;
     693    top: 20px; /* 13 container padding +1 input margin +6 ( ( 32 input height - 20 spinner height ) / 2 ) */
     694    right: 21px;
    736695    margin: 0 !important;
    737696}
     
    740699#available-menu-items #available-menu-items-search .accordion-section-content {
    741700    position: absolute;
    742     left: 1px;
     701    left: 0;
    743702    top: 60px; /* below title div / search input */
    744703    bottom: 0px; /* 100% height that still triggers lazy load */
     
    751710}
    752711
     712#available-menu-items-search .nothing-found {
     713    /* Compensate the 1px top padding of the container. */
     714    margin-top: -1px;
     715}
     716
    753717#available-menu-items-search .accordion-section-title:after {
    754718    display: none;
     
    921885#customize-controls .customize-info .customize-help-toggle:focus:before,
    922886.wp-customizer button:focus .toggle-indicator:after,
    923 #available-menu-items-search .clear-results:focus,
    924887.menu-delete:focus,
    925888.menu-item-bar .item-delete:focus:before,
     
    938901        top: 63px;
    939902    }
    940 
    941     #available-menu-items-search .spinner,
    942     #available-menu-items-search .clear-results {
    943         top: 20px; /* 12 container padding +1 input margin +1 input border +5.5 ( 5.5 rounded to 6 is ( 31 input height - 20 button height ) / 2 ) */
    944     }
    945903}
    946904
    947905@media screen and ( max-width: 640px ) {
    948906    #available-menu-items #available-menu-items-search .accordion-section-content {
    949         top: 133px;
     907        top: 130px;
    950908    }
    951 
    952     #available-menu-items-search .clear-results {
    953         top: 90px; /* 70 section title height + 12 container padding +1 input margin +1 input border +5.5 ( 5.5 rounded to 6 is ( 31 input height - 20 button height ) / 2 ) */
    954     }
    955 }
     909}
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r38668 r38709  
    171171        debounceSearch: null,
    172172        $search: null,
     173        $clearResults: null,
    173174        searchTerm: '',
    174175        rendered: false,
     
    186187
    187188            this.$search = $( '#menu-items-search' );
     189            this.$clearResults = this.$el.find( '.clear-results' );
    188190            this.sectionContent = this.$el.find( '.available-menu-items-list' );
    189191
     
    203205            } );
    204206
    205             // Clear the search results.
    206             $( '.clear-results' ).on( 'click', function() {
     207            // Clear the search results and trigger a `keyup` event to fire a new search.
     208            this.$clearResults.on( 'click', function() {
    207209                self.$search.val( '' ).focus().trigger( 'keyup' );
    208210            } );
     
    262264                $searchSection.find( '.accordion-section-content' ).slideDown( 'fast' );
    263265                $searchSection.addClass( 'open' );
    264                 $searchSection.find( '.clear-results' ).addClass( 'is-visible' );
     266                this.$clearResults.addClass( 'is-visible' );
    265267            } else if ( '' === event.target.value ) {
    266268                $searchSection.removeClass( 'open' );
    267269                $otherSections.show();
    268                 $searchSection.find( '.clear-results' ).removeClass( 'is-visible' );
     270                this.$clearResults.removeClass( 'is-visible' );
    269271            }
    270272
     
    338340                // data.message may be undefined, for example when typing slow and the request is aborted.
    339341                if ( data.message ) {
    340                     $content.empty().append( $( '<p class="nothing-found"></p>' ).text( data.message ) );
     342                    $content.empty().append( $( '<li class="nothing-found"></li>' ).text( data.message ) );
    341343                    wp.a11y.speak( data.message );
    342344                }
  • trunk/src/wp-admin/js/customize-widgets.js

    r38672 r38709  
    7171            }
    7272
    73             // If search is blank, show all themes
    74             // Useful for resetting the views when you clean the input
     73            // If search is blank, set all the widgets as they matched the search to reset the views.
    7574            if ( this.terms === '' ) {
    7675                this.each( function ( widget ) {
     
    150149            'input #widgets-search': 'search',
    151150            'keyup #widgets-search': 'search',
    152             'change #widgets-search': 'search',
    153             'search #widgets-search': 'search',
    154151            'focus .widget-tpl' : 'focus',
    155152            'click .widget-tpl' : '_submit',
     
    164161        currentSidebarControl: null,
    165162        $search: null,
     163        $clearResults: null,
     164        searchMatchesCount: null,
    166165
    167166        initialize: function() {
     
    170169            this.$search = $( '#widgets-search' );
    171170
     171            this.$clearResults = this.$el.find( '.clear-results' );
     172
    172173            _.bindAll( this, 'close' );
    173174
     
    175176
    176177            this.updateList();
     178
     179            // Set the initial search count to the number of available widgets.
     180            this.searchMatchesCount = this.collection.length;
    177181
    178182            // If the available widgets panel is open and the customize controls are
     
    186190            } );
    187191
     192            // Clear the search results and trigger a `keyup` event to fire a new search.
     193            this.$clearResults.on( 'click', function() {
     194                self.$search.val( '' ).focus().trigger( 'keyup' );
     195            } );
     196
    188197            // Close the panel if the URL in the preview changes
    189198            api.previewer.bind( 'url', this.close );
     
    195204
    196205            this.collection.doSearch( event.target.value );
     206            // Update the search matches count.
     207            this.updateSearchMatchesCount();
     208            // Announce how many search results.
     209            this.announceSearchMatches();
    197210
    198211            // Remove a widget from being selected if it is no longer visible
     
    215228                }
    216229            }
    217         },
     230
     231            // Toggle the clear search results button.
     232            if ( '' !== event.target.value ) {
     233                this.$clearResults.addClass( 'is-visible' );
     234            } else if ( '' === event.target.value ) {
     235                this.$clearResults.removeClass( 'is-visible' );
     236            }
     237
     238            // Set a CSS class on the search container when there are no search results.
     239            if ( ! this.searchMatchesCount ) {
     240                this.$el.addClass( 'no-widgets-found' );
     241            } else {
     242                this.$el.removeClass( 'no-widgets-found' );
     243            }
     244        },
     245
     246        // Update the count of the available widgets that have the `search_matched` attribute.
     247        updateSearchMatchesCount: function() {
     248            this.searchMatchesCount = this.collection.where({ search_matched: true }).length;
     249        },
     250
     251        // Send a message to the aria-live region to announce how many search results.
     252        announceSearchMatches: _.debounce( function() {
     253            var message = l10n.widgetsFound.replace( '%d', this.searchMatchesCount ) ;
     254
     255            if ( ! this.searchMatchesCount ) {
     256                message = l10n.noWidgetsFound;
     257            }
     258
     259            wp.a11y.speak( message );
     260        }, 500 ),
    218261
    219262        // Changes visibility of available widgets
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r38672 r38709  
    892892                    <span class="spinner"></span>
    893893                </div>
     894                <div class="search-icon" aria-hidden="true"></div>
    894895                <button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button>
    895896                <ul class="accordion-section-content available-menu-items-list" data-type="search"></ul>
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r38672 r38709  
    734734                'reorderModeOff'   => __( 'Reorder mode closed' ),
    735735                'reorderLabelOn'   => esc_attr__( 'Reorder widgets' ),
    736                 'reorderLabelOff'  => esc_attr__( 'Close reorder mode' ),
     736                'widgetsFound'     => __( 'Number of widgets found: %d' ),
     737                'noWidgetsFound'   => __( 'No widgets found.' ),
    737738            ),
    738739            'tpl' => array(
     
    778779            <div id="available-widgets-filter">
    779780                <label class="screen-reader-text" for="widgets-search"><?php _e( 'Search Widgets' ); ?></label>
    780                 <input type="search" id="widgets-search" placeholder="<?php esc_attr_e( 'Search widgets&hellip;' ) ?>" />
     781                <input type="text" id="widgets-search" placeholder="<?php esc_attr_e( 'Search widgets&hellip;' ) ?>" aria-describedby="widgets-search-desc" />
     782                <div class="search-icon" aria-hidden="true"></div>
     783                <button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button>
     784                <p class="screen-reader-text" id="widgets-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p>
    781785            </div>
    782786            <div id="available-widgets-list">
     
    786790                </div>
    787791            <?php endforeach; ?>
     792            <p class="no-widgets-found-message"><?php _e( 'No widgets found.' ); ?></p>
    788793            </div><!-- #available-widgets-list -->
    789794        </div><!-- #available-widgets -->
Note: See TracChangeset for help on using the changeset viewer.