Setting a button border-radius makes for focus on click - html

I'm seeing some odd behaviour concerning standard HTML buttons on Chrome. A standard button does not add an outline when clicked; only on focus through keyboard.
<button type="button">Works as expects</button>
As soon as I add styling with border-radius, the button will get an outline when clicked.
<button type="button" style="border-radius: 5px;">Focus on click</button>
Does anyone know what makes the button behave this way? And how can I make sure that the outline only gets added on keyboard navigation using the border-radius?

In response to the first part of the question:
If you right click on the round button, click inspect, and click the computed tab you can see that by adding styling it has overridden the platform-native styling:
-webkit-appearance: button;
has changed to:
-webkit-appearance: none;
the button's background-color change (when you hold down click) is also lost.

Related

How to not let accessibility focus on checkbox

We have a toggle switch implemented on top of checkbox. Checkbox is for keeping track of whether toggle switch is on or off. Everything works fine until you turn on accessibility. When accessibility is turned on & user taps on the toggle switch, the focus goes to the checkbox but it's not clickable. However, if user clicks on the label, it's clickable. I need to somehow don't let the accessibility focus come to checkbox, but still announce whether it's checked or unchecked on click of toggle switch or the label.
I have tried using tabindex & z-index to not let focus come to the checkbox but both are not making any difference. I tried using visibility:hidden. It works, but then accessibility stops announcing if checkbox is checked or not.
Our implementation :
<div class="myToggleSwitch >
::before
<inputtype="checkbox" disabled="disabled">
<label>Label for the Toggle Switch
<div class="switch" >
::before
<div class="switch-control">
</div>
::after
</div>
</label>
::after
</div>
You can use CSS to set some styles on the switch when the checkbox is focused.
For example:
.myToggleSwitch input[type="checkbox"]:focus + label .switch {
// Switch styles go here.
outline: 1px solid blue;
}
In plain English, it reads 'Find any elements with a class of "myToggleSwitch" with a focused checkbox input. Then find an adjacent label with a child element with a class of "switch" and give it a blue outline.'
And to make sure the checkbox isn't visible on the page you can do the following:
.myToggleSwitch input[type="checkbox"] {
position: absolute:
left: -1000%;
visibility: hidden;
}
That hides it and positions it off-screen so that it's still focus-able but not visible on the page.
Your HTML structure seems broken.
There is no relation between the input and it's label. Neither is the input nested inside the label, nor do you use a for attribute to link both.
The checkbox is disabled in your example code.
In that case I'm assuming you used some styling that actually does not depend on the checkbox's state? Because clicking on the label will not change the input's value in your example.

keyboard TAB selection is not visible

I have an angular application, when I use keyboard TAB to move around the elements, current focused element is not highlighting.
This is how it looks like when I TAB to an element
This is when I then click on space to expand the accordionTab
I then added the following CSS but it's working only on mouse hover BUT not on tab selection.
::ng-deep {
.ui-accordion-header:hover, .ui-accordion-header:active, .ui-accordion-header:focus {
border: solid #00a1cf 1px !important;
}
}
I had been testing, it is working when I force select focus in chrome developer tools but not when I keyboard tab select.
I am unable to figure out why its not highlighting when focused using keyboard TAB. Can anyone help me out? Thanks in advance :)
What does the markup look like? Normally when tabbing to focus the elements that have focus by default are:
a (anchors)
buttons
inputs
textareas
If you have a different type of element such as a div, you can try and give it focus by adding tabindex to your markup.

CSS-Statement to change the color of a button DURING click

I want to change the color of my button during the click. I didn't find any solution, thats why I'm asking. I don't want to change the color of the button after it was clicked. I want to change the color DURING the click (so the color the button has when you press the button). At the moment the button gets blue while pressing it. (Safari)
Thanks!
<input type="button" value="MyButton">
You might need to add :active in the CSS for your element
input[type='button']:active{
background-color:red;
}
<input type="button" value="MyButton"/>

Why default button overrides outline on focus event?

