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
Added comment to Heading Edit component
  • Loading branch information
igmoweb committed Mar 28, 2019
commit 590592cddb160e2336ba20af960536955a511580
3 changes: 2 additions & 1 deletion packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function HeadingEdit( {
const tagName = 'h' + level;
const BlockControlsLevelsRange = ( levelChoices.length <= 3 ) ?
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

levelChoices :
levelChoices.slice( 1, 4 );
levelChoices.slice( 1, 4 ); //
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I'm following what the logic is here as far as the second, third, fourth, and fifth level choice options being significant. I sense you'd considered to add an inline comment but forgot to complete it?

Taking a guess with the default options, is it mostly about limiting to a select few common options, and omitting H1 specifically? In that case it seems more accurate to express as something like take( without( levelChoices, [ 1 ] ), 3 ) (Array#slice can work just as well)

https://lodash.com/docs/4.17.11#take
https://lodash.com/docs/4.17.11#without

This also seems like it would help avoid having to test length <= 3 and just have a single consistent expression for computing the level choices.

Copy link
Author

Choose a reason for hiding this comment

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

@aduth What I'm trying to do here is to replicate the previous behavior in the BlockControls options (not the sidebar). Right now, it displays only 3 headings: H2, H3 and H4. So if the levels list contains 3 or less options, it will display all of them, otherwise, slice the array and display 3 elements starting by the second one. I think using Lodash for that would be an overkill for such a simple operation.

return (
<Fragment>
<BlockControls>
Expand Down Expand Up @@ -83,6 +83,7 @@ function HeadingEdit( {
}

export default withSelect( ( select ) => {
// Parse the h1,h2,h3... choices to level numbers and pass it as a prop.
const levelChoices = get(
select( 'core/blocks' ).getBlockType( 'core/heading' ),
[ 'attributes', 'content', 'selector' ],
Expand Down