-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -23,7 +23,7 @@ | |||
|
|||
.components-dropdown { | |||
display: block; | |||
height: 36px; | |||
height: fit-content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these height rules be removed entirely?
height: fit-content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: gutenberg/packages/block-editor/src/components/background-image-control/style.scss Line 27 in e3df6a0
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.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height: 36px; | |
height: 40px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @mirka. I've updated the height in the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: juanfra <[email protected]>
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 Button
was updated tocompact
, whose styles are applied using theis-compact
classname.The
is-compact
classname contains a height of32px
as 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-dropdown
applied to its parent, is actually36px
leading 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-dropdown
to now usefit-content
instead 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.scss
Testing Instructions
Screenshots