Description
Reproduction
Stackblitz: https://stackblitz.com/edit/angular-atdzsd
Steps to reproduce:
- Open the Stackblitz above on either FF or non-Chromium Edge. The Stackblitz contains a
mat-checkbox
that disables itself when activated. - Activate the
mat-checkbox
with space. Observe that themat-checkbox
is now indeed disabled.
Expected Behavior
I'd expect that the mat-checkbox
loses its focus styles (and essentially all of the issues in "Actual Behavior" don't occur).
Actual Behavior
Observe the following after activating the mat-checkbox
with space:
- The
mat-checkbox
still has the classes.cdk-focused
and.cdk-keyboard-focused
. - As a result, the
mat-checkbox
still has focus styles. - If you query for the
document.activeElement
, it returns themat-checkbox
. - Subsequent mouse clicks & focus events on the page do not cause the
mat-checkbox
to lose its focus styles (i.e. it looks focused essentially forever).
All of the above are unexpected.
What's Happening
On FF and non-Chromium Edge, when a focused element is [disabled]
it (1) remains the document.activeElement
and (2) consequently no blur
event is emitted. These appear to be browser bugs. As a result of this behavior, the attached FocusMonitor
on mat-checkbox
(and other components like mat-button
) never receives a blur
event to remove the .cdk-focused
and .cdk-keyboard-focused
classes on the element.
Potential Solution
We could add some work-around logic to FocusMonitor
to listen if a monitored element becomes [disabled]
, and if so, do the same thing we'd do if the element was actually blurred.
Environment
- Angular: Latest
- CDK/Material: Latest
- Browser(s): FF, non-Chromium Edge
- Operating System (e.g. Windows, macOS, Ubuntu): macOS