(element: Element)
| 37 | // bot.action.clear left behind in Firefox kept the caret alive in Firefox 3. |
| 38 | // - The IE range-input and blur branches are gone. |
| 39 | function clear(element: Element): void { |
| 40 | if (!isInteractable(element)) { |
| 41 | throw botError(ELEMENT_NOT_INTERACTABLE, 'Element is not currently interactable and may not be manipulated') |
| 42 | } |
| 43 | if (!isEditable(element)) { |
| 44 | throw botError(INVALID_ELEMENT_STATE, 'Element must be user-editable in order to clear it.') |
| 45 | } |
| 46 | |
| 47 | if (isContentEditable(element)) { |
| 48 | if (element.textContent || element.children.length) { |
| 49 | focusOnElement(element) |
| 50 | element.textContent = '' |
| 51 | fire(element, EventType.INPUT, { inputType: 'deleteContentBackward', data: null }) |
| 52 | unfocus(element) |
| 53 | } |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | const field = element as TextField |
| 58 | const badInput = !!(field as HTMLInputElement).validity?.badInput |
| 59 | if (field.value || badInput) { |
| 60 | focusOnElement(field) |
| 61 | field.value = '' |
| 62 | fire(field, EventType.INPUT, { inputType: 'deleteContentBackward', data: null }) |
| 63 | fire(field, EventType.CHANGE, undefined) |
| 64 | unfocus(field) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Focusing the body cannot take focus, so this blurs whatever has it. |
| 69 | function unfocus(element: Element): void { |
nothing calls this directly
no test coverage detected