#60548 closed defect (bug) (fixed)
Image editor: improve the browsePopup function
Reported by: | afercia | Owned by: | joedolson |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 6.3 |
Component: | Media | Keywords: | has-screenshots has-patch has-testing-info commit |
Focuses: | accessibility, javascript | Cc: |
Description
While auditing all the remaining jQuery deprecations still to address in core, I noticed a couple things that offer room for improvements in the browsePopup
function of the core image editor.
- The
browsePopup
function uses thewindow.event
property, which is deprecated and should not be used. This is theglobal
event. Instead, the event should be passed as a function parameter. Aside: instead of using inline events, it could have been better to consider a more modern approach. - When using the keyboard to navigate the items in the 'Image rotation' dropdown menu, the page scrolls. See attached animated GIF. There's some code in place to prevent page scrolling you may need to reduce your viewport height.
Attachments (3)
Change History (24)
#2
@
8 months ago
Adjusting the event handling from onkeyup to onkeydown and passing the event object (event) as a parameter to the browsePopup function should help resolve the issues right?
Using onkeydown would indeed prevent the page from scrolling down as well.
For example inside image-edit.php if we change the following
<button type="button" class="imgedit-rleft button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90° left' ); ?></button>
to
<button type="button" class="imgedit-rleft button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90° left' ); ?></button>
similarly for all the buttons should help.
Also browsePopup could receive the event attribute like below
browsePopup: function (event, el) { ...
Also, we won't have to worry about depending on the global window.event
.
I did test this out on my local environment and seems to be working fine.
#3
@
8 months ago
Adjusting the event handling from onkeyup to onkeydown and passing the event object (event) as a parameter to the browsePopup function should help resolve the issues right?
yes, either that or we would need to add a keydown
event for the only purpose to prevent scrolling. It depends whether keeping the interaction with the menu on keyup
is desired or not. I'd defer to @joedolson for a decision about the preferred interaction.
#4
@
8 months ago
- Owner set to joedolson
- Status changed from new to accepted
Re: "Aside: instead of using inline events, it could have been better to consider a more modern approach. "
I didn't see any reason to have everything else in inline events with just this event being executed differently from the rest of the image editor, nor did I see it as worthwhile to refactor the entire image editor. So, I pretty much stand by that approach in this case, even though it's far from ideal.
This ticket was mentioned in Slack in #core-media by joedolson. View the logs.
7 months ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 months ago
This ticket was mentioned in Slack in #accessibility by rcreators. View the logs.
4 months ago
#9
@
4 months ago
I haven't seen any PR raised for this issue. If it is still valid, shall I raise a PR for the fix?
cc: @afercia @joedolson
This ticket was mentioned in Slack in #accessibility by sabernhardt. View the logs.
4 months ago
This ticket was mentioned in PR #6856 on WordPress/wordpress-develop by @nirajgirixd.
4 months ago
#13
- Keywords has-patch added; needs-patch removed
## Description
This PR addresses the scrolling issue encountered when using the keyboard to navigate different options in the image editor.
## Changes Made
- Replaced
onkeyup
event withonkeydown
event.
## Why?
When using the keyboard to navigate the items in the 'Image rotation' dropdown menu, the page scrolls.
## Screencast
https://github.com/WordPress/wordpress-develop/assets/51747980/fe1f8e04-0a3d-462a-8d10-00ca4ecdaae7
---
## Trac ticket: https://core.trac.wordpress.org/ticket/60548
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
8 weeks ago
#15
@
6 weeks ago
- Keywords needs-testing added
The updated patch incorporates the changes suggested by @afercia and @deepakvijayan for passing events and updating formatting.
Tested, works as expected for me: marking as needs testing.
Testing instructions:
Navigate to the media and edit an image.
Navigate the 'Image Rotation' menu using the tab
and arrow keys. Observe that there is no unexpected shift of viewport position while browsing.
This ticket was mentioned in Slack in #core-media by joedolson. View the logs.
6 weeks ago
#18
@
6 weeks ago
- Keywords commit added; needs-testing removed
This is working good in my testing. Validated the before and after scroll event viewport behavior. Code looks good. Let's ship it :)
This ticket was mentioned in PR #7262 on WordPress/wordpress-develop by @joedolson.
6 weeks ago
#19
Trac ticket: https://core.trac.wordpress.org/ticket/60548
@joedolson commented on PR #7262:
6 weeks ago
#21
In r58946
Some more details:
event
used here, here, and here is the gloablwindow.event
, which is deprecated.preventDefault()
used here doesn't actually prevent the page scrolling default action because the event in use iskeyup
which fires when a key is released. At that point the page scroll already occurred when pressing the key.$target
variable as that's not a jQuery object wrapping a DOM object. It is eitherfalse
or the value returned by jQueryget()
which is the DOM object. Traditionally, the core JavaScript prefixes variable names with$
as a convention for jQuery objects while this is a 'native' DOM object.