-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(material/button): cdk-focus classes not being applied #25619
fix(material/button): cdk-focus classes not being applied #25619
Conversation
src/material/button/button-base.ts
Outdated
@@ -95,6 +103,7 @@ export class MatButtonBase | |||
elementRef: ElementRef, | |||
public _platform: Platform, | |||
public _ngZone: NgZone, | |||
private _focusMonitor: FocusMonitor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use the new inject
function to get the focus monitor. That way you can avoid all the constructor changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point - done.
src/material/button/button-base.ts
Outdated
@@ -95,6 +103,7 @@ export class MatButtonBase | |||
elementRef: ElementRef, | |||
public _platform: Platform, | |||
public _ngZone: NgZone, | |||
private _focusMonitor: FocusMonitor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the focus monitor styles for the focus styles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to these styles here: https://github.com/angular/components/blob/main/src/material/legacy-button/_button-base.scss#L67 I believe that should be the only one for the button component. Visually I can't tell the difference between having those styles or not, but maybe they were included with the legacy button for a reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are the focus styles for the legacy button. I was referring to these https://github.com/angular/components/blob/main/src/material/button/_button-theme-private.scss#L21.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, added .cdk-focused
- would that suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should match the behavior of the old button where the focus indication is only shown for keyboard and programmatic focus. Also the :focus
selector is now redundant and can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - done.
af91153
to
6622bc1
Compare
The code LGTM, but one of the CI checks is failing. You can run |
@@ -18,8 +18,11 @@ | |||
opacity: map.get($opacities, hover); | |||
} | |||
|
|||
&:focus .mat-mdc-button-persistent-ripple::before { | |||
opacity: map.get($opacities, focus); | |||
.cdk-program-focused, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah actually these selectors should be prefixed with &
, otherwise the button focus indication will show when it's inside of any focused element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - done.
6622bc1
to
1943d21
Compare
Fixes a bug in the Angular Material `button` component where cdk-focused, cdk-keyboard-focused, cdk-mouse-focused were not being applied upon respective focus. This is because there was no FocusManager set up with the MDC buttons like the legacy button did. Fixes angular#25618
1943d21
to
f2059c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes a bug in the Angular Material
button
component where cdk-focused, cdk-keyboard-focused, cdk-mouse-focused were not being applied upon respective focus. This is because there was no FocusManager set up with the MDC buttons like the legacy button did.Fixes #25618