-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
85c0583
to
f02c8c5
Compare
@@ -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) { |
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 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'}) {...}
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. I'll apply it to the cases that implement FocusableOption
.
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.
@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);
}
}
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.
@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
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 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).
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.
@jelbourn it's mostly for consistency.
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 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.
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.
Ok, then this looks good for now and we can deprecate the origin param later if needed
src/lib/core/option/option.ts
Outdated
@@ -161,11 +161,11 @@ export class MatOption implements AfterViewChecked, OnDestroy { | |||
} | |||
|
|||
/** Sets focus onto this option. */ | |||
focus(): void { | |||
focus(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.
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
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.
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.
e3ded0e
to
0ff4168
Compare
Hi @crisbeto! This PR has merge conflicts due to recent upstream merges. |
2 similar comments
Hi @crisbeto! This PR has merge conflicts due to recent upstream merges. |
Hi @crisbeto! This PR has merge conflicts due to recent upstream merges. |
0ff4168
to
64dbbb7
Compare
64dbbb7
to
6cd64ad
Compare
4cacad4
to
4f52133
Compare
4f52133
to
4cdd022
Compare
4cdd022
to
183961c
Compare
This change means that users can no longer create a focus key manager with a query list of |
183961c
to
5ce38df
Compare
Reworked to get |
5ce38df
to
9abdc4d
Compare
Looks like |
9abdc4d
to
9040b53
Compare
Updated to have |
bbfc304
to
110beab
Compare
Updates the `focus` methods on the different components to allow for the `FocusOptions` to be passed in. Fixes angular#14182.
110beab
to
edcfdb1
Compare
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. |
Updates the
focus
methods on the different components to allow for theFocusOptions
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.