I do not know if it is a bug or not, but it seems to be.
When you have a default button and you click it when you have a :focus pseudo class it does not seem to have an outline.
#buttontag:focus {
}
<button id="buttontag" type="button">Focus me</button>
It shows the outline when you use tab key, though.
Nevertheless, it shows the outline both when clicking or using tab key on the button if you change the background-color to it.
#buttontag:focus {
background-color: #dde;
}
<button id="buttontag" type="button">Focus me</button>
But it does not work for all types of background-color. For example, it does not work for background-color: #ddd. In this case it is only shows when you use tab key.
#buttontag:focus {
background-color: #ddd;
}
<button id="buttontag" type="button">Focus me</button>
Here an screenshot when the button is focused, nothing changes.
I know that the background-color: #ddd is the same colour as the default border of the button (both on focus or not focused). I have created the following code to be sure of it.
var buttontag = document.getElementById('buttontag');
buttontag.onfocus = function(){
var border = window.getComputedStyle(buttontag).getPropertyValue("border");
alert(border);
}
var border = window.getComputedStyle(buttontag).getPropertyValue("border");
alert(border);
#buttontag:focus {
background-color: #ddd;
}
<button id="buttontag" type="button">Focus me</button>
I know that rgb(221, 221, 221) is the same as #DDDDDD on hex and that is the same as #ddd. I do not know if it has to be something related about contrast between both colours (there is no contrast because they are the same colour) and outline but it is very strange that in this background-color the outline does not appear.
More and more strange
If you inspect the default button and you force it to be focussed (I am trying on Google Chrome debugger) , it has an outline and shows it on the button. It is the default outline that appears in the rest of buttons with another background-color.
:focus {
outline: -webkit-focus-ring-color auto 5px;
}
And I also wanted to know if it was something related about forcing the button to be in focus state so I created a Javascript snippet to see what outline the button has in focus state.
var buttonFocus = document.getElementById('buttontag');
buttonFocus.onfocus = function(){
var outline = window.getComputedStyle(buttonFocus).getPropertyValue("outline");
alert(outline);
}
#buttontag:focus {
background-color: #ddd;
}
<button id="buttontag" type="button">Focus me</button>
It retrieves the default outline, but does not show it. It seems that it only shows the outline if you force the button to be focussed (on the debugger).
I have searched on the official documentation but could not find anything related about a special behaviour for default buttons or specific background-color.
So here I have some questions:
Why is the outline not displayed on the default button when you click on it?
Why with background: #ddd it is not shown also?
Why is the outline shown when you use tab and not when you click on the button (on the two cases above)?
Why the button has the outline in his CSS but it does not display it? Is it a bug?
Might be wrong.
The default button (in Google Chrome at least) uses appearance
style attribute:
button {
-webkit-appearance: button;
}
The appearance property allows you to make elements look like a
standard user interface element from your operating system. Talking about OS X, standard interface buttons do not have outline
by default.
Very easy way to check how the standard os buttons looks:
alert('I am standard button')
When you've created a button:focus pseudo-class that contained
background or border rule (example #2), you have overridden the
standard appearance by default browser style for button + your
rules.
In example #1, the button:focus is empty, and apparently it is
just ignored by the browser, hence os interface style is applied.
If you will create a style:
button { -webkit-appearance: initial; }
you will get default browser button that has outline.
Chrome's default style for button has a rule:
background-color: buttonface;
Safari and Google Chrome support custom color names that are
references to the currently used colors of user interface elements.
It might be the case, that buttonface is '#dddddd' in your system. Interesting though, as I can see the blue outline in OS X Chrome.
For the questions 3 and 4, I am afraid I cannot replicate it, as I do get outline.
Will update the answer after some research. Cheers! :)
webkit Chrome and Safari behave differently, in that they do not trigger :focus on a click event, but do on tab keyboard event.
That :focus behavior is present, especially on the button element.
So you might have to add tabindex attribute on your button element to let the browser know that this element can receive focus.
tabindex="0"
Since without that tabindex attribute, the browser sees that focus flag as being false, hence no :focus.
See W3C spec:
https://drafts.csswg.org/selectors-3/#the-user-action-pseudo-classes-hover-act
There may be document language or implementation specific limits on which elements can become :active or acquire :focus.
Also see the following regarding focused browsing context
https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context
If the attribute is omitted or parsing the value returns an error.
The user agent should follow platform conventions to determine if the element's tabindex focus flag is set and, if so, whether the element and any focusable areas that have the element as their DOM anchor can be reached using sequential focus navigation, and if so, what their relative position in the sequential focus navigation order is to be.
Modulo platform conventions, it is suggested that for the following elements, the tabindex focus flag be set:
a elements that have an href attribute
link elements that have an href attribute
button elements
You can also see this related StackOverflow question:
css focus not working in safari and chrome
button has a default style define by each browser. it might (and often is) different from browser to browser. But we can overwrite the default values to suit our needs.
Why is the outline not displayed on the default button when you click on it?
The button doesn't enter in focus state when you click. It enters the active state.
Why with background: #ddd it is not shown also?
It does show in my browser, but only when in focus. I your examples you use #ddd and #dde which are 2 very similar grays to the default gray, but once I changed the value I could see the difference.
Why is the outline shown when you use tab and not when you click on the button (on the two cases above)?
The focus state is meant to allow the user to hit the Enter/Return key to activate the button. However, the button doesn't enter the focus state one it is clicked
Why the button has the outline in his CSS but it does not display it? Is it a bug?
It is not a bug. It only displays when in focus state, which can be forced through the code inspector, via javascript or by tabbing through form elements. I used my own example declaring:
outline: 2px solid #ccc;
The focus state is very useful when trying t make the application/website accessible to screen readers for people who are visually impaired. It allows us to add more functions that can be triggered in those situations, and to guide the user through the page when looking at it isn't possible.
The default browser behavior is to show an outline only on focus (by using tab f.e.), not on click. Each browser also may have it's default outline color and width.
To avoid any funny behavior you can overwrite the outline, and also add it to a click:
#buttontag:focus, #buttontag:active {
outline: #ddd solid 2px;
}

How to remove CSS mousedown effects

I have this problem in Safari and Chrome but not in IE.
When I click a button the mousedown event triggers some kind of CSS rule which makes it slightly wider.
Because of this it drops down onto the next row and the click event is not triggered.
It stays on the next row until the mouse button is released.
I'm working on a large existing site and it's difficult to isolate all the CSS, but I think this could be due to an effect inherent in the browser(s).
Is there a CSS way to stop any effects occuring when the button is clicked?
Thanks for your help.
This is the CSS I have found for :active / :hover.
I don't think this could cause it!
a:hover, a:active
{
text-decoration: none;
}
(The button is an image inside an anchor)
Open your page with Chrome. Right click on the element and select inspect element. On the right handside corner of the inspect element handler, you will see few icons.
Click on the middle one(Which is having a arrow. When you hover it a label will display as "Toggle element State").
Change the element state to active (and to focus if it didn't change anything), and now you will be able to see what css rules are used to apply those changes to your button(It can be a padding or width).
Since now you know what the rule is, you can undo it using another rule (Or using javascript). It's hard to say how to remove the effects without knowing what the effects are.
you can declare a class in css name it for exemple abortmousedowncss :
.abortmousedowncss{
width:yourwidth; !important /* this dont allow any css to overide it ;)*/
}
and you can apply it after with jquery like this :
$('#yourbutton').addClass("abortmousedowncss");