Skip to content

Cannot change focal element on notify close #676

@oliverfoster

Description

@oliverfoster

Subject of the issue

When opening a notify, it captures the document.activeElement to return there upon closing. There is no easy way to change the element that should be focused after the notify closes.

This feature was introduced in 2018 in this commit, with the following lines in play:

this.$previousActiveElement = $(document.activeElement);

Adapt.trigger('popup:closed notify:closed', this.$previousActiveElement);

Adapt.on('popup:closed', function($target) {
//restore tab indexes
var $launchedElement = $.a11y_popdown();
var $activeElement = $target || $launchedElement;
if ($activeElement) {
return $activeElement.focusOrNext();
}

And can be seen in today's code at these lines:

this.$previousActiveElement = $(document.activeElement);

a11y.popupClosed(this.$previousActiveElement);

closed($focusElement, silent) {
const $previousFocusElement = this._removeLastPopupLayer();
$focusElement = $focusElement || $previousFocusElement || $('body');
if (!silent) {
Adapt.trigger('popup:closed', $focusElement, true);
}
this.a11y.focusFirst($($focusElement), { preventScroll: true });

It would be ideal if we could use the a11y.setPopupCloseTo for the notify:

/**
* When a popup is open, this function makes it possible to swap the element
* that should receive focus on popup close.
*
* @param {Object} $focusElement Set a new element to focus on.
* @returns {Object} Returns previously set focus element.
*/
setPopupCloseTo($focusElement) {
return this._popup.setCloseTo($focusElement);
}

setCloseTo($focusElement) {
const $original = this._focusStack.pop();
this._focusStack.push($focusElement);
return $original;

Metadata

Metadata

Assignees

Projects

Status

Needs Reviewing

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions