Make WordPress Core

Opened 11 months ago

Closed 4 months ago

Last modified 3 months ago

#63238 closed defect (bug) (fixed)

Remove `target="_blank"` from Browser Uploader Link

Reported by: dilipbheda's profile dilipbheda Owned by: joedolson's profile joedolson
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch has-screenshots target-blank commit
Focuses: accessibility, administration Cc:

Description

While visiting the wp-admin/media-new.php page, I noticed that the Browser Uploader link included an unnecessary target="_blank" attribute.

Reason for Removal:

The Browser Uploader link does not navigate to a new page, it simply toggles the browser uploader section dynamically without reloading the page. Therefore, the target="_blank" attribute is redundant and should be removed.

Attachments (3)

Screenshot-from-2025-04-04-21-36-28-04-04-2025_09_37_PM.png (237.6 KB) - added by dilipbheda 11 months ago.
63238.button-role.diff (1.8 KB) - added by sabernhardt 4 months ago.
adds role="button" plus spacebar usability, while keeping the existing strings
63238.button-element.diff (2.5 KB) - added by sabernhardt 4 months ago.
replaces links with buttons and updates elements in script

Download all attachments as: .zip

Change History (21)

This ticket was mentioned in PR #8654 on WordPress/wordpress-develop by @dilipbheda.


11 months ago
#1

#2 @sabernhardt
9 months ago

  • Keywords target-blank added

Yes, the browser uploader link apparently stays on the same page, behaving more like a button, unless you purposely open it in a new tab (with Ctrl+click or similar).

For the patch, I would prefer to keep the translatable string as it is, replacing target="_blank" with an empty string. Then translators would not need to update anything, and the current string would still be available in case a future change requires additional attributes.

printf(
	/* translators: 1: URL to browser uploader, 2: Additional link attributes. */
	__( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" %2$s>browser uploader</a> instead.' ),
	$browser_uploader,
	''
);

However, if changing the string is important, it would only have one %s placeholder:

printf(
	/* translators: %s: URL to browser uploader. */
	__( 'You are using the multi-file uploader. Problems? Try the <a href="%s">browser uploader</a> instead.' ),
	$browser_uploader
);

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


7 months ago

#4 @joedolson
7 months ago

  • Milestone changed from Awaiting Review to 6.9
  • Owner set to joedolson
  • Status changed from new to accepted

Good catch, @dilipbheda!

I'm thinking that we should also semantically change this to a button. To keep things simple, we might want to just add role="button" and add the extra key handler to the events to support spacebar triggering.

That would also continue to allow users to open in a new tab if they are accustomed to doing that, though I wonder how often that actually happens...

#5 @rollybueno
6 months ago

  • Summary changed from Removed `target="_blank"` from Browser Uploader Link to Remove `target="_blank"` from Browser Uploader Link

Honestly, I think adding role="button" still creates semantic mismatch and another accessibility issue. Since this is toggling the uploader in same page, why not just using real <button> instead?

Last edited 6 months ago by rollybueno (previous) (diff)

#6 @joedolson
5 months ago

The reason for not using a real button is the possibility that users are accustomed to being able to open this in a new window.

The only question is whether anybody actually *does* that. There isn't really any sound reason for going to a new window to open the other uploader.

I'm somewhat inclined to simply change this to a button, and see whether anybody complains about the change. If so, it would be easy enough to switch to using role="button", instead.

@sabernhardt
4 months ago

adds role="button" plus spacebar usability, while keeping the existing strings

@sabernhardt
4 months ago

replaces links with buttons and updates elements in script

#7 @sabernhardt
4 months ago

If one switcher link has the button role or becomes a <button> element, the counterpart link with href="#" ought to have the same change.

I think I still prefer keeping the existing strings, but 63238.button-role.diff probably would need further editing.

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


4 months ago

#9 @joedolson
4 months ago

I think I'd rather change the translatable string that depend on manipulating the outcome of a translation. The role="button" patch would break with a simple error in the translated string that modified a href="#". While that's improbable, I think that the string change would be better.

#10 @sabernhardt
4 months ago

Well, changing the element with 63238.button-element.diff should be easier for us. I think the script in 63238.button-role.diff could need editing to work with the spacebar in all browsers, and it would require more testing.

However, the role option should be more backward-compatible.

  • It would keep the well-established strings (see both strings, with their translations). Of course, untranslated admin strings are less of a problem than user-facing strings, and these might be labeled as 'fuzzy'.
  • All of the href="#" string's translations include <a href="#"> today, but if that changes, it would fall back to link semantics and should continue to behave as it does now.
  • If someone had a reason to create a custom replacement of 'plupload-handlers', then it should still function when people click the link or use the Enter key (without needing to update the element name in their script). Most plugins in the directory search results enqueue 'plupload-handlers' on its own or as a dependency. Gmedia Photo Gallery is the only plugin I found to dequeue it and enqueue another script, but that plugin apparently does not affect these switcher links within the core media library.
  • If some people actually have a desire to open the one link in a new tab, the role would continue to allow that.

This ticket was mentioned in Slack in #accessibility by shovan_bhattacharjee. View the logs.


4 months ago

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


4 months ago

This ticket was mentioned in PR #10429 on WordPress/wordpress-develop by @joedolson.


4 months ago
#13

Removes some additional unused code from previous patch.

Trac ticket: https://core.trac.wordpress.org/ticket/63238

#14 @joedolson
4 months ago

Added a PR to update 63238.button-element.diff. The only change is that it also removes the now un-used variables from media_upload_flash_bypass().

#15 @joedolson
4 months ago

In testing, I observed that there was a focus loss when changing uploaders, so I also added focus assignment after switching.

@sabernhardt Can you give this a check? I've tested everything and it's working, but would appreciate a 2nd opinion.

#16 @joedolson
4 months ago

  • Keywords commit added

#17 @joedolson
4 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 61099:

Media: A11y: Switch uploader toggle to button and set focus.

The control to switch between the browser uploader and the default uploader used a link with target="_blank", but was driven by scripts. In a no-js context, this meant that the link could be used to open the browser uploader in a new tab. This is unnecessary, however, because the default uploader is not rendered when JS is not available.

On switching uploaders, browser focus was lost.

For more predictable keyboard and screen reader behavior, switch the media uploader toggle to a button element and set focus to the upload button in the new context.

Props dilipbheda, sabernhardt, rollybueno, westonruter, joedolson.
Fixes #63238.

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


3 months ago

Note: See TracTickets for help on using tickets.