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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 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 @@ -221,18 +222,40 @@ 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 ) =>
onChange( {
...layout,
columnCount: value,
} )
}
value={ columnCount }
min={ 1 }
/>
</FlexItem>
<FlexItem isBlock>
<RangeControl
value={ columnCount }
onChange={ ( value ) =>
onChange( {
...layout,
columnCount: value,
} )
}
min={ 1 }
max={ 16 }
withInputField={ false }
/>
</FlexItem>
</Flex>
</fieldset>
);
}

Expand Down Expand Up @@ -275,16 +298,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>
);
}
Loading