-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(button): focus method does not respect specified origin #17183
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(button): focus method does not respect specified origin #17183
Conversation
It looks like `MatButton` at some point has been refactored to implement the `FocusableOption` interface so that it can be used easily in the `FocusKeyManager`. Currently since the `origin` parameter in the `focus` method is not respected, the `FocusKeyManager#setFocusOrigin` method is a noop for button elements. Additionally consumers of `MatButton` who pass in a specific `FocusOrigin` when calling the `focus` method will be surprised that the `origin` is simply ignored (even though it's part of the public method signature; just prefixed with an underscore). We should just respect the focus origin to make the method less confusing and to properly implement the `FocusableOption`. Fixes angular#17174
jelbourn
left a comment
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
| // Note that we aren't using `_origin`, but we need to keep it because some internal consumers | ||
| // use `MatButton` in a `FocusKeyManager` and we need it to match `FocusableOption`. | ||
| this._getHostElement().focus(options); | ||
| focus(origin: FocusOrigin = 'program', options?: FocusOptions): void { |
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.
FocusOrigin has the definition 'touch' | 'mouse' | 'keyboard' | 'program' | null; (Notice the null)
I think the correct(-er) fix would be to do:
focus(origin: FocusOrigin = null, options?: FocusOptions)
And let the FocusMonitor handle it however it wants to handle an unset FocusOrigin (which happens to be to treat it as 'program').
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 see your point. But I feel like explicitly having program as default is reasonable since this method intends to focus the button programmatically (unless a specific origin had been specified)
It looks like `MatButton` at some point has been refactored to implement the `FocusableOption` interface so that it can be used easily in the `FocusKeyManager`. Currently since the `origin` parameter in the `focus` method is not respected, the `FocusKeyManager#setFocusOrigin` method is a noop for button elements. Additionally consumers of `MatButton` who pass in a specific `FocusOrigin` when calling the `focus` method will be surprised that the `origin` is simply ignored (even though it's part of the public method signature; just prefixed with an underscore). We should just respect the focus origin to make the method less confusing and to properly implement the `FocusableOption`. Fixes #17174 (cherry picked from commit 1c307c8)
|
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. |
It looks like
MatButtonat some point has been refactoredto implement the
FocusableOptioninterface so that it canbe used easily in the
FocusKeyManager.Currently since the
originparameter in thefocusmethodis not respected, the
FocusKeyManager#setFocusOriginmethodis a noop for button elements. Additionally consumers of
MatButtonwho pass in a specificFocusOriginwhen callingthe
focusmethod will be surprised that theoriginis simplyignored (even though it's part of the public method signature; just
prefixed with an underscore).
We should just respect the focus origin to make the method
less confusing and to properly implement the
FocusableOption.Fixes #17174