Skip to content

Commit

Permalink
Menu customizer: More clearly separate search results from available …
Browse files Browse the repository at this point in the history
…items.

Available items now fade from view while you're searching, and there is an explicit way to clear search results. No results gives a better message, though still brief this time around.

props valendesigns, designsimply, DH-Shredder, helen.
fixes #32710.

Built from https://develop.svn.wordpress.org/trunk@33511


git-svn-id: http://core.svn.wordpress.org/trunk@33478 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
helen committed Jul 29, 2015
1 parent 3dfce31 commit ea8f8ac
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 30 deletions.
61 changes: 57 additions & 4 deletions wp-admin/css/customize-nav-menus-rtl.css
Expand Up @@ -590,7 +590,8 @@
bottom: 0;
right: -301px;
visibility: hidden;
overflow: hidden;
overflow-x: hidden;
overflow-y: auto;
width: 300px;
margin: 0;
z-index: 4;
Expand All @@ -600,8 +601,13 @@
border-left: 1px solid #ddd;
}

#available-menu-items.allow-scroll {
overflow-y: auto;
#available-menu-items.opening {
overflow-y: hidden; /* avoid scrollbar jitter with animating heights */
}

#available-menu-items #available-menu-items-search.open {
height: 100%;
border-bottom: none;
}

#available-menu-items .accordion-section-title {
Expand All @@ -610,7 +616,8 @@
background: #fff;
}

#available-menu-items .open .accordion-section-title {
#available-menu-items .open .accordion-section-title,
#available-menu-items #available-menu-items-search .accordion-section-title {
background: #eee;
}

Expand Down Expand Up @@ -702,6 +709,15 @@ button.not-a-button {
max-height: 290px;
}

#available-menu-items #available-menu-items-search .accordion-section-content {
position: absolute;
right: 1px;
top: 60px; /* below title div / search input */
bottom: 0px; /* 100% height that still triggers lazy load */
max-height: none;
width: 270px;
}

#available-menu-items .menu-item-tpl {
margin: 0;
}
Expand Down Expand Up @@ -802,6 +818,43 @@ button.not-a-button {
margin: 0 20px;
}

#available-menu-items-search .clear-results {
position: absolute;
top: 20px;
left: 20px;
width: 20px;
height: 20px;
cursor: pointer;
color: #a00;
text-decoration: none;
}

#available-menu-items-search .clear-results,
#available-menu-items-search.loading .clear-results.is-visible {
display: none;
}

#available-menu-items-search .clear-results.is-visible {
display: block;
}

#available-menu-items-search .clear-results:before {
content: "\f335";
font: normal 20px/1 dashicons;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

#available-menu-items-search .clear-results:hover,
#available-menu-items-search .clear-results:focus {
color: #f00;
}

#available-menu-items-search .clear-results:focus {
-webkit-box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
}

#available-menu-items-search .spinner {
position: absolute;
top: 20px;
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/css/customize-nav-menus-rtl.min.css

Large diffs are not rendered by default.

61 changes: 57 additions & 4 deletions wp-admin/css/customize-nav-menus.css
Expand Up @@ -590,7 +590,8 @@
bottom: 0;
left: -301px;
visibility: hidden;
overflow: hidden;
overflow-x: hidden;
overflow-y: auto;
width: 300px;
margin: 0;
z-index: 4;
Expand All @@ -600,8 +601,13 @@
border-right: 1px solid #ddd;
}

#available-menu-items.allow-scroll {
overflow-y: auto;
#available-menu-items.opening {
overflow-y: hidden; /* avoid scrollbar jitter with animating heights */
}

#available-menu-items #available-menu-items-search.open {
height: 100%;
border-bottom: none;
}

#available-menu-items .accordion-section-title {
Expand All @@ -610,7 +616,8 @@
background: #fff;
}

#available-menu-items .open .accordion-section-title {
#available-menu-items .open .accordion-section-title,
#available-menu-items #available-menu-items-search .accordion-section-title {
background: #eee;
}

Expand Down Expand Up @@ -702,6 +709,15 @@ button.not-a-button {
max-height: 290px;
}

#available-menu-items #available-menu-items-search .accordion-section-content {
position: absolute;
left: 1px;
top: 60px; /* below title div / search input */
bottom: 0px; /* 100% height that still triggers lazy load */
max-height: none;
width: 270px;
}

#available-menu-items .menu-item-tpl {
margin: 0;
}
Expand Down Expand Up @@ -802,6 +818,43 @@ button.not-a-button {
margin: 0 20px;
}

#available-menu-items-search .clear-results {
position: absolute;
top: 20px;
right: 20px;
width: 20px;
height: 20px;
cursor: pointer;
color: #a00;
text-decoration: none;
}

#available-menu-items-search .clear-results,
#available-menu-items-search.loading .clear-results.is-visible {
display: none;
}

#available-menu-items-search .clear-results.is-visible {
display: block;
}

#available-menu-items-search .clear-results:before {
content: "\f335";
font: normal 20px/1 dashicons;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

#available-menu-items-search .clear-results:hover,
#available-menu-items-search .clear-results:focus {
color: #f00;
}

#available-menu-items-search .clear-results:focus {
-webkit-box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
}

