Skip to content
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

Merged

Conversation

devversion
Copy link
Member

  • 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.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 16, 2017
@@ -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() {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@@ -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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds also good

const optionIndex = this._getIndexFromOption(option);

// Check whether the option is the last item
if (optionIndex - 1 >= 0) {
Copy link
Member

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.

Copy link
Member Author

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.

// Check whether the option is the last item
if (optionIndex - 1 >= 0) {
this._keyManager.setPreviousItemActive();
} else if (optionIndex < this.options.length - 1) {
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 see any case, aside from optionIndex === 0, where it would get into this block. You can simplify it to check for optionIndex === 0 instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Addressed your feedback.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM


// Check whether the option is the last item
if (optionIndex - 1 >= 0) {
if (optionIndex > 0) {
Copy link
Member

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

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Sep 17, 2017
@devversion devversion force-pushed the fix/selection-list-active-item-destroy branch from 5e5a8ce to b09262f Compare September 17, 2017 14:51
@devversion devversion added the P2 The issue is important to a large percentage of users, with a workaround label Sep 18, 2017
@devversion devversion force-pushed the fix/selection-list-active-item-destroy branch 3 times, most recently from 8ad9fec to 39d66be Compare September 29, 2017 12:21
* 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.
@devversion devversion force-pushed the fix/selection-list-active-item-destroy branch from 39d66be to 1335a0c Compare September 29, 2017 13:27
@andrewseguin andrewseguin merged commit e05f939 into angular:master Sep 29, 2017
@devversion devversion deleted the fix/selection-list-active-item-destroy branch November 20, 2017 16:36
@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 7, 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 P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants