MCPcopy Create free account
hub / github.com/testing-library/user-event / commitValueAfterInput

Function commitValueAfterInput

src/document/trackValue.ts:59–85  ·  view source on GitHub ↗
(
  element: HTMLInputElement | HTMLTextAreaElement,
  cursorOffset: number,
)

Source from the content-addressed store, hash-verified

57}
58
59export function commitValueAfterInput(
60 element: HTMLInputElement | HTMLTextAreaElement,
61 cursorOffset: number,
62) {
63 const changes = element[TrackChanges]
64
65 element[TrackChanges] = undefined
66
67 if (!changes?.tracked?.length) {
68 return
69 }
70
71 const isJustReactStateUpdate =
72 changes.tracked.length === 2 &&
73 changes.tracked[0] === changes.previousValue &&
74 changes.tracked[1] === element.value
75
76 if (!isJustReactStateUpdate) {
77 setUIValueClean(element)
78 }
79
80 if (hasUISelection(element)) {
81 setUISelection(element, {
82 focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length,
83 })
84 }
85}

Callers 1

commitInputFunction · 0.90

Calls 3

setUIValueCleanFunction · 0.90
hasUISelectionFunction · 0.90
setUISelectionFunction · 0.90

Tested by

no test coverage detected