Skip to content

Commit

Permalink
Fix: Inserter impossible to collapse panels while searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Feb 14, 2019
1 parent b514fb6 commit fe7f504
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,16 @@ export class InserterMenu extends Component {
if ( filterValue !== this.state.filterValue ) {
if ( ! filterValue ) {
openPanels = [ 'suggested' ];
} else if ( reusableItems.length ) {
openPanels = [ 'reusable' ];
} else if ( filteredItems.length ) {
const firstCategory = find( getCategories(), ( { slug } ) => itemsPerCategory[ slug ] && itemsPerCategory[ slug ].length );
openPanels = [ firstCategory.slug ];
} else {
openPanels = [];
if ( reusableItems.length ) {
openPanels.push( 'reusable' );
}
if ( filteredItems.length ) {
openPanels = openPanels.concat(
Object.keys( itemsPerCategory )
);
}
}
}

Expand Down Expand Up @@ -239,7 +244,6 @@ export class InserterMenu extends Component {
const { instanceId, onSelect, rootClientId } = this.props;
const { childItems, filterValue, hoveredItem, suggestedItems, reusableItems, itemsPerCategory, openPanels } = this.state;
const isPanelOpen = ( panel ) => openPanels.indexOf( panel ) !== -1;
const isSearching = !! filterValue;

// Disable reason (no-autofocus): The inserter menu is a modal display, not one which
// is always visible, and one which already incurs this behavior of autoFocus via
Expand Down Expand Up @@ -303,7 +307,7 @@ export class InserterMenu extends Component {
key={ category.slug }
title={ category.title }
icon={ category.icon }
opened={ isSearching || isPanelOpen( category.slug ) }
opened={ isPanelOpen( category.slug ) }
onToggle={ this.onTogglePanel( category.slug ) }
ref={ this.bindPanel( category.slug ) }
>
Expand Down

0 comments on commit fe7f504

Please sign in to comment.