-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: convert exported modules to typescript (#599)
* fix: convert exported modules to typescript * fix: remove/ignore uncovered branches
- Loading branch information
1 parent
a552f18
commit be0b1b6
Showing
13 changed files
with
203 additions
and
165 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {isDisabled, isInstanceOfElement} from './utils' | ||
import {type} from './type' | ||
|
||
function clear(element: Element) { | ||
if ( | ||
!isInstanceOfElement(element, 'HTMLInputElement') && | ||
!isInstanceOfElement(element, 'HTMLTextAreaElement') | ||
) { | ||
// TODO: support contenteditable | ||
throw new Error( | ||
'clear currently only supports input and textarea elements.', | ||
) | ||
} | ||
const el = element as HTMLInputElement | HTMLTextAreaElement | ||
|
||
if (isDisabled(el)) { | ||
return | ||
} | ||
|
||
// TODO: track the selection range ourselves so we don't have to do this input "type" trickery | ||
// just like cypress does: https://github.com/cypress-io/cypress/blob/8d7f1a0bedc3c45a2ebf1ff50324b34129fdc683/packages/driver/src/dom/selection.ts#L16-L37 | ||
|
||
const elementType = el.type | ||
|
||
if (elementType !== 'textarea') { | ||
// setSelectionRange is not supported on certain types of inputs, e.g. "number" or "email" | ||
;(element as HTMLInputElement).type = 'text' | ||
} | ||
|
||
type(element, '{selectall}{del}', { | ||
delay: 0, | ||
initialSelectionStart: | ||
el.selectionStart ?? /* istanbul ignore next */ undefined, | ||
initialSelectionEnd: | ||
el.selectionEnd ?? /* istanbul ignore next */ undefined, | ||
}) | ||
|
||
if (elementType !== 'textarea') { | ||
;(el as HTMLInputElement).type = elementType | ||
} | ||
} | ||
|
||
export {clear} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.