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

md-button stays focused after a click #556

Closed
PaulMougel opened this issue Nov 6, 2014 · 26 comments
Closed

md-button stays focused after a click #556

PaulMougel opened this issue Nov 6, 2014 · 26 comments
Labels
- Lots of Comments resolution: works as expected The functionality works as designed and documented. ui: focus
Milestone

Comments

@PaulMougel
Copy link
Contributor

After clicking or touching on a <md-button>, it stays focused, both on latest Firefox, Chrome, mobile Chrome and mobile Safari (see the demo page). Only by clicking somewhere else will the button loose focus. Is it the intended behavior?

Screenshot in latest Chrome stable, on Mac Os Yosemite, on the demo page:
untitled

@epelc
Copy link
Contributor

epelc commented Nov 6, 2014

This may be intentional can any designers comment? I've seen this in bootstrap and have removed disabled it before but it may be helpful to know the last button you clicked. I'm still back and forth about it maybe it should be an option you could enable if some people want this.

@marcysutton
Copy link
Contributor

There are changes to <md-button> coming. But I can say that a focus style needs to be enabled, so be very careful when disabling something like this.

@PaulMougel
Copy link
Contributor Author

I get that the focused state has to stay enabled for a little bit, but now I get the impression that the action that the button is supposed to do (say, load more content on the page) is not finished, as the button stays "clicked".

@epelc
Copy link
Contributor

epelc commented Nov 6, 2014

I'm not saying remove the focus style. I think @PaulMougel and myself are refering to when you click a button it shouldnt have focus until you click something else. After you click it should be the same as before you clicked it.

The argument against have it like how it is now is that there may be benefits in seeing the last button you clicked easily.

@marcysutton
Copy link
Contributor

Gotcha. We'll take a closer look, that does sound odd. I've just seen focus styles removed entirely for reasons like this.

@PaulMougel
Copy link
Contributor Author

Looks like it is related to keyboard navigation: after having clicked with my mouse the button, I can tab to the next button.
untitled

@marcysutton
Copy link
Contributor

It shouldn't have the focus style when you click, but the button is actually focused. That's how a native button works. There are major changes coming to <md-button>, so we'll keep this in mind.

Updated with a really basic Codepen where we can check native button focus behavior: http://codepen.io/marcysutton/pen/jDKlf

@epelc
Copy link
Contributor

epelc commented Nov 6, 2014

@PaulMougel you can make it a non styled focus where tab would still work and have the right position after a click but it wouldnt have the focused style.

I think we should come back to this after the <md-button> since @marcysutton says they will be major and this might even be fixed after.

@PaulMougel
Copy link
Contributor Author

Alright, let's wait for the refactoring then :) Thanks a lot for the quick answers!

@marcysutton
Copy link
Contributor

Apparently this is a larger issue, and quite difficult to solve cross-platform. Leaving this here for reference: https://twitter.com/patrick_h_lauke/status/530503642399666177

@mlibby
Copy link
Contributor

mlibby commented Nov 7, 2014

The standard is to give focus to buttons when clicked. The default browser style for :focus is a dashed outline. The default :hover style is a darker shade in the button. The two states have very different appearances.

Two ways to resolve this issue would be:

  1. have distinct :focus and :hover states.
  2. turn off :focus styles until the user uses the keyboard to navigate to the element in question.

@epelc
Copy link
Contributor

epelc commented Nov 7, 2014

I also noticed the sliders work the same way. It keeps focus after you click on it until you click somewhere else. Maybe this is intentional as I've seen it on several websites too.

@plato-cambrian
Copy link

I don't mind having a click event on a button setting focus. What if I want
to press the button a lot? It's kind of nice to be able to just keep
whacking Space bar.

also if we want to auto switch focus, its nontrivial to decide what is the
new focus element.

I think the individual click handlers should be in charge of switching
focus away from the clicked button
On Nov 7, 2014 9:22 AM, "Ed Pelc" notifications@github.com wrote:

I also noticed the sliders
https://material.angularjs.org/#/demo/material.components.slider work
the same way. It keeps focus after you click on it until you click
somewhere else.


Reply to this email directly or view it on GitHub
#556 (comment).

@miller9904
Copy link

Also, if md-tooltip is added to the button, it stays visible while the button has focus. That is definitely not the standard.

@marcysutton
Copy link
Contributor

<md-tooltip> is a different component and does not necessarily need to follow the same behavior. The focus style on buttons is something we will continue to work on, thanks for the input.

@ThomasBurleson ThomasBurleson added this to the 0.8.0-rc1 milestone Nov 13, 2014
@albertboada
Copy link

+1 for differentiating :focus styles from the :hover ones, at least

@marcysutton
Copy link
Contributor

Focus styles are covered in a different issue: #142

@irfanka
Copy link

irfanka commented Dec 27, 2014

bump

@caok2709
Copy link

Does anyone know how to disable md-button hover effect?

@vas1468
Copy link

vas1468 commented Dec 10, 2015

 .md-button:not([disabled]):hover {
    background-color: transparent;
  }

@ananyaojha
Copy link

What's the exact solution to this issue? I'm still getting this in my application. When switching tab and coming back to application, button is still showing active.

@simhnna
Copy link

simhnna commented Apr 10, 2018

@marcysutton I think this issue should still be open. The linked issue has been closed without a resolution to this one...

@marcysutton
Copy link
Contributor

@simhnna I don't work on Angular Material anymore, but I'd recommend looking into the proposed :focus-visible CSS selector or the What Input JavaScript library. I lovingly refer to this problem as Button focus hell because it isn't easy to solve in a way that supports all users. However, the aforementioned projects can help provide more styling hooks based on the user's input modality.

@Splaktar Splaktar added - Lots of Comments resolution: works as expected The functionality works as designed and documented. labels Apr 10, 2018
@AngelQuirogaM
Copy link

AngelQuirogaM commented Jun 11, 2018

For the ppl that still wants to get rid of it in the last versions of Angular Material (5.2.3 in my project) you can do the next:
.mat-button:focus .mat-button-focus-overlay { background-color: transparent; }

@Splaktar
Copy link
Member

@AngelQuirogaM Please submit Angular Material questions here and issues here. This repo is for AngularJS Material.

@angular angular locked as resolved and limited conversation to collaborators Jun 11, 2018
@marcysutton
Copy link
Contributor

@AngelQuirogaM the problem with that CSS is you're hiding the visible focus state, which means keyboard users can't see where we are on the screen (a huge accessibility/usability problem). It doesn't get at the core issue, which is that mouse users don't like the persistent focus state. See my above comment for a better way forward.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
- Lots of Comments resolution: works as expected The functionality works as designed and documented. ui: focus
Projects
None yet
Development

No branches or pull requests