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

feat(focus-classes): expose focus origin changes through observable #2974

Merged
merged 5 commits into from
Feb 9, 2017

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Feb 7, 2017

also has a fix to restore focus origin after window loses focus and then regains it

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 7, 2017
renderer.setElementClass(element, 'cdk-program-focused', this._origin == 'program');

subject.next(this._origin);
this._lastFocused = new WeakMap().set(element, this._origin);
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to understand why we need a WeakMap when the the WeakMap always contains one element at most.

I think we can assume that the browser always returns focus to the last focused element and multiple elements can't be focused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I was thinking I needed a reference to the element to check that it was the same one, but you're probably right that I can safely assume that. Let me try.

renderer.setElementClass(element, 'cdk-focused', false);
renderer.setElementClass(element, 'cdk-keyboard-focused', false);
renderer.setElementClass(element, 'cdk-mouse-focused', false);
renderer.setElementClass(element, 'cdk-program-focused', false);
subject.next(null);
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to emit null on blur? I didn't see any test for it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do think we want this, because I want to later expand this to apply the classes if the element or one of its children is focused, and it would be nice to have an easy way for developers to know when focus leaves the subtree. I'll add tests though

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Just was wondering because of the tests.

@mmalerba
Copy link
Contributor Author

mmalerba commented Feb 8, 2017

updated, PTAL

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 8, 2017
@tinayuangao tinayuangao merged commit d4ba648 into angular:master Feb 9, 2017
@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 6, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants