Skip to content

Commit

Permalink
Fix label clicking behavior, remove unneeded event listeners.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed May 25, 2023
1 parent c3b84f5 commit 7665720
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/block-library/src/search/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ window.addEventListener( 'DOMContentLoaded', () => {
).forEach( ( block ) => {
const searchField = block.querySelector( '.wp-block-search__input' );
const searchButton = block.querySelector( '.wp-block-search__button' );
const activeElement = block.ownerDocument.activeElement;

const searchLabel = block.querySelector( '.wp-block-search__label' );
const ariaLabel = searchButton.getAttribute( 'aria-label' );
const id = searchField.getAttribute( 'id' );

Expand All @@ -33,11 +32,7 @@ window.addEventListener( 'DOMContentLoaded', () => {
};

const hideSearchField = ( e ) => {
if (
! e.target.closest( '.wp-block-search__inside-wrapper' ) &&
activeElement !== searchButton &&
activeElement !== searchField
) {
if ( ! e.target.closest( '.wp-block-search' ) ) {
return toggleSearchField( false );
}

Expand All @@ -55,11 +50,11 @@ window.addEventListener( 'DOMContentLoaded', () => {
}
};

searchField.addEventListener( 'blur', hideSearchField );
searchField.addEventListener( 'keydown', ( e ) => {
hideSearchField( e );
} );
searchButton.addEventListener( 'click', handleButtonClick );
searchLabel.addEventListener( 'click', handleButtonClick );
document.body.addEventListener( 'click', hideSearchField );
} );
} );

0 comments on commit 7665720

Please sign in to comment.