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

Is it possible to group multiple checkboxes? #12732

Closed
pryley opened this issue Dec 9, 2018 · 2 comments
Closed

Is it possible to group multiple checkboxes? #12732

pryley opened this issue Dec 9, 2018 · 2 comments
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@pryley
Copy link

pryley commented Dec 9, 2018

I am building a custom block based on a shortcode. I have a use-case where I am using checkboxes that toggle their value in an attribute option array when checked (similar to using a multi-Select element). I need them grouped visually.

Is this possible to do and if so, how?

Individual checkboxes:

edit page site-reviews wordpress 2018-12-09 23-10-26

Grouped checkboxes:

edit page site-reviews wordpress 2018-12-09 23-13-55

@pryley
Copy link
Author

pryley commented Dec 9, 2018

The only way I can figure out to do this it is by writing the BaseControl and CheckboxControl components manually, something like this:

el( 'div',
    { className: 'components-base-control' },
    el( 'div',
        { className: 'components-base-control__field' },
        el( 'input', {
            id: 'inspector-checkbox-control-hide-0',
            type: 'checkbox',
            value: '1',
            onChange: toggleHide.bind( props, 'if_empty' ),
            className: 'components-checkbox-control__input',
        }),
        el( 'label', {
            className: 'components-checkbox-control__label',
            htmlFor: 'inspector-checkbox-control-hide-0',
        }, __('Hide if empty'))
    ),
    el( 'div',
        { className: 'components-base-control__field' },
        el( 'input', {
            id: 'inspector-checkbox-control-hide-1',
            type: 'checkbox',
            value: '1',
            onChange: toggleHide.bind( props, 'bars' ),
            className: 'components-checkbox-control__input',
        }),
        el( 'label', {
            className: 'components-checkbox-control__label',
            htmlFor: 'inspector-checkbox-control-hide-1',
        }, __('Hide the bars'))
    )
    // ...
)

The only problem is that I don't know how to get the instance ID so am having to create my own ID.

There must be a simpler (more concise) way to do this...

@designsimply designsimply added [Type] Question Questions about the design or development of the editor. Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions. and removed [Type] Question Questions about the design or development of the editor. labels Dec 9, 2018
@designsimply
Copy link
Member

Based on the screenshots, it looks like you're trying to reduce the vertical spacing between the checkboxes, is that right?

I am new to JavaScript, so I don't know if there's a better way to do the BaseControl and CheckboxControl components, but I was wondering if you could resolve the problem using CSS in your custom block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

2 participants