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

fix: Avoid unsupported Gallery MenuGroup usage #63953

Merged
Show file tree
Hide file tree
Changes from all 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
88 changes: 51 additions & 37 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,17 @@ function GalleryEdit( props ) {
size="__unstable-large"
/>
) }
{ Platform.isNative ? (
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Link to' ) }
value={ linkTo }
onChange={ setLinkTo }
options={ linkOptions }
hideCancelButton
size="__unstable-large"
/>
) : null }
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Crop images to fit' ) }
Expand Down Expand Up @@ -615,43 +626,46 @@ function GalleryEdit( props ) {
) }
</PanelBody>
</InspectorControls>
<BlockControls group="block">
<ToolbarDropdownMenu
icon={ linkIcon }
label={ __( 'Link To' ) }
>
{ ( { onClose } ) => (
<MenuGroup className="blocks-gallery__link-to-control">
{ linkOptions.map( ( linkItem ) => {
const isOptionSelected =
linkTo === linkItem.value;
return (
<MenuItem
key={ linkItem.value }
isSelected={ isOptionSelected }
className={ clsx(
'components-dropdown-menu__menu-item',
{
'is-active': isOptionSelected,
}
) }
iconPosition="left"
icon={ linkItem.icon }
onClick={ () => {
setLinkTo( linkItem.value );
onClose();
} }
role="menuitemradio"
info={ linkItem.infoText ?? false }
>
{ linkItem.label }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
</BlockControls>
{ Platform.isWeb ? (
<BlockControls group="block">
<ToolbarDropdownMenu
icon={ linkIcon }
label={ __( 'Link To' ) }
>
{ ( { onClose } ) => (
<MenuGroup className="blocks-gallery__link-to-control">
{ linkOptions.map( ( linkItem ) => {
const isOptionSelected =
linkTo === linkItem.value;
return (
<MenuItem
key={ linkItem.value }
isSelected={ isOptionSelected }
className={ clsx(
'components-dropdown-menu__menu-item',
{
'is-active':
isOptionSelected,
}
) }
iconPosition="left"
icon={ linkItem.icon }
onClick={ () => {
setLinkTo( linkItem.value );
onClose();
} }
role="menuitemradio"
info={ linkItem.infoText ?? false }
>
{ linkItem.label }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
</BlockControls>
) : null }
{ Platform.isWeb && (
<>
{ ! multiGallerySelection && (
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/gallery/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,11 @@ describe( 'Gallery block', () => {
<!-- /wp:gallery -->`,
numberOfItems: 2,
} );
const { getByLabelText, getByText } = screen;
const { getByText } = screen;

fireEvent.press( getBlock( screen, 'Gallery' ) );
fireEvent.press( getByLabelText( 'Link To' ) );
// Set "Link to" setting via Gallery block settings
await openBlockSettings( screen );
fireEvent.press( getByText( 'Link to' ) );
fireEvent.press( getByText( 'Link images to media files' ) );

expect( getEditorHtml() ).toMatchSnapshot();
Expand Down
Loading