#available-menu-items-search .spinner {
position: absolute;
top: 20px;
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/css/customize-nav-menus.min.css

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion wp-admin/js/accordion.js
Expand Up @@ -54,7 +54,8 @@
function accordionSwitch ( el ) {
var section = el.closest( '.accordion-section' ),
sectionToggleControl = section.find( '[aria-expanded]' ).first(),
siblings = section.closest( '.accordion-container' ).find( '.open' ),
container = section.closest( '.accordion-container' ),
siblings = container.find( '.open' ),
siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(),
content = section.find( '.accordion-section-content' );

Expand All @@ -63,6 +64,10 @@
return;
}

// Add a class to the container to let us know something is happening inside.
// This helps in cases such as hiding a scrollbar while animations are executing.
container.addClass( 'opening' );

if ( section.hasClass( 'open' ) ) {
section.toggleClass( 'open' );
content.toggle( true ).slideToggle( 150 );
Expand All @@ -74,6 +79,11 @@
section.toggleClass( 'open' );
}

// We have to wait for the animations to finish
setTimeout(function(){
container.removeClass( 'opening' );
}, 150);

// If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value.
if ( sectionToggleControl ) {
sectionToggleControl.attr( 'aria-expanded', String( sectionToggleControl.attr( 'aria-expanded' ) === 'false' ) );
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/js/accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 31 additions & 14 deletions wp-admin/js/customize-nav-menus.js
Expand Up @@ -96,7 +96,6 @@
events: {
'input #menu-items-search': 'debounceSearch',
'keyup #menu-items-search': 'debounceSearch',
'click #menu-items-search': 'debounceSearch',
'focus .menu-item-tpl': 'focus',
'click .menu-item-tpl': '_submit',
'click #custom-menu-item-submit': '_submitLink',
Expand Down Expand Up @@ -138,6 +137,20 @@
}
} );

// Clear the search results.
$( '.clear-results' ).on( 'click keydown', function( event ) {
console.log(event);
if ( event.type === 'keydown' && ( 13 !== event.which && 32 !== event.which ) ) { // "return" or "space" keys only
return;
}

event.preventDefault();

$( '#menu-items-search' ).val( '' ).focus();
event.target.value = '';
self.search( event );
} );

this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() {
$( this ).removeClass( 'invalid' );
});
Expand Down Expand Up @@ -176,25 +189,31 @@
// Search input change handler.
search: function( event ) {
var $searchSection = $( '#available-menu-items-search' ),
$openSections = $( '#available-menu-items .accordion-section.open' );
$otherSections = $( '#available-menu-items .accordion-section' ).not( $searchSection );

if ( ! event ) {
return;
}
// Manual accordion-opening behavior.
if ( this.searchTerm && ! $searchSection.hasClass( 'open' ) ) {
$openSections.find( '.accordion-section-content' ).slideUp( 'fast' );

if ( this.searchTerm === event.target.value ) {
return;
}

if ( '' !== event.target.value && ! $searchSection.hasClass( 'open' ) ) {
$otherSections.fadeOut( 100 );
$searchSection.find( '.accordion-section-content' ).slideDown( 'fast' );
$openSections.find( '[aria-expanded]' ).first().attr( 'aria-expanded', 'false' );
$openSections.removeClass( 'open' );
$searchSection.addClass( 'open' );
}
if ( '' === event.target.value ) {
$searchSection.find( '.clear-results' )
.prop( 'tabIndex', 0 )
.addClass( 'is-visible' );
} else if ( '' === event.target.value ) {
$searchSection.removeClass( 'open' );
$otherSections.show();
$searchSection.find( '.clear-results' )
.prop( 'tabIndex', -1 )
.removeClass( 'is-visible' );
}
if ( this.searchTerm === event.target.value ) {
return;
}

this.searchTerm = event.target.value;
this.pages.search = 1;
this.doSearch( 1 );
Expand Down Expand Up @@ -351,8 +370,6 @@
diff = totalHeight - accordionHeight;
if ( 120 < diff && 290 > diff ) {
sections.css( 'max-height', diff );
} else if ( 120 >= diff ) {
this.$el.addClass( 'allow-scroll' );
}
},

Expand Down
4 changes: 2 additions & 2 deletions wp-admin/js/customize-nav-menus.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion wp-includes/class-wp-customize-nav-menus.php
Expand Up @@ -217,7 +217,7 @@ public function ajax_search_available_items() {
$items = $this->search_available_items_query( array( 'pagenum' => $p, 's' => $s ) );

if ( empty( $items ) ) {
wp_send_json_error( array( 'message' => __( 'No menu items found.' ) ) );
wp_send_json_error( array( 'message' => __( 'No results found.' ) ) );
} else {
wp_send_json_success( array( 'items' => $items ) );
}
Expand Down Expand Up @@ -718,6 +718,7 @@ public function available_items_template() {
<input type="text" id="menu-items-search" placeholder="<?php esc_attr_e( 'Search menu items&hellip;' ) ?>" aria-describedby="menu-items-search-desc" />
<p class="screen-reader-text" id="menu-items-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p>
<span class="spinner"></span>
<span class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></span>
</div>
<ul class="accordion-section-content" data-type="search"></ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-beta4-33510';
$wp_version = '4.3-beta4-33511';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit ea8f8ac

Please sign in to comment.