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

Allow more columns in manual grid layout and change toggle order #59116

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 53 additions & 17 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Flex,
FlexItem,
RangeControl,
__experimentalNumberControl as NumberControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalUnitControl as UnitControl,
Expand Down Expand Up @@ -200,6 +201,8 @@ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
value={ value }
units={ units }
min={ 0 }
label={ __( 'Minimum column width' ) }
hideLabelFromVision
/>
</FlexItem>
<FlexItem isBlock>
Expand All @@ -209,6 +212,8 @@ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
min={ 0 }
max={ RANGE_CONTROL_MAX_VALUES[ unit ] || 600 }
withInputField={ false }
label={ __( 'Minimum column width' ) }
hideLabelFromVision
/>
</FlexItem>
</Flex>
Expand All @@ -221,18 +226,49 @@ function GridLayoutColumnsControl( { layout, onChange } ) {
const { columnCount = 3 } = layout;

return (
<RangeControl
label={ __( 'Columns' ) }
value={ columnCount }
onChange={ ( value ) =>
onChange( {
...layout,
columnCount: value,
} )
}
min={ 1 }
max={ 6 }
/>
<fieldset>
<BaseControl.VisualLabel as="legend">
{ __( 'Columns' ) }
</BaseControl.VisualLabel>
<Flex gap={ 4 }>
<FlexItem isBlock>
<NumberControl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When moving to a separate NumberControl and RangeControl component, I think both components will still need a label prop in order for the fields to be accessible. There was a PR a little while back for fixing this in the HeightControl component: #57683 which resolved the issue described in #57681. (TL;DR — it turned out the fieldset wasn't enough of a label for the controls, but we can use label and hideLabelFromVision props on these two components to get the labels linked). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point! We'll need the same in the min column width controls too; I'll just add it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

size={ '__unstable-large' }
onChange={ ( value ) => {
/**
* If the input is cleared, avoid switching
* back to "Auto" by setting a value of "1".
*/
const validValue = value !== '' ? value : '1';
onChange( {
...layout,
columnCount: validValue,
} );
} }
value={ columnCount }
min={ 1 }
label={ __( 'Columns' ) }
hideLabelFromVision
/>
</FlexItem>
<FlexItem isBlock>
<RangeControl
value={ parseInt( columnCount, 10 ) } // RangeControl can't deal with strings.
onChange={ ( value ) =>
onChange( {
...layout,
columnCount: value,
} )
}
min={ 1 }
max={ 16 }
withInputField={ false }
label={ __( 'Columns' ) }
hideLabelFromVision
/>
</FlexItem>
</Flex>
</fieldset>
);
}

Expand Down Expand Up @@ -275,16 +311,16 @@ function GridLayoutTypeControl( { layout, onChange } ) {
onChange={ onChangeType }
isBlock={ true }
>
<ToggleGroupControlOption
key={ 'manual' }
value="manual"
label={ __( 'Manual' ) }
/>
<ToggleGroupControlOption
key={ 'auto' }
value="auto"
label={ __( 'Auto' ) }
/>
<ToggleGroupControlOption
key={ 'manual' }
value="manual"
label={ __( 'Manual' ) }
/>
</ToggleGroupControl>
);
}