Skip to content

refactor: allow options to be passed to focus methods #14184

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

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

crisbeto
Copy link
Member

Updates the focus methods on the different components to allow for the FocusOptions to be passed in.

Fixes #14182.

Note: this doesn't include a few of the classes that implement FocusableOption, because it has a different requirement for the first param.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Nov 17, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 17, 2018
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 85c0583 to f02c8c5 Compare November 17, 2018 14:54
@@ -160,8 +160,8 @@ export class MatExpansionPanelHeader implements OnDestroy, FocusableOption {
* @param origin Origin of the action that triggered the focus.
* @docs-private
*/
focus(origin: FocusOrigin = 'program') {
this._focusMonitor.focusVia(this._element, origin);
focus(origin: FocusOrigin = 'program', options?: FocusOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make something like:

interface MatFocusOptions extends FocusOptions {
  origin: FocusOrigin?;
}

and then:

/** @breaking-change 9.0.0 remove FocusOrigin as a param type. */
focus(options: FocusOptions | FocusOrigin = {origin: '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.

Makes sense. I'll apply it to the cases that implement FocusableOption.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mmalerba I'm giving this a shot in the step header, it looks like it'll add a fair bit of a code if we want to support it in a backwards-compatible way. In order support the user passing in a FocusOrigin, we'd also have to add an optional dependency on the FocusMonitor. E.g. here's what the step header would look like:

focus(config: FocusableOptionConfig = {origin: 'program'}) {
  let origin: FocusOrigin | undefined;
  let options: FocusOptions | undefined;

  if (config == null || typeof config === 'string') {
    origin = config;
  } else {
    origin = config.origin;
    options = config;
  }

  if (this._focusMonitor) {
    this._focusMonitor.focusVia(this._elementRef, origin, options);
  } else {
    this._elementRef.nativeElement.focus(options);
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@jelbourn do you have any thoughts? The extra code isn't great, but I also don't like how we wind up with inconsistent APIs otherwise

Copy link
Member

Choose a reason for hiding this comment

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

I don't quite follow. Why would you need a dependency on FocusMonitor in places where it isn't used now?

Also, FWIW, I've been considering dropping FocusMonitor entirely and always showing focus state all the time (recommended by the a11y team and what MDC Web does).

Copy link
Member Author

Choose a reason for hiding this comment

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

@jelbourn it's mostly for consistency.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's right to add the FocusMonitor dependency just for that consistency. I'd rather have the discussion on whether we want to drop FocusMonitor now and then maybe just switch everything to the standard options for v8.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, then this looks good for now and we can deprecate the origin param later if needed

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Dec 4, 2018
@@ -161,11 +161,11 @@ export class MatOption implements AfterViewChecked, OnDestroy {
}

/** Sets focus onto this option. */
focus(): void {
focus(options?: FocusOptions): void {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like FocusOption isn't imported in this file. It's causing a presubmit failure. I don't understand why CircleCI is green, though

Copy link
Member Author

Choose a reason for hiding this comment

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

There's something in the DOM API that's called the same. I think we added ours since the interface isn't there in earlier TS versions (which probably happened in G3). I've added the import.

@crisbeto crisbeto force-pushed the 14182/focus-options branch 2 times, most recently from e3ded0e to 0ff4168 Compare December 19, 2018 07:04
@ngbot
Copy link

ngbot bot commented Jan 9, 2019

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

2 similar comments
@ngbot
Copy link

ngbot bot commented Jan 9, 2019

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@ngbot
Copy link

ngbot bot commented Jan 9, 2019

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@crisbeto crisbeto force-pushed the 14182/focus-options branch from 0ff4168 to 64dbbb7 Compare January 9, 2019 21:03
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 64dbbb7 to 6cd64ad Compare January 30, 2019 19:05
@crisbeto crisbeto force-pushed the 14182/focus-options branch 2 times, most recently from 4cacad4 to 4f52133 Compare February 17, 2019 20:32
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 4f52133 to 4cdd022 Compare March 17, 2019 10:50
@mmalerba mmalerba added aaa and removed aaa labels Apr 25, 2019
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 4cdd022 to 183961c Compare May 26, 2019 13:10
@andrewseguin andrewseguin added P2 The issue is important to a large percentage of users, with a workaround G This is is related to a Google internal issue labels May 30, 2019
@andrewseguin
Copy link
Contributor

This change means that users can no longer create a focus key manager with a query list of MatOption since MatOption no longer matches the FocusableOption interface.

@andrewseguin andrewseguin removed the action: merge The PR is ready for merge by the caretaker label Jul 10, 2019
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 183961c to 5ce38df Compare July 10, 2019 18:45
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 10, 2019
@crisbeto
Copy link
Member Author

Reworked to get MatOption to match FocusableOption.

@crisbeto crisbeto force-pushed the 14182/focus-options branch from 5ce38df to 9abdc4d Compare July 10, 2019 18:47
@andrewseguin andrewseguin removed the action: merge The PR is ready for merge by the caretaker label Jul 11, 2019
@andrewseguin
Copy link
Contributor

Looks like MatButton and MatCheckbox also needs to be adjusted so that they match the FocusableOption interface

@crisbeto crisbeto force-pushed the 14182/focus-options branch from 9abdc4d to 9040b53 Compare July 11, 2019 19:34
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 11, 2019
@crisbeto
Copy link
Member Author

Updated to have MatCheckbox and MatButton match FocusableOption.

@crisbeto crisbeto removed the action: merge The PR is ready for merge by the caretaker label Jul 11, 2019
@crisbeto crisbeto force-pushed the 14182/focus-options branch 2 times, most recently from bbfc304 to 110beab Compare July 11, 2019 19:39
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 11, 2019
Updates the `focus` methods on the different components to allow for the `FocusOptions` to be passed in.

Fixes angular#14182.
@crisbeto crisbeto force-pushed the 14182/focus-options branch from 110beab to edcfdb1 Compare July 11, 2019 19:45
@mmalerba mmalerba merged commit e6afdbb into angular:master Aug 7, 2019
mmalerba pushed a commit that referenced this pull request Aug 14, 2019
Updates the `focus` methods on the different components to allow for the `FocusOptions` to be passed in.

Fixes #14182.

(cherry picked from commit e6afdbb)
@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 Sep 11, 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 G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose focusOptions in the focus() APIs (e.g. in MatButton)
5 participants