Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

fix(mdButton): focus styles only on keyboard #1594

Closed
wants to merge 1 commit into from

Conversation

marcysutton
Copy link
Contributor

This change limits focus styles to the keyboard and not on mouse clicks by setting a flag on mousedown and checking for that flag when a focus event happens. The goal is to make custom focus styles act more like native buttons, where clicking doesn't persist a focus style.

Related prototype: http://codepen.io/marcysutton/pen/GgxboO

Closes #1423, #142

@ajoslin ajoslin added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Feb 20, 2015
@marcysutton
Copy link
Contributor Author

Alternative approach uses CSS and ARIA tricks instead of events: http://codepen.io/marcysutton/pen/OPveqd

@gkalpak
Copy link
Member

gkalpak commented Feb 22, 2015

It is a (rather rare) corner-case, but what if the user places the mouse over the element and then uses the keyboard to press the button ?

@marcysutton
Copy link
Contributor Author

@gkalpak I don't think it matters on buttons. On checkboxes and switches, however, this is an issue.

@marcysutton
Copy link
Contributor Author

@ThomasBurleson can you take a look at this one? It will solve the problem with focus styles persisting on mouse click. For buttons, I think handling focus with events is better than creating and managing multiple elements. But they are both pretty hacky, to be honest.

@marcysutton marcysutton self-assigned this Feb 27, 2015
@ThomasBurleson
Copy link
Contributor

@marcysutton - let's review this together after ng-conf, etc.

@albertboada
Copy link

So, does the Material Design spec. not have a unique style for focus (instead of having to share one with hover)?
This looks like a very dodgy solution (probably from my ignorant point of view).

Edit:
Now that I see how native buttons behave, doesn't look like a bad idea at all!

@marcysutton
Copy link
Contributor Author

@albertboada every solution to this problem is dodgy, quite frankly. It's a major and known limitation of browser focus/hover styles. Refer to this thread: #556 (comment)

// restrict focus styles to the keyboard
scope.mouseActive = false;
element
.on('mouseover', function() { scope.mouseActive = true; })
Copy link
Contributor

Choose a reason for hiding this comment

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

var mouseActive;
element.on('moveover', function onMouseOver() {
   mouseActive = true; 
  element.on('mouseleave', onMouseOut );
   element.off('mouseover', onMouseOver );
}

@ThomasBurleson
Copy link
Contributor

@marcysutton - like it.

@ajoslin ajoslin removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Apr 10, 2015
@Splaktar Splaktar added this to the 0.9.0 milestone Apr 10, 2018
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.

<md-button>: cancelling button tap/click does not remove :focus style
6 participants