Problem/Motivation

After editing an image with the entity browser and clicking save or closing the modal, the form submit button gets focused and the page scrolls to the bottom. This happens only while editing, not while adding new entities.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic created an issue. See original summary.

oknate’s picture

+1 on this! I was noticing this this morning. This would be great to fix. I suspect it has something to do with the ajax update of the underlying element. It loses the focus because the element it was focused on was removed.

sasanikolic’s picture

I also believe that for accessibility reasons, we should return the focus to the element that was focused before the entity browser modal was opened:
- Before opening the modal, save a reference to document.activeElement. After closing the modal, focus the reference to the previous activeElement.

sasanikolic’s picture

I did some debugging here, but could not find a triggering element in the event object of the dialogopen/beforecreate functions.
I also tried to have a click event listener on edit/change buttons, but that also didn't work as expected. Any idea where to write a fix for that @oknate?

sasanikolic’s picture

EDIT: sorry for the doublepost.

sasanikolic’s picture

sasanikolic’s picture

This is a patch with a workaround, that disables the focus on the "Save" button. With that at least the page doesn't jump after saving.

Tried adding the test, but unfortunately it seems that there's no way to check for focused elements in a js test?
Got this error:

1) Drupal\Tests\entity_browser\FunctionalJavascript\EntityReferenceWidgetTest::testEntityReferenceWidget
Symfony\Component\CssSelector\Exception\ExpressionErrorException: Pseudo-class "focus" not supported.
sasanikolic’s picture

sasanikolic’s picture

Status: Active » Needs review
Renrhaf’s picture

Status: Needs review » Reviewed & tested by the community

Thanks sasanikolic for the patch. We noticed this issue in our project, then applied this patch and noted that the focus was no more set to the bottom of the form which is great for us ! Setting this to RTBC.

  • oknate committed e8c73f8 on 8.x-2.x authored by sasanikolic
    Issue #3053181 by sasanikolic: Maintain focus on clicked item after...

  • oknate committed f0fb4f6 on 8.x-1.x authored by sasanikolic
    Issue #3053181 by sasanikolic: Maintain focus on clicked item after...
oknate’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

🎉

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.