Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
javascript
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Oct 2020 at 18:15 UTC
Updated:
19 May 2021 at 11:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bnjmnmThis includes the most recent patch from #3113649: Remove drupal.tabbingmanager's jQueryUI dependency which isn't committed yet but appears close.
This includes the addition of a new AjaxCommand to get around f Media Library using
InvokeCommandto find the first focusable element in a form. The Ajax commands expect jQuery, but with :tabbable deprecated the first focusable needs to be found + focused differently. This may need to be scoped to it's own issue but adding here for now as seeing it in a patch is easier than a long explanation.Comment #3
xjmComment #4
bnjmnmThe AJAX command is being added in #3188938: Create AjaxCommand for focusing that does not require :tabbable selector instead of here, so this is now postponed on that issue as well.
Comment #5
nod_Comment #6
bnjmnmAdding patch because the merge request was opened against 9.1 and I'm not sure how to update that + DA people are busy with Drupalcon right now.
Comment #7
bnjmnmComment #8
bnjmnmComment #9
bnjmnmComment #10
zrpnrThe
_focusTabbablefunction incore/misc/dialog/dialog.jquery-ui.es6.jsoverrides the original in
core/assets/vendor/jquery.ui/ui/widgets/dialog.jsIn the original function after the first check for
!hasFocusthe following if statements check for!hasFocus.lengthSeems like your version is more correct however since
this._focusedElementcould be null.This fooled me for a minute because I thought that some of these conditions return a jQuery object already, while others return a DOM node, but then I noticed the
get(0)wherever a jQuery find is used, which ensures you always get the element directly.This also helped me understand why in the original function they had
hasFocus.length- since after the first if statement it could be an empty jQuery object with length 0. In your version it it will just be undefined until there's a match.Your version is an improvement IMO!
The override in tabbingmanager.es6.js is more straightforward- but
I was thrown off by the
addBack. It seems like that's covered here by checking for the rootElement tabbable descendents and then checking if rootElement itself isTabbable. Smart!Manually tested this by opening a media library dialog, clicking another tab. The first input was correctly focused.
The InvokeCommand was previously calling focus on any :tabbable children of #media-library-add-form-wrapper, FocusFirstCommand uses focusFirst in ajax.es6.js to grab the first tabbable element, added in #3188938: Create AjaxCommand for focusing that does not require :tabbable selector. Perfect follow-up use of that method!
The only nits I found were 2 places where comments would now be outdated, referring to ":tabbable"
core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php
(see interdiff)
I don't feel strongly about those, IMHO this is ready. Really nice work @bnjmnm !
Comment #12
zrpnrBumping back to NW for the test failure that came through after.
Comment #13
bnjmnmThe test failure is from
CKEditorIntegrationTest, one of those "unrelated and known to intermittently fail" tests. Used this as an opportunity to update those ":tabbable" uses mentioned in #10Comment #14
bnjmnmThere were file permissions changes in #13 that shouldn't have been there.
Comment #15
zrpnrApparently the test failure in #11 is intermittent and unrelated.
The patch in #14 makes the 2 comment changes I suggested, no other changes.
Comment #16
lauriiiBased on https://github.com/focus-trap/tabbable#tabbable,
tabbable()returns always an array. After that we are testing[]which in JavaScript is a truthy value.Based on that I did some testing and found out that this is broken in cases where the first
tabbable()call didn't find tabbbable values. 😅 That leads into some problems because the dialog doesn't end up focused and therefore tabbing results in focusing items outside the dialog until the user reaches the dialog which could be in the very end of the page.This points out that we are lacking test coverage in some pretty critical parts of the code. Based on this experience, I think we should add some more tests before committing this.
Comment #17
zrpnr@lauriii is correct about the truthy array preventing the correct element from being focused. I also found that tabbable errors out if you try to pass it a non-element.
Added FunctionalJavascript tests for the different focus scenarios:
Updated the code in the overridden function to pass these tests.
Comment #19
bnjmnmI like the steps being attached to the relevant code like this! Easier to understand. A few nits that accompanied it:
- Some of the steps end with punctuation, while others don't. The way it's formatted now, I think it works best with punctuation.
-There should be a line of whitespace preceding each inline comment (not the case in all of core but I've had stuff kicked back for that).
The most inconsequential nit: could this be a 'Thing 3' since there's already a 'Thing 2' above?
Extra closing tag here and in modalContentInput()
Nice that all the possibilities are covered, even unlikely ones like no close button!
Similar to prior nit, this and a few other inline comments in the test can get a whitespace line above them.
The tests look good, what follows is pretty much nitty.
Could these focus assertions remove the jQuery dependency? Something like
document.activeElement === document.querySelector('.ui-dialog')? It will probably be a long time before dialogs have no jQuery dependency, but the vanilla approach may prevent some later debt.Comment #20
zrpnrThanks @bnjmnm - I added the punctuation and spacing you suggested, and fixed the extra closing tag in the test content.
I didn't want to spoil the Dr Seuss joke :) but also because that markup was identical to the previous except for the
autofocusattribute, to prove that it took precedence. Totally fine with changing it though!Good call, I had left these as close to what you had in other tests, such as
MediaLibraryTestBase, where the test change was really minimal.Changed to your suggestion in
ModalRendererTest,I didn't change the similar assertions in
EditModeTest,MediaLibraryTestBaseorEntityReferenceWidgetTestsince those tests had existing use of jQuery and it's more clear that the assertion hasn't changed if it isn't rewritten to remove the jQuery usage.Comment #21
bnjmnmRe #20
That's in line with what I was thinking. There are existing uses that would be out of scope to change in this issue, I just wanted to avoid adding more jQuery here when a no-dependency option was available.
This was RTBC at #15, I feel comfortable switching back to RTBC as @zrpnr has done the work since the previous RTBC to address #16, which I've reviewed and it looks good!
Comment #22
bnjmnmThere's a bit of code duplication that needs to be addressed, I suspect @zrpnr has a new patch on the way, and I'll give it another look then.
Comment #23
zrpnrThis removes the duplicate test and fixes a comment.
Comment #24
lauriii:tabbableselector. If that's not supposed to be in the scope of this issue, we should retitle and open follow-up for deprecating it.core/tabbable.jquery.shimfromcore/drupal.tabbingmanagerlibrary?Comment #25
bnjmnm#24 is correct, the selector should be deprecated (can be added to core/misc/jquery.tabbable.shim.es6.js), the core/tabbable.jquery.shim dependency can be removed, and the change record needs creating.
Comment #26
bnjmnmComment #27
zrpnrAdded the deprecation message to jquery.tabbable.shim.es6.js, and added core/drupal as a dependency so that the message appears.
Removed the shim dependency from tabbing manager
Comment #29
bnjmnmConfirmed the deprecation is triggered.

I spotted a few more things, but this is close.
The 'elements' argument can be an element set OR a jQuery-compatible selector string. This approach currently won't work with a selector string.
Not an item that needs addressing, but just highlighting that although refactoring away
:tabbablemakes this script string longer, keeping thejQueryin there keeps it from becoming an even longer"window.tabbable.tabbable(document.body).forEach((element) => element.setAttribute('data-marked', ''));"Given that it's VERY improbable
#media-library-contentwould not have a tabbable element. But, were that the case, this would error out and break the JS that accompanies it.This is looking in
#media-library-content, but the previous assertion was looking in#media-library-add-form-wrapper. This still passes since the first tabbable element in#media-library-contenthappens to also be the first tabbable element in#media-library-add-form-wrapper, but this should continue to check within the same selector.This should link to the CR instead of this issue
Add a WS line before this comment
Comment #30
zrpnr#29.1 Wrapped this in a jQuery function to ensure if a selector or other arg was passed in that it would be a jQuery object before
.eachis called. Also updated the argument list in the jsdoc to be more thorough.In core there's only one place I found and it is definitely passing a jQuery object, in
core/modules/contextual/js/toolbar/views/AuralView.es6.js.#29.2 👍
#29.3 Just to be safe I added some extra checks so that a null value isn't passed to
tabbableand to make sure the array is not empty.#29.4 Good catch! Restored the previous selector
#29.5 Corrected the link to the CR
#29.6 Added extra linebreak
Comment #31
bnjmnm#30 successfully addresses all my review feedback, so RTBC.
One thing to note:
To clarify for any other reviewers, the change @zrpnr made to the docs here is not due to changed functionality. The prior documentation was not accurate. Correcting this makes the changes within the function easier to understand.
Comment #32
lauriiiWhat is this change for?
Comment #33
bnjmnm#32.2, the addition of
core/drupalto the shim is so the shim can callDrupal.deprecationErrorwhen the:tabbableselector is used.#32.3
The dependency being removed in this patch is one that was added in the dev branch for 9.2 (the same branch this is intended to go in). I'm concerned mentioning this in the CR would be confusing as it wouldn't be documenting the difference between releases. I do think this would be needed if landing this gets postponed to 9.3.
Comment #34
zrpnr#32.1 Added a js deprecation check in the nightwatch test
#32.2 I added that dependency since
Drupal.deprecationErroris in drupal.jsComment #35
zrpnr🤦♂️missing a semicolon
Comment #36
zrpnr@bnjmnm and I discovered a bug in the Nightwatch test, it was no longer testing the tabbable shim after removing that dependency from core/drupal.tabbingmanager in #27.
The tests were still passing due to the error messages being equal ... 😬
Added additional assertions to prove the values should be numbers and not errors, updated the test module library to be
core/jquery.uiinstead - which has a dependency on the tabbable shim.Added an additional deprecation check, the tabbable shim test should have triggered the warning, the fact that it didn't proved the test was not working properly. Thanks @lauriii for pointing us in the right direction to find this problem!
Comment #37
bnjmnmSince we've been through a few rounds of near-rtbc, I'm focusing on the diff and it's looking good:
This should have been the library I attached to begin with, as it is the library directly providing the tabbable selector. Good change.
Locally, I switched the library back to
core/drupal.tabbingmanagerand confirmed these assertions were sufficient to fail a test where the :tabbable selector wasn't available.This existing Nightwatch test already triggers this deprecation all over the place, so this is a nice spot to add the deprecation assertion.
Comment #38
lauriiiI had to run
yarn build:jsbefore committing because we have updated some yarn dependencies since the patch was generated.Committed b48ad90 and pushed to 9.3.x. Thanks!
Comment #41
lauriiiNow also cherry-picked to 9.2.x. ✌️