WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

AlignmentControlMatrix display doesn't respect the `width` prop. #34665

Open ryanwelcher opened 3 years ago

ryanwelcher commented 3 years ago

Description

While updating the documentation for the AlignmentControlMatrix, I found that no matter what value I passed to the width prop, the display was always the same.

Step-by-step reproduction instructions

  1. Add the code snippet to a plugin
  2. Change the width value to anything other than the default of 92
  3. The widget of the component is unchanged

Screenshots, screen recording, code snippet

I created a simple plugin with the following code to render the control:

import { __experimentalAlignmentMatrixControl as AlignmentMatrixControl } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { registerPlugin } from '@wordpress/plugins';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';

const Example = () => {
    const [ alignment, setAlignment ] = useState( 'center center' );
    return (
        <PluginDocumentSettingPanel title="test">
            <AlignmentMatrixControl
                width="2000"
                value={ alignment }
                onChange={ ( newAlignment ) => setAlignment( newAlignment ) }
            />
        </PluginDocumentSettingPanel>
    );
};

registerPlugin( 'my-plugin', { render: Example } );

As you can see in the screenshot, the value is passed to the markup but the default value ( 92 ) is overriding the styles.

AlignmentMatrixControl

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

ryanwelcher commented 3 years ago

Discovered while working on #34662

ajskelton commented 3 weeks ago

@ryanwelcher While testing out the AlignmentControlMatrix today I came across this old open issue. However it appears to be fixed now as setting the width attribute does control the width of the component.

Here is a playground with a block using the AlignmentControlMatrix component and the width is set to 248 (the max width of the sidebar when inside a PanelBody). AlignmentMatrixTest Playground

That playground is loading this plugin that has a simple block using the AlignmentMatrixControl: Plugin Block with width attribute set