Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibility issue when button is disables/enabled

I am facing accessibility issue when my button is enabled/disabled: Below is my angular form:

<form>
<input type="text" id="UserName">
<input type="text" id="Password">
<button type="submit" [disabled]="conditions">
</form>

Here my button is disabled on the condition if nothing is entered inside my input fields. How can I convey to user that my button is disabled as focus can't be put on disabled button. Do I actually need to convey to user about disabled button and convey when it is enabled.

like image 819
Nitesh Rana Avatar asked Sep 21 '26 09:09

Nitesh Rana


1 Answers

Do I actually need to convey to user about disabled button and convey when it is enabled.

That's largely up to you. The information is already conveyed by the user agent (visual ones show the button in a "grey" or similar look; non-visual ones report it other ways).

How can I convey to user that my button is disabled...

This is also up to you. If you want to include a message after it saying something, and only show that when the button is disabled, that's easy enough with HTML and CSS using the next sibling combinator (+):

<button type="submit" [disabled]="conditions">button text</button>
<span class="show-on-disable">your text here</span>

CSS:

.show-on-disable {
    display: none;
}
button[disabled] + .show-on-disable {
    display: inline;
}

Live Example:

document.querySelector("input[type=checkbox]").addEventListener("change", function() {
  var btn = document.querySelector("button");
  btn.disabled = !btn.disabled;
});
.show-on-disable {
    display: none;
}
button[disabled] + .show-on-disable {
    display: inline;
}
<div>
  <label>
    <input type="checkbox">
    Disable the button
  </label>
</div>
<button type="submit">button</button>
<span class="show-on-disable">your text here</span>
like image 194
T.J. Crowder Avatar answered Sep 24 '26 06:09

T.J. Crowder