0

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?

Derrops
  • 7,651
  • 5
  • 30
  • 60

2 Answers2

2

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

Community
  • 1
  • 1
agassner
  • 689
  • 8
  • 25
1

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")
}
});
Pete
  • 280
  • 3
  • 7