vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
454 stars 83 forks source link

Make disabled components focusable and hoverable #4585

Open rolfsmeds opened 2 years ago

rolfsmeds commented 2 years ago

What is the problem?

Disabled components currently have tabindex="-1", which removes them from the keyboard tab order, making them effectively un-focusable, and, as a side-effect, makes them effectively invisible to assistive technologies, thus bad for accessibility.

The disabled state also applies the pointer-events:none css property, which disables hover/mouseover based functionality such as tooltips. This is unfortunate especially as tooltips are a convenient way to inform the user why a component (e.g. a Button) is disabled. Removing this would require some additional css and js to handle the pointer-inertness of the component, but enabled tooltip usage.

Ideally this behavior would be configurable via a feature flag or a global property, so that applications for which it is desired to keep the current behavior could easily revert back to it.

Browsers

Screen Readers

knoobie commented 2 years ago

aria-disabled='true' could still be applied, which could be used as styling attribute and helps sreenreaders to know that this button is disabled. See e.g. Aria-disabled or How can I make a disabled button focusable, clickable, in general “interact-able”?

rolfsmeds commented 2 years ago

Actually, unless I'm mistaken, we don't even have to remove the disabled attribute on the root element, as that has no effect on custom elements.

web-padawan commented 2 years ago

Yes, we still need to keep disabled for styling and to ensure that e.g. setDisableOnClick(true) works as expected. Also, we need to ensure that click events would not fire on disabled elements (maybe stop propagation for them).

web-padawan commented 1 year ago

This issue would also be relevant for vaadin-tooltip as users might want to use it with disabled components:

The current workaround would be to wrap disabled component in a different element and set a tooltip for it.

TatuLund commented 1 year ago

Just noting, that e.g. with buttons, it is possible to override the style using this in styles.css

vaadin-button[disabled] {
   pointer-events: auto;
}
jouni commented 1 year ago

it is possible to override the style using this in styles.css

An unwanted side-effect of that is that disabled button will then apply :hover and [active] styles, making them appear clickable.

enver-haase commented 1 year ago

Just noting, that e.g. with buttons, it is possible to override the style using this in styles.css

Horrible UX (open/close flicker) with Select as well, so not a generically viable solution.

enver-haase commented 1 year ago

Having said that. @TatuLund 's idea seems to work really well for one customer of mine. They claim they have tested a huge range of components with the events enabled along the implementation above. Only Select, for them, exposed an unwanted flicker. Maybe an implementation with pointer events being enabled is not as hard as we think (bar the testing).