Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#8730 closed feature (fixed)

Dialog: Restore focus to opener

Reported by: Jörn Zaefferer Owned by:
Priority: blocker Milestone: 1.10.0
Component: ui.dialog Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:

Description

Whenever a dialog is opened, it should remember what element had focus, and restore focus to that element.

Change History (5)

comment:1 Changed 5 years ago by Jörn Zaefferer

Priority: minorblocker
Status: newopen

comment:2 Changed 5 years ago by Jörn Zaefferer

Resolution: fixed
Status: openclosed

Dialog: Save the active element that opened the dialog and restore focus to that. Fixes #8730 - Dialog: Restore focus to opener.

Changeset: 14691ae6feea2732ec5aeae57b4275aa0e4d1beb

comment:3 Changed 3 years ago by usmonster

The current-implemented behavior can be an issue in cases where the dialog has been opened programmatically (e.g. triggered by some other event) and the originally-focused element ("opener" in the code, a misnomer in this case) is not visible within its scroll parent or the viewport.

Example: http://jsfiddle.net/jzxseunh/1/

Closing the dialog will scroll the element into view even though it wasn't before.

The culprit is here: https://github.com/jquery/jquery-ui/commit/14691ae#diff-bd5d7db0e6a3ff783a7ec2ccf261f6b4R251

The call to .focus() should not be done inside the conditional, but there should instead be a step to store the scrollTop/scrollLeft of the scroll parent just before the focus, then restore it after the focus (perhaps conditionally, depending on whether or not the element was already visible).

Does this sound reasonable? Should this be reopened, or should I copy-paste this as a new issue? Thoughts?

comment:4 in reply to:  3 ; Changed 3 years ago by Scott González

Replying to usmonster:

Does this sound reasonable?

So far, no, because you haven't provided a real world use case, though I'm sure you have one.

Should this be reopened, or should I copy-paste this as a new issue?

Definitely a new issue. This is a two year old feature, it absolutely should not be used for anything at this point.

comment:5 in reply to:  4 Changed 3 years ago by usmonster

Replying to scott.gonzalez:

Definitely a new issue. This is a two year old feature, it absolutely should not be used for anything at this point.

Ok, opened #10686, with real world use case and some rewording and other clarifications.

Note: See TracTickets for help on using tickets.