Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Controls: Take into account mixed controls use-case
  • Loading branch information
youknowriad committed Apr 27, 2017
commit 39abb03cc8d9ebbd6ea69e457db8edfc45746951
12 changes: 7 additions & 5 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { connect } from 'react-redux';
import classnames from 'classnames';
import { Slot } from 'react-slot-fill';
import { first } from 'lodash';
import { reduce, last } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -138,9 +138,11 @@ class VisualEditorBlock extends wp.element.Component {
wrapperProps = settings.getEditWrapperProps( block.attributes );
}

const toolbars = settings.controls && settings.controls.length && ! Array.isArray( first( settings.controls ) )
? [ settings.controls ]
: settings.controls;
const toolbars = reduce( settings.controls, ( memo, toolbar ) => (
Array.isArray( toolbar )
? [ ...memo, toolbar ]
: [ ...memo.slice( 0, -1 ), [ ...( last( memo ) || [] ), toolbar ] ]
), [] );

// Disable reason: Each block can receive focus but must be able to contain
// block children. Tab keyboard navigation enabled by tabIndex assignment.
Expand All @@ -164,7 +166,7 @@ class VisualEditorBlock extends wp.element.Component {
{ isSelected && ! isTyping &&
<div className="editor-visual-editor__block-controls">
<BlockSwitcher uid={ block.uid } />
{ !! toolbars && toolbars.map( ( controls, index ) => (
{ toolbars.map( ( controls, index ) => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will error if a block doesn't define controls because toolbars will be undefined. We'll want to restore the truthy test or use Lodash's map.

<Toolbar
key={ index }
controls={ controls.map( ( control ) => ( {
Expand Down