Media Replace Flow: Add custom toggle support and fix button height#68084
Conversation
…te BackgroundImageControls to specify button variant
…and remove unused default variant
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mirka
left a comment
There was a problem hiding this comment.
This is good, and I think we can future-proof it even further by exposing the entire renderToggle as an optional prop, rather than try to abstract it with buttonVariant. My concern with an abstract approach like buttonVariant is that we'll need to alter the API every time we need something slightly different, like an icon button or another Button variant.
So for example in BackgroundImageControls I want to be able to do something like:
<MediaReplaceFlow
renderToggle={ ( props ) => (
<Button
{ ...props }
__next40pxDefaultSize
/>
) }What do you think? (cc @WordPress/gutenberg-components)
Also as a separate issue, I noticed that the focus manipulation that editMediaButtonRef is being used to do is not relevant/appropriate anymore in these recent implementations. I'm looking at the original commit where that focus manipulation was added, and it seems like it was for focus restoration, which doesn't apply anymore (cc @draganescu in case I'm wrong). We could maybe clean that up as well.
| .components-dropdown { | ||
| display: block; | ||
| height: 36px; | ||
| height: fit-content; |
There was a problem hiding this comment.
Can these height rules be removed entirely?
| height: fit-content; |
There was a problem hiding this comment.
Thanks for the review @mirka.
Yes, we can indeed remove the height rules. I've removed them in the latest commit. Here's a screenshot of the component after recent changes:
It's working as expected on my end.
This is good, and I think we can future-proof it even further by exposing the entire renderToggle as an optional prop, rather than try to abstract it with buttonVariant.
Great Point! I'll work on incorporating this, will update here once done.
…on rendering and support custom toggle rendering
|
As per the suggestions provided by @mirka, the following are the changes made in the recent commit:
Here's a screencast post recent changes: The changes seem to work as expected on my end. |
| aria-haspopup="true" | ||
| onClick={ onToggle } | ||
| onKeyDown={ ( event ) => { | ||
| if ( event.keyCode === DOWN ) { |
There was a problem hiding this comment.
I know we've been doing it like that in other places, but event.keyCode is deprecated. You might want to use:
| if ( event.keyCode === DOWN ) { | |
| if ( event.key === 'ArrowDown' ) { |
There was a problem hiding this comment.
Hi @tyxla, thanks for the review. I've incorporated the suggested changes in the latest commit.
| aria-expanded={ isOpen } | ||
| aria-haspopup="true" | ||
| onClick={ onToggle } | ||
| onKeyDown={ openOnArrowDown } |
There was a problem hiding this comment.
I wonder if we should pass down these as default props for the media flow render toggle. This way, consumers don't have to re-implement a11y best practices.
There was a problem hiding this comment.
Exactly, that is what I had in mind with this usage example. We can assume (and document) that the renderToggle function should accept and pass through button props to an eventual button element.
@yogeshbhutkar Let me know if you're unsure what to do here, I'd be happy to push up some proposed code.
There was a problem hiding this comment.
@mirka, yeah, reread your example after I commented and noticed it 😅
| aria-expanded={ isOpen } | ||
| aria-haspopup="true" | ||
| onClick={ onToggle } | ||
| onKeyDown={ openOnArrowDown } |
There was a problem hiding this comment.
Exactly, that is what I had in mind with this usage example. We can assume (and document) that the renderToggle function should accept and pass through button props to an eventual button element.
@yogeshbhutkar Let me know if you're unsure what to do here, I'd be happy to push up some proposed code.
| name={ | ||
| <InspectorImagePreviewItem | ||
| className="block-editor-global-styles-background-panel__image-preview" | ||
| imgUrl={ url } | ||
| filename={ title } | ||
| label={ imgLabel } | ||
| /> |
There was a problem hiding this comment.
Because name is a standard prop of MediaReplaceFlow, I think it would be safer to continue using this prop rather than rendering it directly into our renderToggle.
One risk I'm thinking about is that the MediaReplaceFlow implementation could change some day to use the name prop in another place as well.
|
While implementing the suggested changes, I found that entirely removing this CSS rule changes the height of the Image Preview component. Instead of completely removing it, the following rule will fix the issue:
Also, it looks like there were some missed lints in the JSON file that previously got committed to the latest trunk The Finally, this comment clarified the suggested approach further. So, I've updated the renderToggle implementation to accept button props, which must be passed to the button component. I've also documented this change. If you feel this is not the best approach, I can refer to a small code example. Here's a screencast after the suggested changes: Thanks a lot to the reviewers for these constant follow-ups ✨. |
There was a problem hiding this comment.
Are changes in this file still necessary?
mirka
left a comment
There was a problem hiding this comment.
API changes look great, thank you! I think we're good to go once the height value is fixed.
| height: 36px; | ||
|
|
||
| .block-editor-global-styles-background-panel__dropdown-toggle { | ||
| height: 36px; |
There was a problem hiding this comment.
| height: 36px; | |
| height: 40px; |
There was a problem hiding this comment.
Thanks for the review @mirka. I've updated the height in the latest commit.
mirka
left a comment
There was a problem hiding this comment.
Thanks for all the follow-ups! 🚀
…ordPress#68084) * Update background image control dropdown height to fit-content * Replace ToolbarButton with Button in MediaReplaceFlow component * Refactor MediaReplaceFlow to support dynamic button variants and update BackgroundImageControls to specify button variant * Refactor MediaReplaceFlow to set default button variant to 'toolbar' and remove unused default variant * Remove redundant height property from background image control dropdown styles * Refactor BackgroundImageControls and MediaReplaceFlow to improve button rendering and support custom toggle rendering * Remove unnecessary blank line in MediaReplaceFlow component * Update BackgroundImageControls to use 'ArrowDown' key for dropdown navigation * Media Replace Flow: Add custom toggle support and fix button height * added `renderToggle` prop details to readme * refactor: remove unused styles * style: increase dropdown toggle height to 40px Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: juanfra <juanfra@git.wordpress.org>
…ordPress#68084) * Update background image control dropdown height to fit-content * Replace ToolbarButton with Button in MediaReplaceFlow component * Refactor MediaReplaceFlow to support dynamic button variants and update BackgroundImageControls to specify button variant * Refactor MediaReplaceFlow to set default button variant to 'toolbar' and remove unused default variant * Remove redundant height property from background image control dropdown styles * Refactor BackgroundImageControls and MediaReplaceFlow to improve button rendering and support custom toggle rendering * Remove unnecessary blank line in MediaReplaceFlow component * Update BackgroundImageControls to use 'ArrowDown' key for dropdown navigation * Media Replace Flow: Add custom toggle support and fix button height * added `renderToggle` prop details to readme * refactor: remove unused styles * style: increase dropdown toggle height to 40px Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: juanfra <juanfra@git.wordpress.org>






Fixes: #68029
What?
This PR contains a patch for fixing spacing inconsistency in the background image selector button.
How?
As the issue description mentions, the default size of
Toolbar Buttonwas updated tocompact, whose styles are applied using theis-compactclassname.The
is-compactclassname contains a height of32pxas mentioned here:gutenberg/packages/components/src/button/style.scss
Line 298 in 581de9f
gutenberg/packages/base-styles/_variables.scss
Line 99 in 581de9f
Whereas, the heights described in
.components-dropdownapplied to its parent, is actually36pxleading to a mismatch in the parent container and child's heights.gutenberg/packages/block-editor/src/components/background-image-control/style.scss
Line 26 in 581de9f
gutenberg/packages/block-editor/src/components/background-image-control/style.scss
Line 47 in 581de9f
To fix the issue, the heights are updated inside
.components-dropdownto now usefit-contentinstead of using the previously hardcoded value36px.As an alternative, we can also hardcode the height to
32px.File Changed:
> packages/block-editor/src/components/background-image-control/style.scssTesting Instructions
Screenshots