@@ -2,9 +2,9 @@ import {dispatchUIEvent} from '../event'
2
2
import { Config } from '../setup'
3
3
import { prepareSelectionInterceptor } from './selection'
4
4
import {
5
+ clearInitialValue ,
5
6
getInitialValue ,
6
7
prepareValueInterceptor ,
7
- setInitialValue ,
8
8
} from './value'
9
9
10
10
const isPrepared = Symbol ( 'Node prepared with document state workarounds' )
@@ -45,8 +45,11 @@ export function prepareDocument(document: Document) {
45
45
e => {
46
46
const el = e . target as HTMLInputElement
47
47
const initialValue = getInitialValue ( el )
48
- if ( typeof initialValue === 'string' && el . value !== initialValue ) {
49
- dispatchUIEvent ( { } as Config , el , 'change' )
48
+ if ( initialValue !== undefined ) {
49
+ if ( el . value !== initialValue ) {
50
+ dispatchUIEvent ( { } as Config , el , 'change' )
51
+ }
52
+ clearInitialValue ( el )
50
53
}
51
54
} ,
52
55
{
@@ -59,10 +62,6 @@ export function prepareDocument(document: Document) {
59
62
}
60
63
61
64
function prepareElement ( el : Node | HTMLInputElement ) {
62
- if ( 'value' in el ) {
63
- setInitialValue ( el )
64
- }
65
-
66
65
if ( el [ isPrepared ] ) {
67
66
return
68
67
}
@@ -75,6 +74,12 @@ function prepareElement(el: Node | HTMLInputElement) {
75
74
el [ isPrepared ] = isPrepared
76
75
}
77
76
78
- export { getUIValue , setUIValue , startTrackValue , endTrackValue } from './value'
77
+ export {
78
+ getUIValue ,
79
+ setUIValue ,
80
+ startTrackValue ,
81
+ endTrackValue ,
82
+ clearInitialValue ,
83
+ } from './value'
79
84
export { getUISelection , setUISelection } from './selection'
80
85
export type { UISelectionRange } from './selection'
0 commit comments