From 5f8b9df35c1a5a18c9f6d028de2b06d21521068a Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Wed, 30 Jan 2019 12:34:57 +1100 Subject: [PATCH 01/15] Adding search widget block Co-authored-by: Rachel Cherry --- lib/load.php | 3 + packages/block-library/src/index.js | 2 + packages/block-library/src/search/edit.js | 86 +++++++++++++++++++ packages/block-library/src/search/editor.scss | 28 ++++++ packages/block-library/src/search/index.js | 29 +++++++ packages/block-library/src/search/index.php | 83 ++++++++++++++++++ packages/block-library/src/search/style.scss | 0 7 files changed, 231 insertions(+) create mode 100644 packages/block-library/src/search/edit.js create mode 100644 packages/block-library/src/search/editor.scss create mode 100644 packages/block-library/src/search/index.js create mode 100644 packages/block-library/src/search/index.php create mode 100644 packages/block-library/src/search/style.scss diff --git a/lib/load.php b/lib/load.php index 2f8644ccf4636..b3c81971a353f 100644 --- a/lib/load.php +++ b/lib/load.php @@ -49,3 +49,6 @@ if ( ! function_exists( 'render_block_core_shortcode' ) ) { require dirname( __FILE__ ) . '/../packages/block-library/src/shortcode/index.php'; } +if ( ! function_exists( 'render_block_core_search' ) ) { + require dirname( __FILE__ ) . '/../packages/block-library/src/search/index.php'; +} diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 5dd3fee7b2a29..aac4e56fc7a8b 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -39,6 +39,7 @@ import * as preformatted from './preformatted'; import * as pullquote from './pullquote'; import * as reusableBlock from './block'; import * as rss from './rss'; +import * as search from './search'; import * as separator from './separator'; import * as shortcode from './shortcode'; import * as spacer from './spacer'; @@ -87,6 +88,7 @@ export const registerCoreBlocks = () => { preformatted, pullquote, rss, + search, separator, reusableBlock, spacer, diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js new file mode 100644 index 0000000000000..98cc730255bb5 --- /dev/null +++ b/packages/block-library/src/search/edit.js @@ -0,0 +1,86 @@ +/** + * WordPress dependencies + */ +import { Component, Fragment } from '@wordpress/element'; +import { InspectorControls } from '@wordpress/editor'; +import { TextControl } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; + +export default class SearchEdit extends Component { + constructor() { + super( ...arguments ); + + this.updateLabel = this.updateLabel.bind( this ); + this.updatePlaceholder = this.updatePlaceholder.bind( this ); + this.updateSubmitValue = this.updateSubmitValue.bind( this ); + this.handleFormSubmit = this.handleFormSubmit.bind( this ); + } + + updateLabel( newLabel ) { + this.props.setAttributes( { label: newLabel } ); + } + + updatePlaceholder( newPlaceholder ) { + this.props.setAttributes( { placeholder: newPlaceholder } ); + } + + updateSubmitValue( newValue ) { + this.props.setAttributes( { submitValue: newValue } ); + } + + handleFormSubmit( event ) { + event.preventDefault(); + return false; + } + + render() { + const { attributes, focus } = this.props; + + const { label, placeholder, submitValue } = attributes; + + return ( + +
+ + +
+ { focus && ( + + + + + + ) } +
+ ); + } +} diff --git a/packages/block-library/src/search/editor.scss b/packages/block-library/src/search/editor.scss new file mode 100644 index 0000000000000..413f391576c68 --- /dev/null +++ b/packages/block-library/src/search/editor.scss @@ -0,0 +1,28 @@ +.editor-block-list__block[data-type="core/search"] { + + .search-form { + + .search-label { + display: block; + margin: 0 0 0.3em; + } + + .search-field { + display: block; + width: 100%; + background: #fff; + border: 1px solid #bbb; + border-radius: 3px; + padding: 0.7em; + margin: 0; + } + + .search-submit { + display: inline-block; + width: auto; + text-align: center; + padding: 0.5em 0.8em; + margin: 0.7em 0 0; + } + } +} diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js new file mode 100644 index 0000000000000..d958fd0990ea8 --- /dev/null +++ b/packages/block-library/src/search/index.js @@ -0,0 +1,29 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import edit from './edit'; + +export const name = 'core/search'; + +export const settings = { + title: __( 'Search' ), + + description: __( 'A search form for your site.' ), + + icon: 'search', + + category: 'widgets', + + keywords: [ __( 'find' ) ], + + edit, + + save() { + return null; + }, +}; diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php new file mode 100644 index 0000000000000..29679ed6ab209 --- /dev/null +++ b/packages/block-library/src/search/index.php @@ -0,0 +1,83 @@ + _x( 'Search for:', 'label', 'gutenberg' ), + 'placeholder' => esc_attr_x( 'Search …', 'placeholder', 'gutenberg' ), + 'submitValue' => esc_attr_x( 'Search', 'submit button', 'gutenberg' ), + ); + + $args = wp_parse_args( $attributes, $defaults ); + + /** + * Filters the arguments used for the search form. + * + * @since x.x.x + * + * @param array $args The search form markup arguments. + */ + $args = apply_filters( 'get_search_form_args', $args ); + + $form = ''; + } + + /** This filter is documented in wp-includes/general-template.php */ + $result = apply_filters( 'get_search_form', $form ); + + if ( null === $result ) { + $result = $form; + } + + return $form; +} + +register_block_type( + 'core/search', + array( + 'attributes' => array( + 'label' => array( + 'type' => 'string', + 'default' => _x( 'Search for:', 'label', 'gutenberg' ), + ), + 'placeholder' => array( + 'type' => 'string', + 'default' => esc_attr_x( 'Search …', 'placeholder', 'gutenberg' ), + ), + 'submitValue' => array( + 'type' => 'string', + 'default' => esc_attr_x( 'Search', 'submit button', 'gutenberg' ), + ), + ), + + 'render_callback' => 'render_block_core_search', + ) +); diff --git a/packages/block-library/src/search/style.scss b/packages/block-library/src/search/style.scss new file mode 100644 index 0000000000000..e69de29bb2d1d From 5a9fcece24c31a7449ca5ca55969d2441c59796f Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Wed, 30 Jan 2019 16:32:13 +1100 Subject: [PATCH 02/15] Search block: Move away from legacy get_search_form() markup Changes the Search block to render its own search form markup, instead of the same markup that get_search_form() renders. This lets us fully match the design spec. --- packages/block-library/src/search/edit.js | 116 ++++++------------ packages/block-library/src/search/editor.scss | 28 ----- packages/block-library/src/search/index.js | 2 +- packages/block-library/src/search/index.php | 107 +++++++--------- packages/block-library/src/search/style.scss | 10 ++ packages/block-library/src/style.scss | 1 + .../full-content/fixtures/core__search.html | 1 + .../full-content/fixtures/core__search.json | 10 ++ .../fixtures/core__search.parsed.json | 18 +++ .../fixtures/core__search.serialized.html | 1 + .../fixtures/core__search__custom-text.html | 1 + .../fixtures/core__search__custom-text.json | 10 ++ .../core__search__custom-text.parsed.json | 21 ++++ .../core__search__custom-text.serialized.html | 1 + 14 files changed, 151 insertions(+), 176 deletions(-) delete mode 100644 packages/block-library/src/search/editor.scss create mode 100644 test/integration/full-content/fixtures/core__search.html create mode 100644 test/integration/full-content/fixtures/core__search.json create mode 100644 test/integration/full-content/fixtures/core__search.parsed.json create mode 100644 test/integration/full-content/fixtures/core__search.serialized.html create mode 100644 test/integration/full-content/fixtures/core__search__custom-text.html create mode 100644 test/integration/full-content/fixtures/core__search__custom-text.json create mode 100644 test/integration/full-content/fixtures/core__search__custom-text.parsed.json create mode 100644 test/integration/full-content/fixtures/core__search__custom-text.serialized.html diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 98cc730255bb5..e3dd302ce528e 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -1,86 +1,40 @@ /** * WordPress dependencies */ -import { Component, Fragment } from '@wordpress/element'; -import { InspectorControls } from '@wordpress/editor'; -import { TextControl } from '@wordpress/components'; +import { Fragment } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; - -export default class SearchEdit extends Component { - constructor() { - super( ...arguments ); - - this.updateLabel = this.updateLabel.bind( this ); - this.updatePlaceholder = this.updatePlaceholder.bind( this ); - this.updateSubmitValue = this.updateSubmitValue.bind( this ); - this.handleFormSubmit = this.handleFormSubmit.bind( this ); - } - - updateLabel( newLabel ) { - this.props.setAttributes( { label: newLabel } ); - } - - updatePlaceholder( newPlaceholder ) { - this.props.setAttributes( { placeholder: newPlaceholder } ); - } - - updateSubmitValue( newValue ) { - this.props.setAttributes( { submitValue: newValue } ); - } - - handleFormSubmit( event ) { - event.preventDefault(); - return false; - } - - render() { - const { attributes, focus } = this.props; - - const { label, placeholder, submitValue } = attributes; - - return ( - -
- - -
- { focus && ( - - - - - - ) } -
- ); - } +import { RichText, InspectorControls } from '@wordpress/editor'; +import { PanelBody, TextControl } from '@wordpress/components'; + +export default function SearchEdit( { attributes, setAttributes } ) { + const { label, placeholder } = attributes; + + return ( + +
+ setAttributes( { label: text } ) } + /> + +
+ + + setAttributes( { placeholder: text } ) } + /> + + +
+ ); } diff --git a/packages/block-library/src/search/editor.scss b/packages/block-library/src/search/editor.scss deleted file mode 100644 index 413f391576c68..0000000000000 --- a/packages/block-library/src/search/editor.scss +++ /dev/null @@ -1,28 +0,0 @@ -.editor-block-list__block[data-type="core/search"] { - - .search-form { - - .search-label { - display: block; - margin: 0 0 0.3em; - } - - .search-field { - display: block; - width: 100%; - background: #fff; - border: 1px solid #bbb; - border-radius: 3px; - padding: 0.7em; - margin: 0; - } - - .search-submit { - display: inline-block; - width: auto; - text-align: center; - padding: 0.5em 0.8em; - margin: 0.7em 0 0; - } - } -} diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js index d958fd0990ea8..28efbb5f5128b 100644 --- a/packages/block-library/src/search/index.js +++ b/packages/block-library/src/search/index.js @@ -13,7 +13,7 @@ export const name = 'core/search'; export const settings = { title: __( 'Search' ), - description: __( 'A search form for your site.' ), + description: __( 'Help your visitors find your content.' ), icon: 'search', diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 29679ed6ab209..a6db76642e511 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -6,78 +6,53 @@ */ /** - * Renders the `core/search` block on server. + * Dynamically renders the `core/search` block. * - * Copied from get_search_form() because the core - * search form function doesn't allow to change markup (yet). - * @param array $attributes The block attributes. * - * @return string Returns the search form markup. + * @return string The search block markup. */ function render_block_core_search( $attributes ) { - - $search_form_template = locate_template( 'searchform.php' ); - if ( '' != $search_form_template ) { - ob_start(); - require( $search_form_template ); - $form = ob_get_clean(); - } else { - - $defaults = array( - 'label' => _x( 'Search for:', 'label', 'gutenberg' ), - 'placeholder' => esc_attr_x( 'Search …', 'placeholder', 'gutenberg' ), - 'submitValue' => esc_attr_x( 'Search', 'submit button', 'gutenberg' ), - ); - - $args = wp_parse_args( $attributes, $defaults ); - - /** - * Filters the arguments used for the search form. - * - * @since x.x.x - * - * @param array $args The search form markup arguments. - */ - $args = apply_filters( 'get_search_form_args', $args ); - - $form = ''; - } - - /** This filter is documented in wp-includes/general-template.php */ - $result = apply_filters( 'get_search_form', $form ); - - if ( null === $result ) { - $result = $form; - } - - return $form; + static $instance_id = 0; + + $html = ' + + '; + + return sprintf( + $html, + esc_url( home_url( '/' ) ), + 'wp-block-search__input-' . ++$instance_id, + esc_html( $attributes['label'] ), + esc_attr( $attributes['placeholder'] ), + esc_attr( get_search_query() ) + ); } -register_block_type( - 'core/search', - array( - 'attributes' => array( - 'label' => array( - 'type' => 'string', - 'default' => _x( 'Search for:', 'label', 'gutenberg' ), - ), - 'placeholder' => array( - 'type' => 'string', - 'default' => esc_attr_x( 'Search …', 'placeholder', 'gutenberg' ), - ), - 'submitValue' => array( - 'type' => 'string', - 'default' => esc_attr_x( 'Search', 'submit button', 'gutenberg' ), +/** + * Registers the `core/search` block on the server. + */ +function register_block_core_search() { + register_block_type( + 'core/search', + array( + 'attributes' => array( + 'label' => array( + 'type' => 'string', + 'default' => __( 'Search' ), + ), + 'placeholder' => array( + 'type' => 'string', + 'default' => __( 'Enter a search keyword or phrase' ), + ), ), - ), - 'render_callback' => 'render_block_core_search', - ) -); + 'render_callback' => 'render_block_core_search', + ) + ); +} + +add_action( 'init', 'register_block_core_search' ); diff --git a/packages/block-library/src/search/style.scss b/packages/block-library/src/search/style.scss index e69de29bb2d1d..87b8db9ac1a3b 100644 --- a/packages/block-library/src/search/style.scss +++ b/packages/block-library/src/search/style.scss @@ -0,0 +1,10 @@ +.wp-block-search { + .wp-block-search__label { + display: block; + font-weight: bold; + } + + .wp-block-search__input { + width: 100%; + } +} diff --git a/packages/block-library/src/style.scss b/packages/block-library/src/style.scss index 09d3a2125e378..35168d85ab237 100644 --- a/packages/block-library/src/style.scss +++ b/packages/block-library/src/style.scss @@ -16,6 +16,7 @@ @import "./pullquote/style.scss"; @import "./quote/style.scss"; @import "./rss/style.scss"; +@import "./search/style.scss"; @import "./separator/style.scss"; @import "./subhead/style.scss"; @import "./table/style.scss"; diff --git a/test/integration/full-content/fixtures/core__search.html b/test/integration/full-content/fixtures/core__search.html new file mode 100644 index 0000000000000..f62e8a853c2ea --- /dev/null +++ b/test/integration/full-content/fixtures/core__search.html @@ -0,0 +1 @@ + diff --git a/test/integration/full-content/fixtures/core__search.json b/test/integration/full-content/fixtures/core__search.json new file mode 100644 index 0000000000000..e1397fdc9a37a --- /dev/null +++ b/test/integration/full-content/fixtures/core__search.json @@ -0,0 +1,10 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/search", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/test/integration/full-content/fixtures/core__search.parsed.json b/test/integration/full-content/fixtures/core__search.parsed.json new file mode 100644 index 0000000000000..0dfea6eb47b8f --- /dev/null +++ b/test/integration/full-content/fixtures/core__search.parsed.json @@ -0,0 +1,18 @@ +[ + { + "blockName": "core/search", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/test/integration/full-content/fixtures/core__search.serialized.html b/test/integration/full-content/fixtures/core__search.serialized.html new file mode 100644 index 0000000000000..f62e8a853c2ea --- /dev/null +++ b/test/integration/full-content/fixtures/core__search.serialized.html @@ -0,0 +1 @@ + diff --git a/test/integration/full-content/fixtures/core__search__custom-text.html b/test/integration/full-content/fixtures/core__search__custom-text.html new file mode 100644 index 0000000000000..e99a8009a342d --- /dev/null +++ b/test/integration/full-content/fixtures/core__search__custom-text.html @@ -0,0 +1 @@ + diff --git a/test/integration/full-content/fixtures/core__search__custom-text.json b/test/integration/full-content/fixtures/core__search__custom-text.json new file mode 100644 index 0000000000000..e1397fdc9a37a --- /dev/null +++ b/test/integration/full-content/fixtures/core__search__custom-text.json @@ -0,0 +1,10 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/search", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/test/integration/full-content/fixtures/core__search__custom-text.parsed.json b/test/integration/full-content/fixtures/core__search__custom-text.parsed.json new file mode 100644 index 0000000000000..3755dbc0b2962 --- /dev/null +++ b/test/integration/full-content/fixtures/core__search__custom-text.parsed.json @@ -0,0 +1,21 @@ +[ + { + "blockName": "core/search", + "attrs": { + "label": "Custom label", + "placeholder": "Custom placeholder" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/test/integration/full-content/fixtures/core__search__custom-text.serialized.html b/test/integration/full-content/fixtures/core__search__custom-text.serialized.html new file mode 100644 index 0000000000000..f62e8a853c2ea --- /dev/null +++ b/test/integration/full-content/fixtures/core__search__custom-text.serialized.html @@ -0,0 +1 @@ + From daae12450c6ceac19559a8a459bdf22c1e47f9d6 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 31 Jan 2019 12:18:49 +1100 Subject: [PATCH 03/15] s/Placeholder text/Placeholder Text/ Co-Authored-By: noisysocks --- packages/block-library/src/search/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index e3dd302ce528e..edb907c10c7f4 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -29,7 +29,7 @@ export default function SearchEdit( { attributes, setAttributes } ) { setAttributes( { placeholder: text } ) } /> From 871b31579eb65a9319e74b0425c496adf8b99c82 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 31 Jan 2019 12:19:13 +1100 Subject: [PATCH 04/15] Remove superfluous 'your' Co-Authored-By: noisysocks --- packages/block-library/src/search/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js index 28efbb5f5128b..0fcfa75722ff4 100644 --- a/packages/block-library/src/search/index.js +++ b/packages/block-library/src/search/index.js @@ -13,7 +13,7 @@ export const name = 'core/search'; export const settings = { title: __( 'Search' ), - description: __( 'Help your visitors find your content.' ), + description: __( 'Help visitors find your content.' ), icon: 'search', From 4f4da5e02a205ae858900741c051a8b7558ccf23 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 31 Jan 2019 15:45:12 +1100 Subject: [PATCH 05/15] Search: Add button and inline placeholder editing --- packages/block-library/src/editor.scss | 1 + packages/block-library/src/search/edit.js | 64 ++++++++++--------- packages/block-library/src/search/editor.scss | 26 ++++++++ packages/block-library/src/search/index.php | 42 ++++++++---- packages/block-library/src/search/style.scss | 11 +++- .../fixtures/core__search__custom-text.html | 2 +- .../core__search__custom-text.parsed.json | 1 + 7 files changed, 101 insertions(+), 46 deletions(-) create mode 100644 packages/block-library/src/search/editor.scss diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 9fb94f40bdef7..b5778d5b472ff 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -23,6 +23,7 @@ @import "./pullquote/editor.scss"; @import "./quote/editor.scss"; @import "./rss/editor.scss"; +@import "./search/editor.scss"; @import "./shortcode/editor.scss"; @import "./spacer/editor.scss"; @import "./subhead/editor.scss"; diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index edb907c10c7f4..31df5c162cdf4 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -1,40 +1,42 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ -import { Fragment } from '@wordpress/element'; +import { RichText } from '@wordpress/editor'; import { __ } from '@wordpress/i18n'; -import { RichText, InspectorControls } from '@wordpress/editor'; -import { PanelBody, TextControl } from '@wordpress/components'; -export default function SearchEdit( { attributes, setAttributes } ) { - const { label, placeholder } = attributes; +export default function SearchEdit( { className, attributes, setAttributes } ) { + const { label, placeholder, buttonText } = attributes; return ( - -
- setAttributes( { label: text } ) } - /> - -
- - - setAttributes( { placeholder: text } ) } - /> - - -
+
+ setAttributes( { label: html } ) } + /> + setAttributes( { placeholder: event.target.value } ) } + /> + setAttributes( { buttonText: html } ) } + /> +
); } diff --git a/packages/block-library/src/search/editor.scss b/packages/block-library/src/search/editor.scss new file mode 100644 index 0000000000000..cb5a489f180fb --- /dev/null +++ b/packages/block-library/src/search/editor.scss @@ -0,0 +1,26 @@ +.wp-block-search { + .wp-block-search__input { + border-radius: $radius-round-rectangle; + border: 1px solid $dark-gray-150; + color: $dark-opacity-300; + font-family: $default-font; + font-size: $default-font-size; + + &:focus { + outline: none; + } + } + + .wp-block-search__button { + background: #f7f7f7; + border-radius: $radius-round-rectangle; + border: 1px solid #ccc; + box-shadow: inset 0 -1px 0 #ccc; + font-family: $default-font; + font-size: $default-font-size; + + .wp-block-search__button-rich-text { + padding: 6px 10px; + } + } +} diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index a6db76642e511..0c98771e4f7d3 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -15,20 +15,34 @@ function render_block_core_search( $attributes ) { static $instance_id = 0; - $html = ' - - '; + $input_id = 'wp-block-search__input-' . ++$instance_id; + + if ( ! empty( $attributes['label'] ) ) { + $label_markup = sprintf( + '', + $input_id, + $attributes['label'] + ); + } + + $input_markup = sprintf( + '', + $input_id, + esc_attr( get_search_query() ), + esc_attr( $attributes['placeholder'] ) + ); + + if ( ! empty( $attributes['buttonText'] ) ) { + $button_markup = sprintf( + '', + $attributes['buttonText'] + ); + } return sprintf( - $html, + '', esc_url( home_url( '/' ) ), - 'wp-block-search__input-' . ++$instance_id, - esc_html( $attributes['label'] ), - esc_attr( $attributes['placeholder'] ), - esc_attr( get_search_query() ) + $label_markup . $input_markup . $button_markup ); } @@ -46,7 +60,11 @@ function register_block_core_search() { ), 'placeholder' => array( 'type' => 'string', - 'default' => __( 'Enter a search keyword or phrase' ), + 'default' => '', + ), + 'buttonText' => array( + 'type' => 'string', + 'default' => __( 'Search' ), ), ), diff --git a/packages/block-library/src/search/style.scss b/packages/block-library/src/search/style.scss index 87b8db9ac1a3b..0b65f440f719e 100644 --- a/packages/block-library/src/search/style.scss +++ b/packages/block-library/src/search/style.scss @@ -1,10 +1,17 @@ .wp-block-search { + display: flex; + flex-wrap: wrap; + .wp-block-search__label { - display: block; font-weight: bold; + width: 100%; } .wp-block-search__input { - width: 100%; + flex-grow: 1; + } + + .wp-block-search__button { + margin-left: 10px; } } diff --git a/test/integration/full-content/fixtures/core__search__custom-text.html b/test/integration/full-content/fixtures/core__search__custom-text.html index e99a8009a342d..bb6e6a56c9a33 100644 --- a/test/integration/full-content/fixtures/core__search__custom-text.html +++ b/test/integration/full-content/fixtures/core__search__custom-text.html @@ -1 +1 @@ - + diff --git a/test/integration/full-content/fixtures/core__search__custom-text.parsed.json b/test/integration/full-content/fixtures/core__search__custom-text.parsed.json index 3755dbc0b2962..fd128b35f93c8 100644 --- a/test/integration/full-content/fixtures/core__search__custom-text.parsed.json +++ b/test/integration/full-content/fixtures/core__search__custom-text.parsed.json @@ -2,6 +2,7 @@ { "blockName": "core/search", "attrs": { + "buttonText": "Custom button text", "label": "Custom label", "placeholder": "Custom placeholder" }, From ab4ba8de7059a2bd1a7d12ea0bf6fec41107a8af Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 31 Jan 2019 15:57:48 +1100 Subject: [PATCH 06/15] Update CHANGELOG --- packages/block-library/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 12ab36c1f2104..427d55ba22412 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -4,6 +4,7 @@ - Add background color controls for the table block. - Add new `RSS` block ([#7966](https://github.com/WordPress/gutenberg/pull/7966)). +- Add new `Search` block ([#13583](https://github.com/WordPress/gutenberg/pull/13583)). ## 2.2.12 (2019-01-03) From cd1d839c882d8d2fab85e20e7808e8a0919e9e98 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 31 Jan 2019 16:58:03 +1100 Subject: [PATCH 07/15] Search block: Support custom CSS classes --- packages/block-library/src/search/edit.js | 7 +------ packages/block-library/src/search/index.php | 8 +++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 31df5c162cdf4..52e3c27381362 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ @@ -13,7 +8,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { const { label, placeholder, buttonText } = attributes; return ( -
+
%s', + '', + $class, esc_url( home_url( '/' ) ), $label_markup . $input_markup . $button_markup ); From 1eae8ea6cf3fa1b11a9cd01e097b9b8aa40e80df Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 1 Feb 2019 10:44:37 +1100 Subject: [PATCH 08/15] Search block: Add aria-label to placeholder --- packages/block-library/src/search/edit.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 52e3c27381362..0b714a0c6e31a 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -11,25 +11,26 @@ export default function SearchEdit( { className, attributes, setAttributes } ) {
setAttributes( { label: html } ) } /> setAttributes( { placeholder: event.target.value } ) } /> setAttributes( { buttonText: html } ) } />
From fb9b79015e45f2603d9e0f5979901861283c8196 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 1 Feb 2019 10:48:37 +1100 Subject: [PATCH 09/15] Search block: Style label as bold in theme.scss --- packages/block-library/src/search/style.scss | 1 - packages/block-library/src/search/theme.scss | 5 +++++ packages/block-library/src/theme.scss | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/block-library/src/search/theme.scss diff --git a/packages/block-library/src/search/style.scss b/packages/block-library/src/search/style.scss index 0b65f440f719e..80a8a20b5fd37 100644 --- a/packages/block-library/src/search/style.scss +++ b/packages/block-library/src/search/style.scss @@ -3,7 +3,6 @@ flex-wrap: wrap; .wp-block-search__label { - font-weight: bold; width: 100%; } diff --git a/packages/block-library/src/search/theme.scss b/packages/block-library/src/search/theme.scss new file mode 100644 index 0000000000000..f95849183b5f6 --- /dev/null +++ b/packages/block-library/src/search/theme.scss @@ -0,0 +1,5 @@ +.wp-block-search { + .wp-block-search__label { + font-weight: bold; + } +} diff --git a/packages/block-library/src/theme.scss b/packages/block-library/src/theme.scss index 3dcef9d811ecb..7a4dcce562f8a 100644 --- a/packages/block-library/src/theme.scss +++ b/packages/block-library/src/theme.scss @@ -2,5 +2,6 @@ @import "./preformatted/theme.scss"; @import "./pullquote/theme.scss"; @import "./quote/theme.scss"; +@import "./search/theme.scss"; @import "./separator/theme.scss"; @import "./table/theme.scss"; From 0d3fb096f1058d822d70ee9d92d846487b543a1e Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 1 Feb 2019 11:01:05 +1100 Subject: [PATCH 10/15] Search block: Add aria-label to all inputs --- packages/block-library/src/search/edit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 0b714a0c6e31a..275aeace8b111 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -11,6 +11,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) {
setAttributes( { placeholder: event.target.value } ) } @@ -27,6 +28,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { Date: Fri, 1 Feb 2019 11:07:53 +1100 Subject: [PATCH 11/15] Search block: Use ellipsis at end of input placeholders --- packages/block-library/src/search/edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 275aeace8b111..65b5718d8cabb 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -12,7 +12,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { setAttributes( { placeholder: event.target.value } ) } /> @@ -29,7 +29,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { wrapperClassName="wp-block-search__button" className="wp-block-search__button-rich-text" aria-label={ __( 'Button text' ) } - placeholder={ __( 'Add button text' ) } + placeholder={ __( 'Add button text…' ) } keepPlaceholderOnFocus formattingControls={ [] } value={ buttonText } From 154cddcacb1b577b2c40cee5c901cb47e6b5e472 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 1 Feb 2019 11:51:18 +1100 Subject: [PATCH 12/15] Search block: Display placeholder in 'placeholder' attribute, not 'value' --- packages/block-library/src/search/edit.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 65b5718d8cabb..7bc07c078de1c 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -21,8 +21,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { setAttributes( { placeholder: event.target.value } ) } /> Date: Fri, 1 Feb 2019 12:56:57 +1100 Subject: [PATCH 13/15] Revert "Search block: Display placeholder in 'placeholder' attribute, not 'value'" This reverts commit 154cddcacb1b577b2c40cee5c901cb47e6b5e472. --- packages/block-library/src/search/edit.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 7bc07c078de1c..65b5718d8cabb 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -21,7 +21,8 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { setAttributes( { placeholder: event.target.value } ) } /> Date: Mon, 4 Feb 2019 10:32:23 +1100 Subject: [PATCH 14/15] Search block: Remove placeholder attribute when there is a placeholder value --- packages/block-library/src/search/edit.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 65b5718d8cabb..87148284574f9 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -21,7 +21,10 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { setAttributes( { placeholder: event.target.value } ) } /> From dffa8d3809403e50dc938fd1af578147e6c408c0 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 7 Feb 2019 10:37:28 +1100 Subject: [PATCH 15/15] Search block: Fix placeholder attribute receiving false instead of undefined --- packages/block-library/src/search/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index 87148284574f9..f5a5acd20c498 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -24,7 +24,7 @@ export default function SearchEdit( { className, attributes, setAttributes } ) { // We hide the placeholder field's placeholder when there is a value. This // stops screen readers from reading the placeholder field's placeholder // which is confusing. - placeholder={ ! placeholder && __( 'Optional placeholder…' ) } + placeholder={ placeholder ? undefined : __( 'Optional placeholder…' ) } value={ placeholder } onChange={ ( event ) => setAttributes( { placeholder: event.target.value } ) } />