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

[Gradient Tool]: Fix closing of popover when the angle control is clicked #40735

Merged
Merged
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 @@ -28,12 +28,11 @@ function AngleCircle( { value, onChange, ...props } ) {

const changeAngleToPosition = ( event ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this is the handler for onDragMove and onDragEnd (in addition to being called by onDragStart) so it's executing event.target.focus() way more than necessary. Perhaps even the old blur() would work if it were only called from onDragStart. Not that I'm suggesting that blur() should be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! I didn't notice any performance penalty in my testing, but I suppose we could add a check before calling .focus() to only do that if the element isn't already focused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely agree here. I noticed this as well that these events are tied together in a bit weird fashion. I'll land this as is to fix the issue for now, and we need to check how to separate/handle the drag events better.

const { x: centerX, y: centerY } = angleCircleCenter.current;
const { ownerDocument } = angleCircleRef.current;
// Prevent (drag) mouse events from selecting and accidentally
// triggering actions from other elements.
event.preventDefault();
// Ensure the input isn't focused as preventDefault would leave it.
ownerDocument.activeElement.blur();
// Input control needs to lose focus and by preventDefault above, it doesn't.
event.target.focus();
onChange( getAngle( centerX, centerY, event.clientX, event.clientY ) );
};

Expand Down Expand Up @@ -72,6 +71,7 @@ function AngleCircle( { value, onChange, ...props } ) {
value ? { transform: `rotate(${ value }deg)` } : undefined
}
className="components-angle-picker-control__angle-circle-indicator-wrapper"
tabIndex={ -1 }
>
<CircleIndicator className="components-angle-picker-control__angle-circle-indicator" />
</CircleIndicatorWrapper>
Expand Down