Problem/Motivation
Spin-off from #2988431: [Meta] Accessibility plan for Media Library Widget:
The grid view contains a link you can't click.
Currently, when using the media library widget, the grid display of the media item contains a link to the canonical URL of the media item. This is the case for:
- The grid display in the media library view.
- The previews of the media items when you have selected them in the widget.
- The 'Additional selected media' element shown below the added items (from #3023797: Let users choose what to do after selecting and/or adding items in the media library).
This currently has 2 issues:
- Media does not necessarily have a canonical route, see #3017935: Media items should not be available at /media/{id} to users with 'view media' permission by default
- For at least the links in the modal, we don't want them to be active because they take the user away from their current task, without being able to go back. This has been "solved" by adding
pointer-events:noneon and a click handler, but users can still tab to the link.
Proposed resolution
I don't think we really need this link. Let's just remove it.
Turns out we used the link for the admin/content/media overview to link to the edit page. Since the media view modes are shared between the admin/content/medias overview and the media library widget, some hacks are in place to prevent users from navigating away from the widget.
The proposed resolution is:
- Remove the link from the view mode.
- Add a new edit link to the page display of the media library view (used for admin/content/media) so users can still edit media.
- Add a new delete link to the page display as well. This could be done in a separate issue, but doing it here might make it easier to review and minimizes the number of update hooks touching the existing views of users.
Remaining tasks
Write patchWrite update hook testCode reviewA11Y reviewUX ReviewFrontend review- Commit
User interface changes
Remove the link from the grid display of media items in the media library widget.
- Current HTML

- Current tabbability
- As you can see, we can still tab to it, despite
pointer-events: none;:

- UI before

- Updated UI

API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #62 | 3039829-62.patch | 65.48 KB | alexpott |
| #62 | 61-62-interdiff.txt | 2.19 KB | alexpott |
| #61 | 3039829-61.patch | 65.67 KB | alexpott |
| #61 | 56-61-interdiff.txt | 1.06 KB | alexpott |
| #58 | 3039829-58.png | 175.54 KB | phenaproxima |
Comments
Comment #2
mgiffordCan you include a screenshot of the problem? Maybe even of the desired state too?
Comment #3
wim leersThis has tripped me up many times.
#2: Screenshots added. The desired state is simple: remove the
<a>, but keep the text wrapped by the<a>.Comment #4
seanbCorrect! The view mode is also being used on the media overview on admin/content/media though. We still need to agree on the best way to solve this, or at least need UX approval on whether it is ok to just remove the link.
Comment #5
phenaproximaI think Wim pretty much nailed it.
Comment #6
wim leersOh, I hadn’t considered #4! That is a very good point. I think in that case the entire thumbnail could be made into a link?
Comment #7
andrewmacpherson commentedAs well as the CSS
pointer-events: none, there is a JS keypress listener which tries to "fix" this for by presenting a confirmation dialog. Can we clean that up at the same time?There's another side to this which is that we expand the size of the link when it has focus, to avoid truncating the media label. I don't recall how we did this in the end, but it needn't require
a:focus. We can expand the media label with a focusin/focusout behaviour on the media item wrapper.There are some other problem links too. The table view has links in the author column which are also unnecessary (they take you away from the dialog). That could be changed to a plain text author name.
Comment #8
wim leers+1 — because those are partial work-arounds for the same problem.
Let's not to do those in this issue. One problem at a time, so that we can get improvements committed without getting stuck :)
Comment #9
geaseRemoved a link from all displays and added an edit link to page admin display.
Comment #10
wim leersThanks, @gease!
Comment #11
wim leersComment #12
seanbThis is a great first start. Thanks!
As discussed with gease this needs some input from a design/UX perspective on how to place and style the edit link.
Besides that we probably needs an update path to also update the view in existing sites and have some tests to assert the link is gone.
Comment #13
geaseAdded some tests.
Comment #14
seanbWe are removing the link in the view mode, which means we have to add a separate edit link for the view display for /admin/content/media.
We have discussed this in the UX call. The screenshots below visualise what this could look like.
Before / current:

Only a edit link:

Edit link and delete button:

Another thought, the view on admin/content/media-table also includes a delete link for each item. I think it might be good to also add the delete link. I know it's a bit of a scope creep, but since we need to have an update hook and tests to update the view, it might be efficient to add the edit and delete button in 1 issue to minimise the updates on the view configuration.
Comment #15
phenaproximaTransferring credit for @mcannon, myself, @HeikkiY, and @lauriii from #3041111: Items selected from the media library cannot be reordered by weight, which I'm closing as a duplicate. We should copy the tests from that issue into this one, since it adds some valuable coverage.
Comment #19
phenaproximaComment #20
phenaproximaKicking back to "needs work" for tests to be copied from #3041111: Items selected from the media library cannot be reordered by weight.
Comment #21
geaseFinished restyling "edit" link and hook_update_N() without still considering comment #15.
Comment #22
phenaproximaLet's see how the tests feel...
Comment #23
geaseAdded tests from #3041111: Items selected from the media library cannot be reordered by weight (comments #6 & #12).
Comment #24
geaseAdded "delete media" icon to media library page. Unless some community review fails, nothing more I can add here.
Comment #25
geaseComparison of current 8.8.x media library items on content admin page without and with patch:


Comment #26
seanbThanks @gease. This is coming along really nice! This looks like a huge improvement to me.
Some feedback on the patch. The feedback in #7 also does not seem to be addressed.
We should probably override the field classes instead of providing an empty div.
I think we need a textual fallback for the links (for a11y purposes).
Are we sure this is always 44px?
Why do we need this?
Do we still need this? It seemed to be specific for the link styles.
I know it already sucked a bit, but with the new additions I hope we can find a better way to write this :(
Can we removed
.views-field-edit-media?I think we need to be a bit more specific. When a user has changed the media_library view on an existing site this would override their changes. We probably need to make sure we only make additions.
We should also have a test for this.
Can we have an extra test for the delete link as well?
I don't think we need this line here.
I think we can do:
$assert_session->elementNotExists('css', '.media-library-item__name a');The name should never have an anchor in it if I'm not mistaken.
Can we have explicit tests for the widget that there are no links to edit/delete media from the media library? This could be done in a separate issue, but since the solution we chose here is chosen partly to make sure the edit/delete link are NOT in the media library widget, it might be good to assert that.
Comment #27
geaseThanks @seanB for the thorough review.
I'll go step by step:
Comment #7 has three distinct notes.
I am planning to cleanup js with the issue #3062375: Media library item loses focus when hovering over item's title.
It's expanded on hover over container.
This should be a separate ticket, if at all.
Comment #28
rosinegrean commentedComment #29
geaseIf we just override the class, the icon won't be a link. I think I've taken the most transparent way (that is, with the least amount of code and overrides).
You are correct, I thought about this (after posting the last patch). Will do it.
All the margins, offsets, sizes for those icons are given in pixels. And I see no breakpoints or anything. So yes, we are sure.
Good question. I turned it off and see no regression. And for sure don't remember clearly why I've put it there. I can guess that before restyling "edit" and "delete" links it prevented clicking them. I can remove it now.
No, it's for the title. It's part of "show full title on hover" functionality.
Basically, I see no reason for putting all kinds of pseudo-selectors, but I kept it as it was, assuming it was done for some reason.
No, because we have media widget and media page, and edit button is positioned differently in those cases.
Comment #30
geaseAgree about the test, will add check that there is an edit and delete links on media page. What concerns the view, I'm overriding just the fields of the display concerned. Of course, we can be more granular and just add "edit" and "delete", but chances are this will mess up users' overrides. Overall I don't think it's a best practice to override third-party views.
Btw, the test for "edit" is there. So just the same for "delete" to be added.
To make sure we are in grid view. If you think this is superfluous, I'll remove it.
At least, this sounds quite logical. I'll try.
Ok, I will add these. There is a "remove" button on a widget, but it's an input element, so no problem.
Comment #31
geaseNew patch as per above comments.
pointer-events: none;comes from #3041111: Items selected from the media library cannot be reordered by weight, items weights are not clickable.
Comment #32
lauriiiComment #33
lauriiiOops, referenced to wrong issue.
Comment #34
seanbAttached is a new patch with some code changes:
Only thing I believe we are still missing is a test for the update hook.
After that, we need to demo this to the UX team and get a11y and frontend maintainer signoff since we made some pretty significant UX/frontend changes.
Comment #35
seanbUpdated IS and screenshots.
UI before:

Updated UI:

Comment #37
seanbWe showed a demo of this issue today in the UX meeting (you can watch that here https://www.youtube.com/watch?v=aipwkFhZDms). We also had a11y people present. The general consensus was that everyone liked the approach and implementation. The following non-blocking comment were made, we need to have followups for that:
As mentioned, these things need followups. I will however remove the a11y and UX review tags.
What is left for this issue:
Comment #38
phenaproximaFollow-ups filed:
#3064586: [PP-1] Improve checkbox styling in the administrative media library
#3064587: Improve positioning of publishing status label for media items in the administrative media library
#3064589: [PP-1] Improve focus styles for items in the administrative media library
Comment #39
seanbFixed code style issues and added update test.
Comment #40
phenaproximaThis is really close to ready, and a huge win.
It looks like we have only added things to this view, and not removed anything. I thought we'd be removing some stuff too?
Have we properly dealt with the referenced issue? (i.e., is it closed or triaged correctly in relation to this one?)
This could use a comment.
Why are we adding pointer-events: none here?
What is meant by "a lot of selectors buttons"? Also, "heave" should be "heavy" :)
Should this maybe be a post-update hook, so we can take advantage of the Views and entity APIs?
$view will always be truthy, even if the view has been deleted. We should check
if (!$view->isNew()).s/exist/exists
Nit: These calls can be changed.
Do we, by any chance, have an existing update path test we could merge this into?
This should be $assert_session->elementExists()->click(), to prevent potential method calls on NULL.
Comment #41
lauriiiThis should document that this is for LTR.
Maybe we should open a follow-up against Views UI for this.
This should be marked as LTR.
Where can I test this version of the element where the element has .button? Could we remove the .button class from the element to simplify this?
This should be marked as LTR.
This should be marked as LTR.
Comment #42
phenaproximaThis may be somewhat relevant: #2998005-51: [PP-1] Support Drupal core's Media Library.
Comment #43
wim leers#35: That screenshot looks great! This is part of the work that #3023807-12: Override media fields from the reference field proposed 👍
I'm also building on top of this in #2998005-51: [PP-1] Support Drupal core's Media Library, which @phenaproxima cross-posted with me 🤓
Comment #44
seanbFixed the tests.
#40
1. We removed the link in the template.
2. The referenced issue #2985168: [PP-1] Allow media items to be edited in a modal when using the field widget is already closed as won't fix. Actually removing the edit link should be the end of it. So I think we are good.
3. Fixed.
4. To fix #3041111: Items selected from the media library cannot be reordered by weight
5. Fixed.
6. Not sure, we have done this in regular update hooks before so I thought it would be good to stick with the same pattern.
7. Nice catch, thanks.
8. Fixed.
9. Fixed.
10. Technically we could merge it into any existing update path test, but since those fixtures would be older the test would not just the test the new update hook. In the past we tried merge update path tests but I was lead to believe having a separate test for each update hook was the way to go. I personally have no strong preference, but if we can merge update tests we probably need to refactor existing update tests as well (in a follow up).
11. This exact line is in the MediaLibraryTest test 11 times. So fixed all occurrences.
#41
1. This has been discussed in the UX meeting twice, but the general consensus seemed to be that these links needed to be directly visible instead of hidden behind a contextual link button or in a dropbutton. Not sure what/where to document?
2. Fixed.
3. The views code below was added to views in 2009. Never noticed this issue before though. Added #3064914: Views preview adds margin top to views rows to see if this can be removed.
4. Fixed.
5. Fixed. The media library widget (when adding a media field to a node for example) contains a delete button when you have selected media from the library. Since this is a form submit, it automatically gets the button class from core. We could remove the extra styles for the .media-library-item__edit since we don't have an edit button in the widget yet. This will probably be added in #3023807: Override media fields from the reference field, but we will see about that when we get there I guess.
6. Fixed.
7. Fixed.
Comment #45
phenaproximaPatch no longer applies. I think it needs a reroll :)
Comment #46
seanbRerolled #44.
Comment #47
phenaproximaI gave this a quick manual test. I installed Drupal from HEAD, then enabled Media Library. I then applied the patch and ran the database update, which went flawlessly. Then I logged in as admin and went to /admin/content/media, added a couple of media items, then navigated into them with the keyboard (which worked great!) and the mouse (which also worked great!). I was able to select them, edit them, and delete them without any issue.
It also worked admirably on a clean install. I think this is done.
Comment #48
chr.fritschFor updating some config in an update hook, we usually use the ConfigEntityUpdater. For example, see block_content_post_update_add_views_reusable_filter()
I think we should do that here as well.
Comment #49
phenaproximaI don't know if that's necessary here, since we're only modifying a single config entity, and we're doing it using the low-level config system...
Comment #50
phenaproximaMinor IS update.
Comment #51
lauriii#44.1 I think having it in this issue is enough (at least now it's somewhere).
#44.5 Can we open follow-up to figure out if it would be possible to remove the automatically added classes?
It seems like the field widget remove button has some issues with the positioning of the cross:

Chrome:
Firefox:

Other than that the frontend changes look good to me.
Comment #52
starshapedI just tried reproducing the cross alignment issues from #51, and I'm not able to reproduce it. I took this screenshot on a Retina Macbook Pro; Chrome 75.0.3770.100 on the left and Firefox 67.0.3 on the right.
Comment #53
phenaproximaSo...I am reproducing this problem on a non-Retina MacBook Air. However, the weird thing is that the problem disappears if I zoom in; only at the default zoom level do I see it. Here's a screenshot; Chrome is on the left, Firefox on the right.
Comment #54
phenaproximaThis is a weird problem. Fiddling with it in the web inspector, I discovered that, on my machine at least, changing the background-size of the X to 14px solves the problem. Screenshot attached; Chrome on the left, Firefox on the right.
Comment #55
lauriiiIt seems to be some kind of rounding issue. Changing the background size changes the size of the icon, so we probably should increase the size of the button as well to keep the design consistent. If that doesn't work, there are some other, more complex workarounds we could look into.
Edit: another solution would be to just change the size of the button, without changing the background size. For example, increasing the size by 1px seems very minor change to the design, and fixes the rounding issue on 100% zoom.
Comment #56
starshapedIncreased the button size, and now the X looks good in both Firefox and Chrome.
Comment #57
phenaproximaLooks good to me; thanks @starshaped!!
Comment #58
phenaproximaI filed #3065431: Allow buttons to opt out of getting the 'button' class to handle the
buttonclass snafu.I also look another quick look at the changes from @starshaped. Looks great in both Chrome and Firefox at 100% zoom:
I think we're done here. Green once testbot catches up.
Comment #59
phenaproximaComment #60
wim leersWhew, I didn't expect cross-browser CSS issues to suddenly appear! Now I'm extra glad that I made #2994702: Allow editors to alter embed-specific metadata, as well as `data-align` and `data-caption` reuse this patch's CSS rather than duplicating it 😅
Comment #61
alexpottThis patch introduces some css coding standards regressions. You can find this out by doing:
And fix this by doing adding
--fixto the command.Comment #62
alexpottThe @see is not correct. And the docs aren't really either - it's for adding on top of drupal-8.4.0-media_installed.php.
I think we should call this drupal-8.7.2-media_library_installed.php as this file is probably more generic than just for this specific issue. And remove the @see
Also we should file a follow-up issue to rename and merge core/modules/media_library/tests/fixtures/update/drupal-8.media_library-update-view-table-display-2981044.php and core/modules/media_library/tests/fixtures/update/drupal-8.media_library-update-widget-view-3020716.php to whatever version of media library install they represent.
Leaving rtbc as this is naming things.
Comment #63
phenaproximaFiled #3065718: Merge and rename Media Library update path fixtures.
Comment #64
effulgentsia commentedCrediting @andrewmacpherson for review.
Comment #66
effulgentsia commentedPushed to 8.8.x.
Comment #67
wim leersYay! Rebased #2994702-15: Allow editors to alter embed-specific metadata, as well as `data-align` and `data-caption`, because it no longer needs to include this patch anymore 🥳
Comment #68
phenaproximaI would like to nominate this patch to be backported to 8.7.x, since it’s a significant accessibility improvement in an experimental module.
Comment #69
phenaproximaComment #70
xjmWhile this is indeed a good accessibility improvement, I think it's too disruptive to backport the item for a patch release (given the update hook, UI changes, etc.). I would leave this one as 8.8-only for now unless it's blocking other accessibility bugfixes or unless the issue is more severe than I understand.
Thanks!
Comment #71
catchThis should probably have been a post update rather than hook_update_N(). If we're not going to backport it, it creates a conflict if we did want to backport another update in the future. Also the update is just updating a config entity.
Comment #72
effulgentsia commentedHm, should we have a followup that moves it to a post_update, and leaves behind an empty
media_library_update_8703()? Then we can backport just the emptymedia_library_update_8703()to 8.7 to prevent future number conflict? Or the entire a11y fix if we decide to?Comment #73
gagarine commentedApparently this bug is the cause of #3041111: Items selected from the media library cannot be reordered by weight. Can we at least provide a patch that fix this issue? It's unusable in a lot of use case.
Comment #74
xjmAdam will create a followup for the update issue.
Comment #75
phenaproximaFiled #3084043: Convert media_library_update_8703() to a post-update hook.
Comment #76
phenaproximaThe follow-up has been created and is now RTBC, so I think this can be marked fixed.