Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

fix(button): properly show focus effect #9826

Merged
merged 1 commit into from
Oct 24, 2016

Conversation

devversion
Copy link
Member

@devversion devversion commented Oct 12, 2016

  • Only apply the focus effect for keyboard interaction (as same as it does currently, but not with a random timeout).

Similar to #9827

Fixes #8749. References #7963

@devversion devversion added the needs: review This PR is waiting on review from the team label Oct 12, 2016
.on('blur', function(ev) {
});

element.on('blur', function() {
Copy link
Member Author

@devversion devversion Oct 12, 2016

Choose a reason for hiding this comment

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

Note: This is intentionally another on statement, because otherwise the indention is ugly and this is just more clear..

@devversion devversion force-pushed the fix/button-focus-effect branch from b3d2f2d to 984d61b Compare October 12, 2016 17:36
@devversion devversion changed the title fix(button): only apply focus effect for keyboard interaction. fix(button): properly show focus effect Oct 12, 2016

element.on('focus', function() {
// Only show the focus effect when being focused through keyboard interaction.
if ($mdInteraction.getLastInteractionType() === 'keyboard') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this change the existing interaction if a developer focuses an element over Javascript (such as when opening a dialog or a custom component)?

Copy link
Contributor

@clshortfuse clshortfuse Oct 13, 2016

Choose a reason for hiding this comment

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

I think if you want to target operations related to the mouse, you should target those events specifically. Tracking the element's last interaction seems to better than tracking to body, since a click event somewhere else on a page would prevent a button from getting a md-focused class (again like a custom popup).

Copy link
Member Author

Choose a reason for hiding this comment

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

This does not change anything to the existing behavior, just that we now check the global interaction to detect the last interaction.

Focusing manually per .focus does not work right now as well, because the mousedown event didn't get fired.

This is the approach we wanted to go with the $mdInteraction service, as proposed by Marcy. Similar to #9827

Copy link
Contributor

Choose a reason for hiding this comment

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

This does not change anything to the existing behavior, just that we now check the global interaction to detect the last interaction.

You can see the behavior change with this codepen: http://codepen.io/shortfuse/pen/LRAarO

Copy link
Contributor

@clshortfuse clshortfuse Oct 13, 2016

Choose a reason for hiding this comment

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

I just some testing and mousedown gets fired after focus on Chrome. Instead of tracking mouseactive as a boolean, I would suggest a timestamp on last mousedown event. Then attach a timeout to the adding of md-focused. If mousedown was triggered within a certain time (say 100ms), don't add the class.

Edit: You also have to cancel said timeout from 'blur'

@devversion devversion added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Oct 13, 2016
@devversion devversion force-pushed the fix/button-focus-effect branch from 984d61b to c77660e Compare October 14, 2016 17:46
@devversion devversion removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Oct 14, 2016
@devversion devversion force-pushed the fix/button-focus-effect branch 2 times, most recently from c0629cd to 6774229 Compare October 14, 2016 18:11
@@ -54,7 +54,7 @@ angular
* </hljs>
*
*/
function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $mdUtil, $timeout) {
function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $mdUtil, $timeout, $mdInteraction) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the $mdInteraction import is unused.

*/
MdInteractionService.prototype.isProgrammatic = function(checkDelay) {
var delay = angular.isDefined(checkDelay) ? checkDelay : 15;
Copy link
Member

Choose a reason for hiding this comment

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

angular.isNumber might be more appropriate here.

* @returns {boolean} Whether there was any interaction or not.
*/
MdInteractionService.prototype.isProgrammatic = function(checkDelay) {
Copy link
Member

Choose a reason for hiding this comment

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

I know that we decided on the naming for this together, but I'm still not sure that isProgrammatic is very obvious. It seems like it implies that the service is programmatic. That being said, I don't have any better suggestions at the moment, perhaps other team member can pitch in?

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, Carlos had a great idea here. - isUserInvoked.

@devversion devversion force-pushed the fix/button-focus-effect branch 2 times, most recently from 4463449 to 7bcc991 Compare October 14, 2016 18:50
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.


button.triggerHandler('focus');

expect(button[0]).toHaveClass('md-focused');
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK you don't have to fetch the DOM node here. expect(button).toHaveClass('md-focused') should work as well.

Copy link
Member Author

@devversion devversion Oct 14, 2016

Choose a reason for hiding this comment

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

Valid and changed it. But FYI: a lot of other tests are doing the same and I don't want to diff the whole test now.

Copy link
Member

Choose a reason for hiding this comment

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

That's why I didn't make it a blocking request. It's basically the same, it just looks nicer.

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, changed it for the tests I've added.

* Only apply the focus effect for programmatic focus or by keyboard interaction (as same as it does currently, but not with a random timeout).

References angular#7963 Fixes angular#8749
@devversion devversion force-pushed the fix/button-focus-effect branch from 7bcc991 to 1630d42 Compare October 14, 2016 19:02
@ThomasBurleson ThomasBurleson added needs: presubmit and removed needs: review This PR is waiting on review from the team labels Oct 14, 2016
@jelbourn jelbourn merged commit 34823ac into angular:master Oct 24, 2016
@devversion devversion deleted the fix/button-focus-effect branch October 24, 2016 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants