Search code examples
vaadinvaadin-flowvaadin23

Vaadin: Exclude readonly fields from tabbing order


In a Vaadin 23 form there are some input fields. Some of them are read-only.

I want to exclude these read-only fields from tabbing order.

https://vaadin.com/docs/latest/components/input-fields#focus states hits:

Read-only elements cannot be edited, but they are in the tabbing order and can thus receive focus.

Is there a way to exclude read-only elements from tabbing order, but keep all other properties as-is? E.g. I'd like to keep the functionality for the user to mark the content and copy it.

Disabling the input fields (instead of setting them readonly) is not intended.


Solution

  • Setting tabindex="-1" for those fields should be enough.

    field.setTabIndex(-1);
    

    https://vaadin.com/api/platform/23.1.1/com/vaadin/flow/component/Focusable.html#setTabIndex(int)