-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(selection-list): restore focus if active item is destroyed #7125
fix(selection-list): restore focus if active item is destroyed #7125
Conversation
src/lib/list/selection-list.ts
Outdated
@@ -170,11 +157,11 @@ export class MdListOption extends _MdListOptionMixinBase | |||
|
|||
_handleFocus() { | |||
this._hasFocus = true; | |||
this._renderer.addClass(this._element.nativeElement, FOCUSED_STYLE); | |||
this.selectionList._setFocusedOption(this); | |||
} | |||
|
|||
_handleBlur() { |
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.
Since this is just toggling a boolean, it can also be done inline.
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.
Sure
src/lib/list/selection-list.ts
Outdated
@@ -334,4 +294,9 @@ export class MdSelectionList extends _MdSelectionListMixinBase | |||
private _isValidIndex(index: number): boolean { | |||
return index >= 0 && index < this.options.length; | |||
} | |||
|
|||
/** Returns the index of the specified list option. */ | |||
private _getIndexFromOption(option: MdListOption): number { |
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.
Call this something like _getOptionIndex
?
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.
Sounds also good
src/lib/list/selection-list.ts
Outdated
const optionIndex = this._getIndexFromOption(option); | ||
|
||
// Check whether the option is the last item | ||
if (optionIndex - 1 >= 0) { |
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.
if (optionIndex > 0)
should be a bit more readable.
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.
Yeah that's better. Just took the old logic here.
src/lib/list/selection-list.ts
Outdated
// Check whether the option is the last item | ||
if (optionIndex - 1 >= 0) { | ||
this._keyManager.setPreviousItemActive(); | ||
} else if (optionIndex < this.options.length - 1) { |
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 see any case, aside from optionIndex === 0
, where it would get into this block. You can simplify it to check for optionIndex === 0
instead.
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.
Done. Addressed your feedback.
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
src/lib/list/selection-list.ts
Outdated
|
||
// Check whether the option is the last item | ||
if (optionIndex - 1 >= 0) { | ||
if (optionIndex > 0) { |
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 an extra space before the >
.
5e5a8ce
to
b09262f
Compare
8ad9fec
to
39d66be
Compare
* Removes the `destroyed` and `onFocus` observables and instead just calls methods on the injected `MdSelectionList` instance. * Fixes that the active item is not updating if the active item is being destroyed.
39d66be
to
1335a0c
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. |
Removes the
destroyed
andonFocus
observables and instead just calls methods on the injectedMdSelectionList
instance.Fixes that the active item is not updating if the active item is being destroyed.