Derrops
Derrops

Reputation: 8137

How to achieve normal Tab behaviour in a Vaadin TextArea

I am using Vaadin and I have a TextArea, and I want the user to be able to enter Tabs into the text. But pressing tab cycles through components in a web browser. Is there any configuration I can do to achieve this so that instead of cycling the user to the next component, a literal of "\t" is entered?

Upvotes: 0

Views: 393

Answers (2)

Pete
Pete

Reputation: 280

Adding a shortcutlistener seems to work, e.g:

TextArea area = new TextArea("test")
area.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.TAB, null) {
@Override
public void handleAction(Object sender, Object target) {
    area.setValue(area.getValue() + "\t")
}
});

Upvotes: 1

agassner
agassner

Reputation: 689

The Vaadin TextArea is a simple HTML <textarea> element, which doesn't support the input of tab characters out of the box without client-side modifications. The tab character is usually used to switch focusable elements (tabindex).

You could use e.g. CodeMirror (https://vaadin.com/directory#!addon/v-codemirror) to enable a client-side code editor which can handle tab characters. A second option is to extend the Vaadin TextArea with client-side JS/GWT extensions: see Use tab to indent in textarea and https://vaadin.com/docs/-/part/framework/gwt/gwt-extension.html

Upvotes: 2

Related Questions