Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust alignment-toolbar so that we disable the left, middle & right alignment options as needed #5195

Closed
gubbigubbi opened this issue Feb 22, 2018 · 5 comments

Comments

@gubbigubbi
Copy link

Issue Overview

There will be blocks which will only require the full/wide width options and wouldnt need the left, right, centre alignment options. For example I have made a 'section' block which wraps other blocks similar to rows in page builder plugins.

untitled___ grey_matter_concrete _wordpress

It looks like the alignment options are constants in the block-alignment component:
const ALIGNMENT_CONTROLS = [ { icon: 'editor-alignleft', title: __( 'Align left' ), align: 'left', }, { icon: 'editor-aligncenter', title: __( 'Align center' ), align: 'center', }, { icon: 'editor-alignright', title: __( 'Align right' ), align: 'right', }, ];

Possible Solution

It would be cool if when defining the you could specifiy which alignment constants could shown. Something like:

``
<BlockAligmnentToolbar allowedControls = array['left'] />

``

I am happy to help with expanding the documentation on this feature.

@youknowriad
Copy link
Contributor

Ther's a prop "controls" you can use to do that

<BlockAligmnentToolbar controls={['left']} />

@gziolo
Copy link
Member

gziolo commented Feb 22, 2018

It is also available to specify the list of alignment controls when registering your block as described here: https://github.com/WordPress/gutenberg/blob/a3ceee55afbe0200a1567945e14de6f3b3f14f61/docs/block-api.md#supports-optional. This update to documentation should land in the master together with the changes included in #5099.

registerBlockType( 'my-block', {
    supports: {
        align: [ 'left' ],
    },
    // ... rest of your definitions 
} );

If you use this option you don't need to manually include <BlockAligmnentToolbar controls={['left']} /> in your code. The editor will handle it for you.

@gubbigubbi
Copy link
Author

gubbigubbi commented Feb 22, 2018 via email

@gziolo
Copy link
Member

gziolo commented Feb 23, 2018

Good idea to include it there, too. If you would open a PR, that would be awesome 👍

@gubbigubbi
Copy link
Author

Cheers will do this weekend :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants