Created
April 15, 2022 16:05
-
-
Save reyronald/bcddc9a861b95869dadbde61c6e51b92 to your computer and use it in GitHub Desktop.
This one moves the user's cursor within a text input.
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
export function moveCursorWithinInput(input, position) { | |
if (input.setSelectionRange) { | |
input.focus(); | |
input.setSelectionRange(position, position); | |
} else if (input.createTextRange) { | |
var range = input.createTextRange(); | |
range.collapse(true); | |
range.moveEnd('character', position); | |
range.moveStart('character', position); | |
range.select(); | |
} | |
} | |
// SOURCE: https://www.joshwcomeau.com/react/file-structure/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment