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

Fix buttons :focus state styles #27890

Merged
merged 14 commits into from
Apr 5, 2019

Conversation

mattez
Copy link
Contributor

@mattez mattez commented Dec 21, 2018

Small change which fix two issues:

1] Buttons :hover and :focus state shares styles now.

As you expect and as it is in BS3, :focus state is same as :hover state only extended by outline.

Before: .btn with :focus appears as normal button state with 'outline':
image
After: .btn with :focus looks like :hover state with 'outline':
image

2] Buttons :focus text color on 'a.btn' is now consistent with others '.btn'.

If you somewhere define specific color (e.g. $danger) for :focus state on <a> then ...

Before: This specific color is presented in :focus state on .btn made from <a>:
image
After: Specific color is overridden with right .btn color:
image

Buttons :hover and :focus state shares styles.
Buttons :focus text color on 'a.btn' is now consistent with others '.btn'.
@mattez mattez requested a review from a team as a code owner December 21, 2018 13:08
@MartijnCuppens
Copy link
Member

:focus styles should be in sync with .focus styles, so it might be better to copy these lines:

color: color-yiq($hover-background);
@include gradient-bg($hover-background);
border-color: $hover-border;

to:

&:focus,
&.focus {
// Avoid using mixin so we can pass custom focus shadow properly

Maybe we should add this here:
&.focus {

(wait a sec before applying any changes, would like to have a second opinion from @mdo or @ysds)

@mattez
Copy link
Contributor Author

mattez commented Dec 29, 2018

@MartijnCuppens I agree :focus must be in sync with .focus. Very good point, thank you, I missed that. I'm for copy styles to:

&:focus,
&.focus {
// Avoid using mixin so we can pass custom focus shadow properly

One idea come to my mind: If there should be always available .focus styles where is :focus across the whole Bootstrap, if this is some kind of standard, then .focus may should be added to hover mixins. Like e.g. this:

@mixin hover-focus {
&:hover,
&:focus {
@content;
}
}

to:

@mixin hover-focus { 
   &:hover, 
   &:focus,
   &.focus
   { 
     @content; 
   } 
} 

etc. The others should be changed accordingly (:active = .active).
But this is may be to much right?

I look forward to your and @mdo / @ysds views.

@mdo
Copy link
Member

mdo commented Dec 30, 2018

I’m against adding a .focus across the board. I can’t think of why we even have it on buttons honestly—everything can be done with :focus. As for :active/.active`, it’s an unfortunately named class that means “selected” more than “active”. The pairing of the names is circumstantial.

@mattez
Copy link
Contributor Author

mattez commented Jan 3, 2019

@mdo
I searched a bit, and I found a reason for the existence of the .focus class on buttons.
Historically, it has been added here #13907
Actual Button plugin still adding .focus class on focus.

So @MartijnCuppens is right - :focus should still remain in sync with .focus class. Until someone revises whether it is still needed do add .focus on focus.

So I'm going to prepare new commit where styles will be copied to :focus, .focus definition.

@MartijnCuppens
Copy link
Member

I'm not really convinced :focus and :hover states should have the same background. I like the current behaviour where I get :hover feedback when I hover a focused button. But I do like the color fix to prevent the behaviour in example 2.

I would go for adding color: color-yiq($background); to the focus state and move the hover styles under the focus block (to keep the color change on hover if needed). This would lead to the same result we have today, but it would fix the red btn in your second example.

What do you think?

@mattez
Copy link
Contributor Author

mattez commented Jan 9, 2019

1) color

Agreed. Add color: color-yiq($hover-background); to focus state.

2) background

So I tested the case when is default a styled not only with color but also background to look e.g. like:
image
("text utilities" is focused link with $danger color, $danger outline and $yellow background)

then button :focus state on .btn made from <a> looks like this:
image
so it follows that we should set some background to buttons focus state to ensure consistency of the buttons. So if you @MartijnCuppens prefer (and I agree so) to keep normal button state background, then we should add @include gradient-bg($background); to

&:focus,
&.focus {

3) border

A case where someone would add a border to link is really marginal (almost crazy? :). For demonstration it behaves as expected:
image
then button :focus state on .btn made from <a> looks like this:
image
IMHO we don't have to deal with this crazy rare case.

Summary:

I propose to add color: color-yiq($hover-background); and @include gradient-bg($background); to focus state:

&:focus,
&.focus {
	color: color-yiq($hover-background);
	@include gradient-bg($background);
	...
}

What do you think?

@XhmikosR XhmikosR changed the base branch from v4-dev to master February 19, 2019 14:08
@mattez
Copy link
Contributor Author

mattez commented Mar 6, 2019

Hello everybody who is in charge here :]. So what? @MartijnCuppens please :]

Just summarize this:

This change is only in one file /scss/mixins/_buttons.scss.
Into this focus state

&:focus,
&.focus {
// Avoid using mixin so we can pass custom focus shadow properly

adding these lines of code:

&:focus,
&.focus {
  color: color-yiq($hover-background);
  @include gradient-bg($hover-background);
  border-color: $hover-border;
  // Avoid using mixin so we can pass custom focus shadow properly

(here is diff of /scss/mixins/_buttons.scss)

to fix issues specified above in my last issuecomment ie color, background and border style.

The intent is override customized user setup for link styles (basic a href) to keep consistency of focus state of buttons made from a hrefs.

IMHO This can not hurt anyone.
What do you think?

Copy link
Member

@MartijnCuppens MartijnCuppens left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@XhmikosR XhmikosR requested a review from mdo March 27, 2019 19:06
@XhmikosR
Copy link
Member

XhmikosR commented Apr 5, 2019

@MartijnCuppens: does this need to be backported to v4?

@MartijnCuppens
Copy link
Member

Yeah, this fixes issues with focus styles. Good call @XhmikosR

@XhmikosR XhmikosR merged commit e0738f8 into twbs:master Apr 5, 2019
XhmikosR pushed a commit that referenced this pull request Apr 5, 2019
* Fix buttons :focus state styles

Buttons :hover and :focus state shares styles.
Buttons :focus text color on 'a.btn' is now consistent with others '.btn'.

* `:focus` styles should be in sync with `.focus`.

So shared styles with hover were copy to focus definition. Rather then using
`hover-focus` mixin which do not contain `.focus`.
XhmikosR pushed a commit that referenced this pull request Apr 29, 2019
* Fix buttons :focus state styles

Buttons :hover and :focus state shares styles.
Buttons :focus text color on 'a.btn' is now consistent with others '.btn'.

* `:focus` styles should be in sync with `.focus`.

So shared styles with hover were copy to focus definition. Rather then using
`hover-focus` mixin which do not contain `.focus`.
@mdo mdo mentioned this pull request Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants