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

Media Replace Flow: Add custom toggle support and fix button height #68084

Merged
merged 14 commits into from
Jan 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Placeholder,
Spinner,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Button,
} from '@wordpress/components';
import { __, _x, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
Expand Down Expand Up @@ -378,6 +379,9 @@ function BackgroundImageControls( {
/>
}
variant="secondary"
renderToggle={ ( props ) => (
<Button { ...props } __next40pxDefaultSize />
) }
onError={ onUploadError }
onReset={ () => {
closeAndFocus();
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

Are changes in this file still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, @Mamaduka. I've tried to explain it above in this comment.

Thanks a lot for reviewing the PR 🚀

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

.components-dropdown {
display: block;
height: 36px;

.block-editor-global-styles-background-panel__dropdown-toggle {
height: 40px;
}
}
}

Expand All @@ -44,7 +47,6 @@

.components-dropdown {
display: block;
height: 36px;
}

button.components-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ If passed, children are rendered inside the dropdown.
- Required: No

If passed, children are rendered inside the dropdown. If a function is provided for this prop, it will receive an object with the `onClose` prop as an argument.

### renderToggle

- Type: `func`
- Required: No

If passed, it will be used to render the provided button instead of the default one. It should accept and pass through `button` props to a `button` element.
38 changes: 23 additions & 15 deletions packages/block-editor/src/components/media-replace-flow/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
import {
FormFileUpload,
NavigableMenu,
MenuItem,
ToolbarButton,
Dropdown,
withFilters,
ToolbarButton,
} from '@wordpress/components';
import { useSelect, withDispatch } from '@wordpress/data';
import { DOWN } from '@wordpress/keycodes';
Expand Down Expand Up @@ -55,9 +54,9 @@ const MediaReplaceFlow = ( {
addToGallery,
handleUpload = true,
popoverProps,
renderToggle,
} ) => {
const { getSettings } = useSelect( blockEditorStore );
const editMediaButtonRef = useRef();
const errorNoticeID = `block-editor/media-replace-flow/error-notice/${ ++uniqueId }`;

const onUploadError = ( message ) => {
Expand Down Expand Up @@ -133,17 +132,27 @@ const MediaReplaceFlow = ( {
<Dropdown
popoverProps={ popoverProps }
contentClassName="block-editor-media-replace-flow__options"
renderToggle={ ( { isOpen, onToggle } ) => (
<ToolbarButton
ref={ editMediaButtonRef }
aria-expanded={ isOpen }
aria-haspopup="true"
onClick={ onToggle }
onKeyDown={ openOnArrowDown }
>
{ name }
</ToolbarButton>
) }
renderToggle={ ( { isOpen, onToggle } ) => {
if ( renderToggle ) {
return renderToggle( {
'aria-expanded': isOpen,
'aria-haspopup': 'true',
onClick: onToggle,
onKeyDown: openOnArrowDown,
children: name,
} );
}
return (
<ToolbarButton
aria-expanded={ isOpen }
aria-haspopup="true"
onClick={ onToggle }
onKeyDown={ openOnArrowDown }
>
{ name }
</ToolbarButton>
);
} }
renderContent={ ( { onClose } ) => (
<>
<NavigableMenu className="block-editor-media-replace-flow__media-upload-menu">
Expand Down Expand Up @@ -222,7 +231,6 @@ const MediaReplaceFlow = ( {
showSuggestions={ false }
onChange={ ( { url } ) => {
onSelectURL( url );
editMediaButtonRef.current.focus();
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
} }
/>
</form>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/post-template/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
},
"__experimentalDefaultControls": {
"blockGap": true,
"padding" : false,
"margin" : false
"padding": false,
"margin": false
}
},
"interactivity": {
Expand Down
Loading