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 Mar 11, 2019
1 parent 6d81e2a commit 2010aa2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,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 @@ -238,7 +243,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 @@ -300,7 +304,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 2010aa2

Please sign in to comment.