Skip to content

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

Conversation

devversion
Copy link
Member

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

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
@devversion devversion added the target: patch This PR is targeted for the next patch release label Sep 24, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 24, 2019
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Sep 24, 2019
@andrewseguin andrewseguin merged commit 1c307c8 into angular:master Sep 27, 2019
// 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 {
Copy link
Contributor

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').

Copy link
Member Author

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)

andrewseguin pushed a commit that referenced this pull request Sep 30, 2019
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)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatButton.focus ignores origin argument
5 participants