-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(mdButton): focus styles only on keyboard #1594
Conversation
Alternative approach uses CSS and ARIA tricks instead of events: http://codepen.io/marcysutton/pen/OPveqd |
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 ? |
@gkalpak I don't think it matters on buttons. On checkboxes and switches, however, this is an issue. |
@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 - let's review this together after ng-conf, etc. |
So, does the Material Design spec. not have a unique style for focus (instead of having to share one with hover)? Edit: |
@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; }) |
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.
var mouseActive;
element.on('moveover', function onMouseOver() {
mouseActive = true;
element.on('mouseleave', onMouseOut );
element.off('mouseover', onMouseOver );
}
d242427
to
55204cf
Compare
@marcysutton - like it. |
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