Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-library/src/search/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"editorStyle": "wp-block-search-editor",
"style": "wp-block-search",
"selectors": {
"color": ".wp-block-search .wp-block-search__button",
"color": ".wp-block-search .wp-block-search__button, .wp-block-search.wp-block-search__no-button .wp-block-search__input",
"border": ".wp-block-search.wp-block-search__button-outside .wp-block-search__input, .wp-block-search.wp-block-search__button-outside .wp-block-search__button, .wp-block-search.wp-block-search__no-button .wp-block-search__input, .wp-block-search.wp-block-search__button-only .wp-block-search__input, .wp-block-search.wp-block-search__button-only .wp-block-search__button, .wp-block-search.wp-block-search__button-inside .wp-block-search__inside-wrapper"
}
}
2 changes: 2 additions & 0 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ export default function SearchEdit( {
// If the input is inside the wrapper, the wrapper gets the border color styles/classes, not the input control.
const textFieldClasses = clsx(
'wp-block-search__input',
hasNoButton ? colorProps.className : undefined,
isButtonPositionInside ? undefined : borderProps.className,
typographyProps.className
);
const textFieldStyles = {
...( hasNoButton ? colorProps.style : {} ),
...( isButtonPositionInside
? {
borderRadius: borderProps.style?.borderRadius,
Expand Down
26 changes: 23 additions & 3 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ function render_block_core_search( $attributes ) {
if ( ! empty( $typography_classes ) ) {
$input_classes[] = $typography_classes;
}
if ( ! $show_button && ! empty( $color_classes ) ) {
$input_classes[] = $color_classes;
}
if ( $input->next_tag() ) {
$input->add_class( implode( ' ', $input_classes ) );
$input->set_attribute( 'id', $input_id );
Expand Down Expand Up @@ -430,20 +433,37 @@ function styles_for_block_core_search( $attributes ) {
}
}

$use_input_for_colors = ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'];

// Add color styles.
$has_text_color = ! empty( $attributes['style']['color']['text'] );
if ( $has_text_color ) {
$button_styles[] = sprintf( 'color: %s;', $attributes['style']['color']['text'] );
$text_color_style = sprintf( 'color: %s;', $attributes['style']['color']['text'] );
if ( $use_input_for_colors ) {
$input_styles[] = $text_color_style;
} else {
$button_styles[] = $text_color_style;
}
}

$has_background_color = ! empty( $attributes['style']['color']['background'] );
if ( $has_background_color ) {
$button_styles[] = sprintf( 'background-color: %s;', $attributes['style']['color']['background'] );
$background_color_style = sprintf( 'background-color: %s;', $attributes['style']['color']['background'] );
if ( $use_input_for_colors ) {
$input_styles[] = $background_color_style;
} else {
$button_styles[] = $background_color_style;
}
}

$has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] );
if ( $has_custom_gradient ) {
$button_styles[] = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] );
$custom_gradient_style = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] );
if ( $use_input_for_colors ) {
$input_styles[] = $custom_gradient_style;
} else {
$button_styles[] = $custom_gradient_style;
}
}

// Get typography styles to be shared across inner elements.
Expand Down
Loading