Skip to content

Commit

Permalink
HierarchicalTermSelector: Use TextControl component (#33545)
Browse files Browse the repository at this point in the history
* Update selector in e2e tests
  • Loading branch information
Mamaduka authored Jul 20, 2021
1 parent 3b8d568 commit 3c84158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/editor/various/taxonomies.test.js
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

0 comments on commit 3c84158

Please sign in to comment.