-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ImageSizeControls: Replace ButtonGroup with ToggleGroupControl #65386
base: trunk
Are you sure you want to change the base?
Conversation
…l and ToggleGroupControlOption
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. |
} | ||
value={ addSelectedScaleValue() } | ||
isBlock | ||
isDeselectable |
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.
If we remove the isDeselectable
prop, keyboard users won't be able to set a custom value:
71dcd41756d30d74f869d014456c5284.mp4
As I commented here too, we might need to add an option called "Custom".
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.
keyboard users won't be able to set a custom value
This isn't inherently true — it's only because the logic of addSelectedScaleValue
doesn't account for it. In fact the current logic sets invalid values on the ToggleGroupControl, when it should be set back to undefined
instead. (cc @hbhalodia)
For the sake of this PR, I'm ok with just replicating the existing functionality. And as it turns out, the Reset button doesn't actually reset, it just sets it to 100%, which is different from an actual reset. So to actually reset, the user needs to clear the width/height input fields. I think that means we don't even need a Reset button nor a "Custom" option to replicate the existing functionality.
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 @mirka, If I had read it correct, need to update the logic on addSelectedScaleValue()
function should return undefined
, when we set custom values? is that something need to changed.
Thank You,
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.
it's only because the logic of addSelectedScaleValue doesn't account for it. In fact the current logic sets invalid values on the ToggleGroupControl, when it should be set back to undefined instead.
Hi @mirka, I tried to set directly undefined on that logic, seems like anyhow keyboard user would ultimately land on the first option of the ToggleGroupControl
, which ultimately sets the first option even we have undefined set on that logic.
Can you please let me know how to set it undefined for keyboard users on that logic, because ultimately when user lands on the toggleGroupControl
it would call handleUpdateDimension()
which ultimately sets the dimension based on the scale size, and it would remove the custom dimension set.
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.
After investigating this issue, I found that when the ToggleGroupControl
component is focused, onChange
fires and the value that actually exists in the options is referenced. This may be one of the causes of the unintended behavior.
I thought that the side effects of the useDimensionHandler
hook might be affecting it, but deleting useEffect did not solve the problem. Therefore, I still don't know what is causing the unintended onChange event 🤔
Please refer to the verification video below:
51d9a31d054528b23dc9fdd3fdcb3559.mp4
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 looked into this, and I think it's a bug in ToggleGroupControl 😭 Sorry. Just a moment while I address this at the root.
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.
Fix proposed in #66151
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, @mirka for getting the bug fixed.
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.
Fix is merged. Thank you for your patience!
packages/block-editor/src/components/image-size-control/index.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/image-size-control/index.js
Outdated
Show resolved
Hide resolved
const addSelectedScaleValue = () => { | ||
const scaleSize = Math.round( currentWidth * ( 100 / imageWidth ) ); | ||
|
||
if ( IMAGE_SIZE_PRESETS.includes( scaleSize ) ) { | ||
return scaleSize; | ||
} | ||
|
||
return undefined; | ||
}; |
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 think we need to follow the original logic and check that not only the width but also the height matches.
We should be able to determine this as follows:
const selectedValue = IMAGE_SIZE_PRESETS.find( ( scale ) => {
const scaledWidth = Math.round( imageWidth * ( scale / 100 ) );
const scaledHeight = Math.round( imageHeight * ( scale / 100 ) );
return currentWidth === scaledWidth && currentHeight === scaledHeight;
} );
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 @t-hamano, For the updated logic, I would add this logic and would wait for ToggleGroupControl
bug to be fixed 🤞.
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.
Update: The logic has been updated and waiting for the ToggleGroupControl fix to be land.
Thank You,
What?
PR replaces the
ButtonGroup
component withToggleGroupControl
in the ImageSizeControls.Why?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast