Enhance FocusMonitor to communicate window deactivation vs other forms of focus loss #15744
Labels
area: cdk/a11y
feature
This issue represents a new feature or feature request rather than a bug or bug fix
P4
A relatively minor issue that is not relevant to core functions
Please describe the feature you would like to request.
Please extend the FocusMonitor to better align with document.activeElement, by treating window deactivation as a slightly different case than a loss of focus resulting from the user actually clicking on a different element of the page. Also a way to detect window re-activation as opposed to user selection of an element.
What is the use-case or motivation for this proposal?
When a browser window loses focus, document.activeElement is not changed. From the DOM's point of view, there is still an "active" element, but the FocusMonitor treats this the same as if the user had simply clicked somewhere else on the page. There are cases where we don't want to blur the state of the page just because it is no longer the active window, and cases where we don't want to go through a re-focus process just because the window became active again.
Is there anything else we should know?
This change could easily be implemented with minimal breakage by using undefined to mean window deactivated (as both undefined and null are falsey). 'window' could then be added as a FocusOrigin value to signal window activation.
The implementation below has been working well in my own project, but it seems useful enough to merge into the base FocusMonitor.
`
export type FocusOriginEx = FocusOrigin | 'window' | undefined;
@Injectable()
export class FocusMonitorEx extends FocusMonitor {
}
`
The text was updated successfully, but these errors were encountered: