Closed tarekoraby closed 4 years ago
The workaround via a JavaScript call works though:
button.getElement().executeJs("this.setAttribute('role', 'custom-role')");
Couldn't reproduce this with v14 branch of skeleton-starter-flow-spring Added
textField.getElement().setAttribute("myAttribute", "value");
button.getElement().setAttribute("myAttribute", "value");
To MainView.java
and attribute is correctly added to both elements.
Can't be reproduced, closing
It is working for any attribute, except "role".
@tarekoraby is referencing this in
The workaround via a JavaScript call works though:
button.getElement().executeJs("this.setAttribute('role', 'custom-role')");
Maybe the heading of the issue could be more specified to the role attribute.
It is working for any attribute, except "role".
@DavidKoenig that's true. I had a discussion about this with @alvarezguille earlier today and we wondering if you could please elaborate a bit on your use case: Why do you need to override the 'role' attribute?
Please also note, that getElement().setAttribute('role', 'custom-role')
should only affect the <vaadin-button>
element, not the <button>
one embedded within. So, if the aim is to alter the latter, then something like this JS call would be necessary perhaps:
button.getElement().executeJs("this.shadowRoot.getElementById('button').setAttribute('role','custom-role')");
I think we should disallow using custom role
attribute for accessibility reasons.
In future we might change this and remove role="button"
from the host element, while also removing role="presentation"
from the native button, as it seems to causes problems in some cases.
See https://github.com/vaadin/vaadin-button/issues/96#issuecomment-579758891
@tarekoraby We wanted to change the attribute on the <vaadin-button>
and inner <button>
for accessibility reasons, but our assumption was wrong and the Vaadin implementation is correct.
Nevertheless a better documentation about attributes that you can't change on certain components, like the button or the items in a MenuBar, would be nice. Otherwise you always wonder why you can't change attributes on one component via element api but not on the other.
getElement().setAttribute() isn't working if called upon the Button's attachment (it seems to work if called later).
To reproduce:
Expected: 'myAttribute' is added to the button, however, no such attribute is added upon inspection.
Tried in a Vaadin 14.3.7 + Spring boot project