eclipsesource / eclipsesource/tabris-js
Provide a way to preprocess input of TextInput
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 171
- PR merge metrics
- No merged PRs in 30d
Description
### Problem description
Currently, it is not easily possible to modify the TextInput text during input. Changing the `"text"` property on input would not work as expected, since the selection would reset to the last position. Another possibility would be to manually set the selection after changing `"text"`:
```js
new TextInput({
top: 20, left: '20%', right: '20%',
message: 'Type here, then confirm'
}).on('input', ({text, target}) => {
let oldSelection = target.selection;
target.text = text.toUpperCase();
target.selection = oldSelection;
}).appendTo(ui.contentView);
```
However, this approach has some side effects. For example, on Android the input would be laggy when setting the `"selection"` after each character is input. Also, holding backspace to delete a whole word does not work.
### Expected behavior
There should be an API to intercept and seamlessly modify the user input before it is rendered in the TextInput. This would enable use cases like enforcing caps or lowercase (`autoCapitalize` sets the Shift key mode, but the Shift key mode can be manually changed by the user), prohibiting characters and normalizing the input in other ways.
### Environment
- Tabris.js version: 2.x, 3.x
Contributor guide
Assessment
This issue has not been assessed yet.