Files
ladybird/Tests/LibWeb/Text/input/DOM/FormAssociatedElement-selection.html
Jelle Raaijmakers 814ca3267e LibWeb: Implement input/textarea selection APIs
For both types of elements, `.selectionStart`, `.selectionEnd`,
`.selectionDirection`, `.setSelectionRange()`, `.select()` and the
`select` event are now implemented.
2024-08-27 07:11:50 -04:00

47 lines
1.6 KiB
HTML

<input type="text" id="text-input">
<input type="date" id="date-input">
<textarea id="textarea">some
text</textarea>
<script src="../include.js"></script>
<script>
test(() => {
let textInput = document.getElementById('text-input');
let dateInput = document.getElementById('date-input');
let textarea = document.getElementById('textarea');
const dumpSelection = (element) => {
println(`${element.id} selectionStart: ${element.selectionStart} selectionEnd: ${element.selectionEnd} selectionDirection: ${element.selectionDirection}`);
};
dumpSelection(textInput);
dumpSelection(dateInput);
dumpSelection(textarea);
textInput.value = 'Well hello friends';
dumpSelection(textInput);
try {
dateInput.selectionStart = 0;
} catch (e) {
println(`date input setting selectionStart error: ${e}`);
}
textInput.addEventListener('select', e => println(`select event fired: ${e.target.selectionStart} ${e.target.selectionEnd}`))
textInput.select();
dumpSelection(textInput);
textInput.setSelectionRange(2, 4, 'forward');
dumpSelection(textInput);
textInput.selectionStart = 1;
dumpSelection(textInput);
textInput.selectionEnd = 5;
dumpSelection(textInput);
textInput.selectionStart = 6;
dumpSelection(textInput);
textInput.selectionDirection = 'backward';
dumpSelection(textInput);
textarea.select();
dumpSelection(textarea);
});
</script>