Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HierarchicalTermSelector: Use TextControl component #33545

Merged
merged 4 commits into from
Jul 20, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe( 'Taxonomies', () => {

// Type the category name in the field.
await page.type(
'.editor-post-taxonomies__hierarchical-terms-input[type=text]',
'.editor-post-taxonomies__hierarchical-terms-input input[type=text]',
'z rand category 1'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { __, _x, _n, sprintf } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import {
CheckboxControl,
TextControl,
TreeSelect,
withSpokenMessages,
withFilters,
Expand Down Expand Up @@ -79,10 +80,8 @@ class HierarchicalTermSelector extends Component {
onUpdateTerms( newTerms, taxonomy.rest_base );
}

onChangeFormName( event ) {
const newValue =
event.target.value.trim() === '' ? '' : event.target.value;
this.setState( { formName: newValue } );
onChangeFormName( value ) {
this.setState( { formName: value } );
}

onChangeFormParent( newParent ) {
Expand Down Expand Up @@ -299,9 +298,8 @@ class HierarchicalTermSelector extends Component {
return termsTree;
}

setFilterValue( event ) {
setFilterValue( filterValue ) {
const { availableTermsTree } = this.state;
const filterValue = event.target.value;
const filteredTermsTree = availableTermsTree
.map( this.getFilterMatcher( filterValue ) )
.filter( ( term ) => term );
Expand Down Expand Up @@ -393,13 +391,7 @@ class HierarchicalTermSelector extends Component {
}

render() {
const {
slug,
taxonomy,
instanceId,
hasCreateAction,
hasAssignAction,
} = this.props;
const { slug, taxonomy, hasCreateAction, hasAssignAction } = this.props;

if ( ! hasAssignAction ) {
return null;
Expand Down Expand Up @@ -442,8 +434,6 @@ class HierarchicalTermSelector extends Component {
);
const noParentOption = `— ${ parentSelectLabel } —`;
const newTermSubmitLabel = newTermButtonLabel;
const inputId = `editor-post-taxonomies__hierarchical-terms-input-${ instanceId }`;
const filterInputId = `editor-post-taxonomies__hierarchical-terms-filter-${ instanceId }`;
const filterLabel = get(
this.props.taxonomy,
[ 'labels', 'search_items' ],
Expand All @@ -458,18 +448,12 @@ class HierarchicalTermSelector extends Component {

return [
showFilter && (
<label key="filter-label" htmlFor={ filterInputId }>
{ filterLabel }
</label>
),
showFilter && (
<input
type="search"
id={ filterInputId }
<TextControl
key="term-filter-input"
className="editor-post-taxonomies__hierarchical-terms-filter"
label={ filterLabel }
value={ filterValue }
onChange={ this.setFilterValue }
className="editor-post-taxonomies__hierarchical-terms-filter"
key="term-filter-input"
/>
),
<div
Expand All @@ -496,16 +480,9 @@ class HierarchicalTermSelector extends Component {
),
showForm && (
<form onSubmit={ this.onAddTerm } key="hierarchical-terms-form">
<label
htmlFor={ inputId }
className="editor-post-taxonomies__hierarchical-terms-label"
>
{ newTermLabel }
</label>
<input
type="text"
id={ inputId }
<TextControl
className="editor-post-taxonomies__hierarchical-terms-input"
label={ newTermLabel }
value={ formName }
onChange={ this.onChangeFormName }
required
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/post-taxonomies/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

.editor-post-taxonomies__hierarchical-terms-input {
margin-top: 8px;
width: 100%;
}
.editor-post-taxonomies__hierarchical-terms-filter {
margin-bottom: 8px;
Expand Down