-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear.ts
More file actions
29 lines (24 loc) · 786 Bytes
/
clear.ts
File metadata and controls
29 lines (24 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { Driver } from '../Driver.js';
import { InvalidElementState } from '../errors/InvalidElementState.js';
import { fromWebDriverElement } from '../helpers/Element.js';
import { isEditableElement } from '../helpers/isEditableElement.js';
export function clear(this: Driver, elementId: string): void {
const element = fromWebDriverElement(elementId);
if (!isEditableElement(element)) {
throw InvalidElementState('element is not editable');
}
if (element.isContentEditable) {
if (element.innerHTML !== '') {
element.focus();
element.innerHTML = '';
element.blur();
}
return;
}
const input = element as HTMLInputElement | HTMLTextAreaElement;
if (input.value) {
input.focus();
input.value = '';
input.blur();
}
}