File tree 5 files changed +72
-7
lines changed
13.x-next/docs/api/events
5 files changed +72
-7
lines changed Original file line number Diff line number Diff line change @@ -110,4 +110,31 @@ describe('type() for managed TextInput', () => {
110
110
111
111
expect ( events ) . toMatchSnapshot ( 'input: "ABC", value: "XXX"' ) ;
112
112
} ) ;
113
+
114
+ it ( 'skips blur and endEditing events when `skipBlur: true` in managed TextInput' , async ( ) => {
115
+ const { events, logEvent } = createEventLogger ( ) ;
116
+ render ( < ManagedTextInput logEvent = { logEvent } /> ) ;
117
+
118
+ const user = userEvent . setup ( ) ;
119
+ await user . type ( screen . getByTestId ( 'input' ) , 'a' , {
120
+ skipBlur : true ,
121
+ } ) ;
122
+
123
+ const eventNames = getEventsNames ( events ) ;
124
+
125
+ // Ensure 'endEditing' and 'blur' are not present
126
+ expect ( eventNames ) . not . toContain ( 'endEditing' ) ;
127
+ expect ( eventNames ) . not . toContain ( 'blur' ) ;
128
+
129
+ // Verify the exact events that should be present
130
+ expect ( eventNames ) . toEqual ( [
131
+ 'pressIn' ,
132
+ 'focus' ,
133
+ 'pressOut' ,
134
+ 'keyPress' ,
135
+ 'change' ,
136
+ 'changeText' ,
137
+ 'selectionChange' ,
138
+ ] ) ;
139
+ } ) ;
113
140
} ) ;
Original file line number Diff line number Diff line change @@ -386,4 +386,34 @@ describe('type()', () => {
386
386
await user . type ( input , ' World' ) ;
387
387
expect ( input ) . toHaveDisplayValue ( 'Hello World' ) ;
388
388
} ) ;
389
+
390
+ it ( 'skips blur and endEditing events when `skipBlur: true`' , async ( ) => {
391
+ const { events } = renderTextInputWithToolkit ( ) ;
392
+
393
+ const user = userEvent . setup ( ) ;
394
+ await user . type ( screen . getByTestId ( 'input' ) , 'a' , {
395
+ skipBlur : true ,
396
+ } ) ;
397
+
398
+ const eventNames = getEventsNames ( events ) ;
399
+
400
+ // Ensure 'endEditing' and 'blur' are not present
401
+ expect ( eventNames ) . not . toContain ( 'endEditing' ) ;
402
+ expect ( eventNames ) . not . toContain ( 'blur' ) ;
403
+
404
+ // Verify the exact events that should be present
405
+ expect ( eventNames ) . toEqual ( [
406
+ 'pressIn' ,
407
+ 'focus' ,
408
+ 'pressOut' ,
409
+ 'keyPress' ,
410
+ 'change' ,
411
+ 'changeText' ,
412
+ 'selectionChange' ,
413
+ ] ) ;
414
+
415
+ expect ( lastEventPayload ( events , 'selectionChange' ) ) . toMatchObject ( {
416
+ nativeEvent : { selection : { start : 1 , end : 1 } } ,
417
+ } ) ;
418
+ } ) ;
389
419
} ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { parseKeys } from './parse-keys';
12
12
export interface TypeOptions {
13
13
skipPress ?: boolean ;
14
14
submitEditing ?: boolean ;
15
+ skipBlur ?: boolean ;
15
16
}
16
17
17
18
export async function type (
@@ -67,9 +68,10 @@ export async function type(
67
68
dispatchEvent ( element , 'submitEditing' , EventBuilder . TextInput . submitEditing ( finalText ) ) ;
68
69
}
69
70
70
- dispatchEvent ( element , 'endEditing' , EventBuilder . TextInput . endEditing ( finalText ) ) ;
71
-
72
- dispatchEvent ( element , 'blur' , EventBuilder . Common . blur ( ) ) ;
71
+ if ( ! options ?. skipBlur ) {
72
+ dispatchEvent ( element , 'endEditing' , EventBuilder . TextInput . endEditing ( finalText ) ) ;
73
+ dispatchEvent ( element , 'blur' , EventBuilder . Common . blur ( ) ) ;
74
+ }
73
75
}
74
76
75
77
type EmitTypingEventsContext = {
Original file line number Diff line number Diff line change 86
86
element : ReactTestInstance ,
87
87
text : string ,
88
88
options ?: {
89
- skipPress?: boolean
90
- submitEditing ?: boolean
89
+ skipPress?: boolean ;
90
+ skipBlur ?: boolean ;
91
+ submitEditing ?: boolean ;
91
92
}
92
93
` ` `
93
94
@@ -109,6 +110,7 @@ This function will add text to the text already present in the text input (as sp
109
110
### Options {#type-options}
110
111
111
112
- ` skipPress ` - if true, ` pressIn ` and ` pressOut ` events will not be triggered.
113
+ - ` skipBlur ` - if true, ` endEditing ` and ` blur ` events will not be triggered when typing is complete.
112
114
- ` submitEditing ` - if true, ` submitEditing ` event will be triggered after typing the text.
113
115
114
116
### Sequence of events {#type-sequence}
@@ -140,6 +142,7 @@ The `pressIn` and `pressOut` events are sent by default but can be skipped by pa
140
142
- ` blur `
141
143
142
144
The ` submitEditing ` event is skipped by default. It can sent by setting the ` submitEditing : true ` option.
145
+ The ` endEditing ` and ` blur ` events can be skipped by passing the ` skipBlur : true ` option.
143
146
144
147
## ` clear ()`
145
148
Original file line number Diff line number Diff line change 80
80
element : ReactTestInstance ,
81
81
text : string ,
82
82
options ?: {
83
- skipPress?: boolean
84
- submitEditing ?: boolean
83
+ skipPress?: boolean ;
84
+ skipBlur ?: boolean ;
85
+ submitEditing ?: boolean ;
85
86
}
86
87
` ` `
87
88
@@ -103,6 +104,7 @@ This function will add text to the text already present in the text input (as sp
103
104
### Options {#type-options}
104
105
105
106
- ` skipPress ` - if true, ` pressIn ` and ` pressOut ` events will not be triggered.
107
+ - ` skipBlur ` - if true, ` endEditing ` and ` blur ` events will not be triggered when typing is complete.
106
108
- ` submitEditing ` - if true, ` submitEditing ` event will be triggered after typing the text.
107
109
108
110
### Sequence of events {#type-sequence}
@@ -134,6 +136,7 @@ The `pressIn` and `pressOut` events are sent by default but can be skipped by pa
134
136
- ` blur `
135
137
136
138
The ` submitEditing ` event is skipped by default. It can sent by setting the ` submitEditing : true ` option.
139
+ The ` endEditing ` and ` blur ` events can be skipped by passing the ` skipBlur : true ` option.
137
140
138
141
## ` clear ()`
139
142
You can’t perform that action at this time.
0 commit comments