Gutenberg: Limit number of columns

Created on 19 Oct 2018  路  11Comments  路  Source: WordPress/gutenberg

When using the Columns block, is there a way to limit the number of columns?
As of now, the user can choose between 2-6 columns.
If I want to limit this to say, no more than 4 columns, how do I achieve that?

[Block] Columns [Block] Gallery [Feature] Extensibility [Type] Enhancement

All 11 comments

To my knowledge, this would not be possible except through very complex direct replacement of the Columns edit implementation using the BlockEdit filter, which is not something I'd advise.

Ideally for themer extension, this would be something where the Columns block attributes could be extended / filtered to specify a minimum / maximum value for the columns attribute, which would then be referenced as the min / max attributes passed to the range rendered in the editor.

Would be great to have the same filter functionality for the gallery block.

+1 for the ability to limit the number of columns also on the Gallery Block.

Created an initial PR for this now, see #12861. Any feedback welcome!

As of now, the user can choose between 2-6 columns.

Or enter as many as the user wants...
99-columns
WP 5.0.2-alpha-44105 at wordpress.org/gutenberg

I was thinking about this and I'm not sure it is a good idea to limit the minimum amount of columns to 2. Having 1 there would allow this block to work as a container which I'm pretty sure in some cases would be useful to add some custom classes to the block or something similar.

Having 1 there would allow this block to work as a container which I'm pretty sure in some cases would be useful to add some custom classes to the block or something similar.

This is better done in a separate section block, see #4900.

Or enter as many as the user wants...

That sounds like a bug in the RangeControl component to me. I just crashed my browser by typing a super high number in there because adding columns is so slow. The maximum enforces a limit when clicking the upper arrow, but it's not validated onChange.

This is better done in a separate section block, see #4900.

Too late, issue open since 10 months, still no such block in Gutenberg, so people look for, find and use "one column" blocks as an alternative, one example of many out there...

Having 1 as the minimum would make it work similar to the gallery block.

Also makes sense for the following scenario:

  • Designer designs responsive website
  • Developer defines some front-end breakpoints according to the design spec
  • Developer sets minimum and maximum values of columns for columns and gallery block (maybe there's other blocks where this would make sense)
  • Editor sets a different amount of columns for each of those breakpoints (1 for mobile 99% of the time)

Some plugins are already adding controls to customize a block's options given multiple breakpoints. This would be useful to have in core for theme developers and I guess it'll land at some point in the future?

This could be achieved very neatly by the method we're proposing in https://github.com/WordPress/gutenberg/issues/18892

As well as restricting column choices it would also be useful to be able to disable manual resizing (of column widths) for certain layouts; again the method proposed #18892 would seem like a clean and simple way to permit this; the block would just need to be made sensitive to the presence of the relevant extensions.

Was this page helpful?
0 / 5 - 0 ratings