Skip to content

Commit

Permalink
Get frontend js correctly working withb the show and hide of the text…
Browse files Browse the repository at this point in the history
… field.
  • Loading branch information
apeatling committed May 27, 2021
1 parent 8ad0a24 commit d544e4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
17 changes: 11 additions & 6 deletions packages/block-library/src/search/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const wpBlockSearch = ( block ) => {

if (
block.classList.contains(
'wp-search-block__searchfield-hidden'
'wp-block-search__searchfield-hidden'
)
) {
showSearchField(
Expand All @@ -44,16 +44,21 @@ const wpBlockSearch = ( block ) => {
attributes.width,
attributes.widthUnit
);
block.classList.remove( 'wp-block-search__searchfield-hidden' );
} else {
hideSearchField( wrapper, searchField, button );
block.classList.add( 'wp-block-search__searchfield-hidden' );
}
} );
};

// eslint-disable-next-line @wordpress/no-global-event-listener
document.addEventListener( 'DOMContentLoaded', () => {
Array.from( document.getElementsByClassName( 'wp-block-search__button-behavior-expand' ) ).forEach(
( block ) => {
wpBlockSearch( block );
}
);
Array.from(
document.getElementsByClassName(
'wp-block-search__button-behavior-expand'
)
).forEach( ( block ) => {
wpBlockSearch( block );
} );
} );
21 changes: 8 additions & 13 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ function render_block_core_search( $attributes ) {
}
}

if ( $show_input ) {
$input_markup = sprintf(
'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" %s required />',
$input_id,
esc_attr( get_search_query() ),
esc_attr( $attributes['placeholder'] ),
$inline_styles['shared']
);
}
$input_markup = sprintf(
'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" %s required />',
$input_id,
esc_attr( get_search_query() ),
esc_attr( $attributes['placeholder'] ),
$inline_styles['shared']
);

if ( $show_button ) {
$button_internal_markup = '';
Expand Down Expand Up @@ -152,6 +150,7 @@ function classnames_for_block_core_search( $attributes ) {

if ( 'button-only' === $attributes['buttonPosition'] ) {
$classnames[] = 'wp-block-search__button-only';
$classnames[] = 'wp-block-search__searchfield-hidden';

if ( ! empty( $attributes['buttonBehavior'] ) ) {
if ( 'expand-searchfield' === $attributes['buttonBehavior'] ) {
Expand All @@ -162,10 +161,6 @@ function classnames_for_block_core_search( $attributes ) {
$classnames[] = 'wp-block-search__button-behavior-link';
}
}

if ( ! empty( $attributes['isSearchFieldHidden'] ) ) {
$classnames[] = 'wp-block-search__searchfield-hidden';
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/search/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
min-width: 0 !important;
padding: 0 !important;
border-left-width: 0 !important;
flex-grow: 0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/search/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const PC_WIDTH_DEFAULT = 50;
export const PX_WIDTH_DEFAULT = 350;
export const MIN_WIDTH = 220;
export const MIN_WIDTH_UNIT = 'px';
const SEARCHFIELD_ANIMATION_DURATION = 300;
export const SEARCHFIELD_ANIMATION_DURATION = 300;

/**
* Returns a boolean whether passed unit is percentage
Expand Down

0 comments on commit d544e4b

Please sign in to comment.