gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

BlockControls handling with multiple editable elements that trigger a truthy isSelected

Open xupaosso opened this issue 8 years ago • 3 comments

Issue Overview

When creating blocks with multiple editable elements that can trigger an isSelected state (e.g. RichText), the BlockControls will expand to include the editing controls for all the elements within that block with no identifying characteristics. A native block following this format is the Text Columns block

screen shot 2018-02-27 at 1 35 37 pm Shown above: two sets of RichText editing controls - one for each column

Are there plans to:

  1. Set sub selected states for the individual blocks to trigger the BlockControls?
  2. Create sub block groups that can have their own isSelected triggers?
  3. Create some kind of identifier in the BlockControls UI to define which element is being affected?

xupaosso avatar Feb 27 '18 20:02 xupaosso

Was going to report this. It should show as only one is enough. Mine was like 3 column then 3 editing control.

Emilybkk avatar Feb 28 '18 06:02 Emilybkk

I've had a chance to look into this more. This issue lies in the following code for the RichText element (blocks/rich-text/index.js):

{ isSelected &&
  <Fill name="Formatting.Toolbar">
    { ! inlineToolbar && formatToolbar }
  </Fill>
}
{ isSelected && inlineToolbar &&
  <div className="block-rich-text__inline-toolbar">
    { formatToolbar }
  </div>
}

the isSelected value is determined by the entire block state, and not by the individual RichText components. If there are multiple RichText components in the block, this code executes for every one of them. We need to find some way to determine if the node is selected or if the block is selected.

xupaosso avatar Mar 05 '18 21:03 xupaosso

There's no issue in the RichText component itself, you can take a look at how we achieve this in the quote block for instance to pass an isSelected value true to only one RichText at a time

https://github.com/WordPress/gutenberg/blob/master/blocks/library/quote/index.js#L214-L215

youknowriad avatar Mar 06 '18 16:03 youknowriad