Flow: The disabled attribute

Created on 14 Jan 2020  路  4Comments  路  Source: vaadin/flow

Why do we have setEnabled for HTML components such as div, a, span etc? It produces semantically incorrect HTML.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled

The disabled attribute is supported by <button>, <command>, <fieldset>, <keygen>, <optgroup>, <option>, <select>, <textarea> and <input>.

enhancement question

Most helpful comment

It's a good point that we could consider to not add the attribute even though we would still mark the element as disabled in our own internal bookkeeping.

Technically, this would mean that Component.onEnabledStateChanged(boolean) could be updated to be more selective, though I'm not sure exactly what would be a good default there since we also need to take into account custom elements and the fact that application themes may have CSS selectors such as div[disabled].foobar.

All 4 comments

They may have children that support disabled attribute and setEnabled enables/disables those children. This is a convenient feature.

It's a good point that we could consider to not add the attribute even though we would still mark the element as disabled in our own internal bookkeeping.

Technically, this would mean that Component.onEnabledStateChanged(boolean) could be updated to be more selective, though I'm not sure exactly what would be a good default there since we also need to take into account custom elements and the fact that application themes may have CSS selectors such as div[disabled].foobar.

One important question here is that does adding disabled attribute to e.g. div harm in any way?

Was this page helpful?
0 / 5 - 0 ratings