diff --git a/modules/search/instant-search/components/search-filter-post-types.jsx b/modules/search/instant-search/components/search-filter-post-types.jsx index 3ff2751426221..188edb8cdca91 100644 --- a/modules/search/instant-search/components/search-filter-post-types.jsx +++ b/modules/search/instant-search/components/search-filter-post-types.jsx @@ -3,18 +3,33 @@ /** * External dependencies */ -import { h, Component } from 'preact'; +import { h, createRef, Component } from 'preact'; import strip from 'strip'; +import { getCheckedInputNames } from '../lib/dom'; export default class SearchFilterPostTypes extends Component { + constructor( props ) { + super( props ); + this.state = { selected: this.props.initialValue }; + this.filtersList = createRef(); + } + + toggleFilter = () => { + const selected = getCheckedInputNames( this.filtersList.current ); + this.setState( { selected }, () => { + this.props.onChange( 'postTypes', selected ); + } ); + }; + renderPostType = ( { key, doc_count: count } ) => { - const name = this.props.postTypes[ key ]; + const name = key in this.props.postTypes ? this.props.postTypes[ key ] : key; return (