Skip to content

Display heading levels dynamically in Heading Options when Heading block is selected #14688

@igmoweb

Description

@igmoweb

So far, the heading levels are hardcoded in the Heading Edit component.

Captura de pantalla 2019-03-28 a las 18 13 33

Here are the current lines of code in public_html/wp-content/plugins/gutenberg/packages/block-library/src/heading:

<HeadingToolbar minLevel={ 2 } maxLevel={ 5 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />

And

<HeadingToolbar minLevel={ 1 } maxLevel={ 7 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />

However, under some circumstances, this selection could be limited by using blocks.registerBlockType filter to a reduced set of headings. Right now this is tricky due to the hardcoded numbers.

Describe the solution you'd like
Dynamically, extract the level numbers from selector attribute in attributes.content for Heading Block and generate the range of selectors based on that list.

I'm pushing a PR to demonstrate in a sec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions