Skip to content

Commit

Permalink
Improve how last focused element is determined in PositronModalReactR…
Browse files Browse the repository at this point in the history
…enderer (#4693)
  • Loading branch information
softwarenerd authored Sep 16, 2024
1 parent 10f5bb3 commit a026b23
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,17 @@ export class PositronModalReactRenderer extends Disposable {
// Call the base class's constructor.
super();

// Set the last focused element.
const activeElement = DOM.getWindow(options.parent).document.activeElement;
if (activeElement instanceof HTMLElement) {
// Get the active element.
let activeElement: Element | null = null;
if (options.parent) {
activeElement = DOM.getWindow(options.parent).document.activeElement;
}
if (!activeElement) {
activeElement = DOM.getActiveWindow().document.activeElement;
}

// If the active element is an HTML element, set it as the last focused element.
if (DOM.isHTMLElement(activeElement)) {
this._lastFocusedElement = activeElement;
}

Expand Down

0 comments on commit a026b23

Please sign in to comment.