-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
bfec616
commit 5778c3c
Showing
14 changed files
with
151 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Fragment> | ||
<form | ||
role="search" | ||
method="get" | ||
className="search-form" | ||
onSubmit={ this.handleFormSubmit } | ||
> | ||
<label> | ||
<span className="search-label">{ label }</span> | ||
<input | ||
type="search" | ||
className="search-field" | ||
placeholder={ placeholder } | ||
value="" | ||
name="s" | ||
/> | ||
</label> | ||
<input type="submit" className="search-submit" value={ submitValue } /> | ||
</form> | ||
{ focus && ( | ||
<InspectorControls key="inspector"> | ||
<TextControl | ||
label={ __( 'Search label' ) } | ||
value={ label } | ||
onChange={ this.updateLabel } | ||
help={ __( 'Provides a label for the search field.' ) } | ||
/> | ||
<TextControl | ||
label={ __( 'Placeholder text' ) } | ||
value={ placeholder } | ||
onChange={ this.updatePlaceholder } | ||
help={ __( 'Provides placeholder text for the search field.' ) } | ||
/> | ||
<TextControl | ||
label={ __( 'Submit text' ) } | ||
value={ submitValue } | ||
onChange={ this.updateSubmitValue } | ||
help={ __( 'The text for the form submit button.' ) } | ||
/> | ||
</InspectorControls> | ||
) } | ||
</Fragment> | ||
); | ||
} | ||
import { RichText, InspectorControls } from '@wordpress/editor'; | ||
import { PanelBody, TextControl } from '@wordpress/components'; | ||
|
||
export default function SearchEdit( { attributes, setAttributes } ) { | ||
const { label, placeholder } = attributes; | ||
|
||
return ( | ||
<Fragment> | ||
<div className="wp-block-search"> | ||
<RichText | ||
tagName="div" | ||
className="wp-block-search__label" | ||
value={ label } | ||
formattingControls={ [] } | ||
onChange={ ( text ) => setAttributes( { label: text } ) } | ||
/> | ||
<input | ||
type="search" | ||
className="wp-block-search__input" | ||
value="" | ||
placeholder={ placeholder } | ||
/> | ||
</div> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Search Settings' ) }> | ||
<TextControl | ||
label={ __( 'Placeholder text' ) } | ||
value={ placeholder } | ||
onChange={ ( text ) => setAttributes( { placeholder: text } ) } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
</Fragment> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.wp-block-search { | ||
.wp-block-search__label { | ||
display: block; | ||
font-weight: bold; | ||
} | ||
|
||
.wp-block-search__input { | ||
width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:search /--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"clientId": "_clientId_0", | ||
"name": "core/search", | ||
"isValid": true, | ||
"attributes": {}, | ||
"innerBlocks": [], | ||
"originalContent": "" | ||
} | ||
] |
18 changes: 18 additions & 0 deletions
18
test/integration/full-content/fixtures/core__search.parsed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"blockName": "core/search", | ||
"attrs": {}, | ||
"innerBlocks": [], | ||
"innerHTML": "", | ||
"innerContent": [] | ||
}, | ||
{ | ||
"blockName": null, | ||
"attrs": {}, | ||
"innerBlocks": [], | ||
"innerHTML": "\n", | ||
"innerContent": [ | ||
"\n" | ||
] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
test/integration/full-content/fixtures/core__search.serialized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:search /--> |
1 change: 1 addition & 0 deletions
1
test/integration/full-content/fixtures/core__search__custom-text.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:search {"label":"Custom label","placeholder":"Custom placeholder"} /--> |
10 changes: 10 additions & 0 deletions
10
test/integration/full-content/fixtures/core__search__custom-text.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"clientId": "_clientId_0", | ||
"name": "core/search", | ||
"isValid": true, | ||
"attributes": {}, | ||
"innerBlocks": [], | ||
"originalContent": "" | ||
} | ||
] |
21 changes: 21 additions & 0 deletions
21
test/integration/full-content/fixtures/core__search__custom-text.parsed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
test/integration/full-content/fixtures/core__search__custom-text.serialized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:search /--> |