javascript – How do add more elements to an already existing section in Gutenberg

Question

I am filtering core block to add more functionality and I know how I can create a new section in the sidebar that is opened by default like this:

        return (
            <>
                <InspectorControls>
                    <PanelBody
                        title={ __( 'Block Attributes' ) }
                        initialOpen={ true }
                    >
                        <TextControl
                            label={ __( '<table> class(es)' ) }
                            value={ tableClass }
                            onChange={ ( newTableClass ) =>
                                props.setAttributes( {
                                    tableClass: newTableClass,
                                } )
                            }
                        />
                    </PanelBody>
                </InspectorControls>

                <Stuff />
            </>
        );

Code somewhere else:

        return (
            <>
                <InspectorControls>
                    <PanelBody
                        title={ __( 'Block Attributes' ) }
                        initialOpen={ true }
                    >
                        <SomeThing />
                    </PanelBody>
                </InspectorControls>

                <Stuff />
            </>
        );

My issue is, I like to add to this section from a totally different place in the code. When I do this and give the <PanelBody> The same title, there will be just another <PanelBody> being created instead of adding the controls to the already existing <PanelBody>.

Btw, I know there is a ‘Advanced’ section for id and class but I do like to create my own. Should probably be another question but I also like to know how I can move the Advanced section to the very top and open it my default. I like my own section but adding my controls to the Advanced section would also be a less desirable solution for me, I have seen plugins do that.

0
NextGenThemes 2 months 2023-03-21T15:50:46-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse