Closed (duplicate)
Project:
Drupal core
Version:
10.1.x-dev
Component:
ajax system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Sep 2019 at 11:16 UTC
Updated:
28 Apr 2023 at 11:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
sasanikolic commentedHere is the patch with the proposed fix.
Comment #3
sasanikolic commentedComment #4
sasanikolic commentedComment #5
cilefen commentedComment #7
renrhafSetting to RTBC, tested in our project (see https://www.drupal.org/project/entity_browser/issues/3053181#comment-133...).
As per https://api.jquery.com/focus/ :
"The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (input, select, etc.) and links. In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property."
And https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabi... :
"A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard navigation, but could be focused with Javascript or visually... The user won't be able to focus any element with a negative tabindex using the keyboard, but a script can do so by calling the focus() method."
Comment #8
renrhafOoops, maybe we should make sure not to alter the tabindex if there is already one set on the focused element.
Setting back to review.
Comment #9
sasanikolic commentedThanks for the feedback @Renrhaf!
Doesn't this contradict the statement "not to alter the tabindex if there is already one set on the focused element."?
Comment #10
renrhafOh yeah, you're right sasanikolic... sorry for this.
Here is the updated patch.
Comment #11
sasanikolic commentedHmm, seems like this is causing some side effects. For example, when clicking Edit on a paragraph, the '.paragraph-top' parent class is focused.
Comment #12
miro_dietikerIn any case @Renrhaf this issue can not be RTBC without test coverage. The pass above lead to two learnings:
EDIT: When reading this issue i had trouble to reproduce what the bug was and what the fix would exactly result in. Test coverage would clarify this a lot.
Comment #13
miro_dietikerI checked Paragraphs accessibility and improved the situation for keyboard navigation.
See #3092762-15: Unable to access toggle button options using keyboard navigation.
This seems to be the next most annoying problem as after any ajax operation, the focus is lost and you need to tab through the whole form again, making the keyboard UX pretty unacceptable.
Comment #14
miro_dietikerComment #15
kasey_mk commentedThanks for this. #10 works for us and makes editing paragraphs much less annoying.
Comment #16
miro_dietikerForcing any element to become focusable seems a strange hack to me.
In Paragraphs, we add scroll persistency recovery when switching the behavior tabs. So we modify scroll position to make sure the active element stays in the viewport. This is needed because document length can vary, most importantly the length of elements above the viewport.
As one approach, Paragraphs could put the tabindex: -1 on each widget.
This is however not a Paragraphs only thing. It likely also affects Inline Entity Form. Does the problem also apply to regular fields with many values?
How about this alternative: Focus the first focussable element. The loop that identifies a target needs to also check for focussability.
I feel like this is the best we can do while maintaining the designed semantics of UX instead of force changing them.
Comment #17
sasanikolic commentedI tried your proposed solution @miro_dietiker, but couldn't figure out a couple of issues and I'm unsure this is the right direction to solve this, as we are forcing a decision to focus the first element of a parent, which might not be related to the clicked (and removed) element at all?
The issues I faced with this approach was, that it didn't work at all when opening and closing modals - e.g. entity browser for selecting images. Initially the close button was focused when opening the EB, but with these changes the "Select entities" was being focused instead. And when closing the EB by clicking the x button, the focus was not persisted but moved to the previous focused element. Not sure what is forcing that behavior, probably some code elsewhere. When replacing the image, however, this triggered the link "Show row weights" link to be focused, instead of the "Replace button"
See the new patch and screenshots attached.
Will try to figure out what is going on during the weekend.
Comment #20
abhisekmazumdarRe-roll the patch to 9.2.x.
Also unassigning the issue from @sasanikolic as it needed to be reviewed by others.
Comment #21
abhisekmazumdarFixed lint errors.
Comment #26
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #27
wim leersIs this even still relevant?
AFAICT it's not possible to automatically determine which element to focus after an AJAX command — it's context-dependent.
#3188938: Create AjaxCommand for focusing that does not require :tabbable selector added an AJAX command to make it feasible to do focus handling correctly, allowing each UI to handle it correctly in their context. Closing as a duplicate of that.