@tamagui/react-native-web-lite 1.130.4 → 1.130.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/cjs/ActivityIndicator/__tests__/index-test.cjs +1 -1
  2. package/dist/cjs/ActivityIndicator/index.cjs +1 -1
  3. package/dist/cjs/AppRegistry/AppContainer.cjs +1 -1
  4. package/dist/cjs/AppRegistry/__tests__/index-test.cjs +1 -1
  5. package/dist/cjs/AppRegistry/__tests__/index-test.node.cjs +2 -2
  6. package/dist/cjs/AppRegistry/index.cjs +1 -1
  7. package/dist/cjs/AppRegistry/renderApplication.cjs +2 -2
  8. package/dist/cjs/AppState/__tests__/index-test.cjs +1 -1
  9. package/dist/cjs/DeviceEmitter.cjs +1 -1
  10. package/dist/cjs/DeviceInfo/index.cjs +1 -1
  11. package/dist/cjs/Dimensions/__tests__/index-test.cjs +1 -1
  12. package/dist/cjs/FlatList.cjs +4 -4
  13. package/dist/cjs/Image/index.cjs +3 -3
  14. package/dist/cjs/ImageBackground/__tests__/index-test.cjs +2 -2
  15. package/dist/cjs/ImageBackground/index.cjs +2 -2
  16. package/dist/cjs/InteractionManager/index.cjs +3 -3
  17. package/dist/cjs/KeyboardAvoidingView/index.cjs +1 -1
  18. package/dist/cjs/Linking/__tests__/index-test.cjs +1 -1
  19. package/dist/cjs/Modal/ModalAnimation.cjs +1 -1
  20. package/dist/cjs/Modal/ModalContent.cjs +1 -1
  21. package/dist/cjs/PanResponder/index.cjs +1 -1
  22. package/dist/cjs/PixelRatio/index.cjs +1 -1
  23. package/dist/cjs/Pressable/index.cjs +1 -1
  24. package/dist/cjs/RefreshControl/index.cjs +1 -1
  25. package/dist/cjs/SafeAreaView/index.cjs +1 -1
  26. package/dist/cjs/ScrollView/ScrollViewBase.cjs +1 -1
  27. package/dist/cjs/ScrollView/index.cjs +3 -3
  28. package/dist/cjs/SectionList.cjs +1 -1
  29. package/dist/cjs/Text/index.cjs +1 -1
  30. package/dist/cjs/TextInput/index.cjs +1 -1
  31. package/dist/cjs/TouchableNativeFeedback.cjs +1 -1
  32. package/dist/cjs/TouchableOpacity.cjs +1 -1
  33. package/dist/cjs/UnimplementedView.cjs +1 -1
  34. package/dist/cjs/View/index.cjs +1 -1
  35. package/dist/cjs/VirtualizedList.cjs +1 -1
  36. package/dist/cjs/createElement/__tests__/index-test.cjs +1 -1
  37. package/dist/cjs/index.cjs +47 -47
  38. package/dist/cjs/useColorScheme/index.cjs +1 -1
  39. package/dist/cjs/useWindowDimensions/index.cjs +1 -1
  40. package/dist/cjs/vendor/react-native/Animated/Animated.cjs +8 -8
  41. package/dist/cjs/vendor/react-native/Animated/AnimatedEvent.cjs +3 -3
  42. package/dist/cjs/vendor/react-native/Animated/AnimatedImplementation.cjs +19 -19
  43. package/dist/cjs/vendor/react-native/Animated/AnimatedMock.cjs +8 -8
  44. package/dist/cjs/vendor/react-native/Animated/Easing.cjs +1 -1
  45. package/dist/cjs/vendor/react-native/Animated/NativeAnimatedHelper.cjs +6 -6
  46. package/dist/cjs/vendor/react-native/Animated/NativeAnimatedModule.cjs +1 -1
  47. package/dist/cjs/vendor/react-native/Animated/NativeAnimatedTurboModule.cjs +1 -1
  48. package/dist/cjs/vendor/react-native/Animated/animations/Animation.cjs +1 -1
  49. package/dist/cjs/vendor/react-native/Animated/animations/DecayAnimation.cjs +2 -2
  50. package/dist/cjs/vendor/react-native/Animated/animations/SpringAnimation.cjs +3 -3
  51. package/dist/cjs/vendor/react-native/Animated/animations/TimingAnimation.cjs +3 -3
  52. package/dist/cjs/vendor/react-native/Animated/components/AnimatedFlatList.cjs +2 -2
  53. package/dist/cjs/vendor/react-native/Animated/components/AnimatedImage.cjs +2 -2
  54. package/dist/cjs/vendor/react-native/Animated/components/AnimatedScrollView.cjs +2 -2
  55. package/dist/cjs/vendor/react-native/Animated/components/AnimatedSectionList.cjs +2 -2
  56. package/dist/cjs/vendor/react-native/Animated/components/AnimatedText.cjs +2 -2
  57. package/dist/cjs/vendor/react-native/Animated/components/AnimatedView.cjs +2 -2
  58. package/dist/cjs/vendor/react-native/Animated/createAnimatedComponent.cjs +2 -2
  59. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedAddition.cjs +3 -3
  60. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedColor.cjs +3 -3
  61. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedDiffClamp.cjs +2 -2
  62. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedDivision.cjs +4 -4
  63. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedInterpolation.cjs +2 -2
  64. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedModulo.cjs +2 -2
  65. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedMultiplication.cjs +3 -3
  66. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedNode.cjs +1 -1
  67. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedProps.cjs +4 -4
  68. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedStyle.cjs +4 -4
  69. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedSubtraction.cjs +3 -3
  70. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedTracking.cjs +3 -3
  71. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedTransform.cjs +3 -3
  72. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedValue.cjs +3 -3
  73. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedValueXY.cjs +2 -2
  74. package/dist/cjs/vendor/react-native/Animated/nodes/AnimatedWithChildren.cjs +2 -2
  75. package/dist/cjs/vendor/react-native/Animated/useAnimatedProps.cjs +4 -4
  76. package/dist/cjs/vendor/react-native/EventEmitter/NativeEventEmitter.cjs +1 -1
  77. package/dist/cjs/vendor/react-native/EventEmitter/RCTDeviceEventEmitter.cjs +1 -1
  78. package/dist/cjs/vendor/react-native/FlatList/index.cjs +4 -4
  79. package/dist/cjs/vendor/react-native/JSEventLoopWatchdog/index.cjs +1 -1
  80. package/dist/cjs/vendor/react-native/SectionList/index.cjs +1 -1
  81. package/dist/cjs/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.cjs +2 -2
  82. package/dist/cjs/vendor/react-native/VirtualizedList/VirtualizedListContext.cjs +1 -1
  83. package/dist/cjs/vendor/react-native/VirtualizedList/index.cjs +9 -9
  84. package/dist/cjs/vendor/react-native/VirtualizedSectionList/index.cjs +1 -1
  85. package/dist/cjs/vendor/react-native/emitter/EventEmitter.cjs +1 -1
  86. package/dist/cjs/vendor/react-native/emitter/_EmitterSubscription.cjs +1 -1
  87. package/dist/cjs/vendor/react-native/emitter/_EventEmitter.cjs +2 -2
  88. package/dist/cjs/without-animated.cjs +48 -48
  89. package/package.json +13 -9
  90. package/src/TextInput/__tests__/index-test.tsx +0 -679
@@ -1,679 +0,0 @@
1
- /**
2
- * Copyright (c) Nicolas Gallagher.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import { render } from '@testing-library/react'
9
- import { createEventTarget } from 'dom-event-testing-library'
10
- import React from 'react'
11
- import { act } from 'react-dom/test-utils'
12
-
13
- import TextInput from '..'
14
-
15
- function findInput(container) {
16
- return container.querySelector('input')
17
- }
18
-
19
- function findTextArea(container) {
20
- return container.querySelector('textarea')
21
- }
22
-
23
- const testIfDocumentIsFocused = (message, fn) => {
24
- if (document.hasFocus && document.hasFocus()) {
25
- test(message, fn)
26
- } else {
27
- test.skip(`${message} – document is not focused`, () => {})
28
- }
29
- }
30
-
31
- function createEvent(type, data = {}) {
32
- const event = document.createEvent('CustomEvent')
33
- event.initCustomEvent(type, true, true)
34
- if (data != null) {
35
- Object.keys(data).forEach((key) => {
36
- const value = data[key]
37
- if (key === 'timeStamp' && !value) {
38
- return
39
- }
40
- Object.defineProperty(event, key, { value })
41
- })
42
- }
43
- return event
44
- }
45
-
46
- function createKeyboardEvent(
47
- type,
48
- {
49
- altKey = false,
50
- ctrlKey = false,
51
- isComposing = false,
52
- key = '',
53
- keyCode = 0,
54
- metaKey = false,
55
- preventDefault = () => {},
56
- shiftKey = false,
57
- } = {}
58
- ) {
59
- return createEvent(type, {
60
- altKey,
61
- ctrlKey,
62
- isComposing,
63
- key,
64
- keyCode,
65
- metaKey,
66
- preventDefault,
67
- shiftKey,
68
- })
69
- }
70
-
71
- function keydown(payload) {
72
- return createKeyboardEvent('keydown', payload)
73
- }
74
-
75
- describe('components/TextInput', () => {
76
- describe('prop "autoComplete"', () => {
77
- test('value "on"', () => {
78
- const { container } = render(<TextInput />)
79
- const input = findInput(container)
80
- expect(input.getAttribute('autoComplete')).toEqual('on')
81
- })
82
-
83
- test('value "off"', () => {
84
- const { container } = render(<TextInput autoComplete="off" />)
85
- const input = findInput(container)
86
- expect(input.getAttribute('autoComplete')).toEqual('off')
87
- })
88
-
89
- test('autoCompleteType fallback', () => {
90
- const { container } = render(<TextInput autoCompleteType="off" />)
91
- const input = findInput(container)
92
- expect(input.getAttribute('autoComplete')).toEqual('off')
93
- })
94
- })
95
-
96
- describe('prop "autoFocus"', () => {
97
- test('value "false"', () => {
98
- const { container } = render(<TextInput />)
99
- const input = findInput(container)
100
- expect(document.activeElement).not.toBe(input)
101
- })
102
-
103
- test('value "true"', () => {
104
- const { container } = render(<TextInput autoFocus />)
105
- const input = findInput(container)
106
- expect(document.activeElement).toBe(input)
107
- })
108
- })
109
-
110
- describe('prop "clearTextOnFocus"', () => {
111
- const defaultValue = 'defaultValue'
112
-
113
- testIfDocumentIsFocused('value "false"', () => {
114
- const { container } = render(<TextInput defaultValue={defaultValue} />)
115
- const input = findInput(container)
116
- input.focus()
117
- expect(input.node.value).toEqual(defaultValue)
118
- })
119
-
120
- testIfDocumentIsFocused('value "true"', () => {
121
- const { container } = render(
122
- <TextInput clearTextOnFocus defaultValue={defaultValue} />
123
- )
124
- const input = findInput(container)
125
- input.focus()
126
- expect(input.node.value).toEqual('')
127
- })
128
- })
129
-
130
- test('prop "defaultValue"', () => {
131
- const defaultValue = 'defaultValue'
132
- const { container } = render(<TextInput defaultValue={defaultValue} />)
133
- const input = findInput(container)
134
- expect(input.value).toEqual(defaultValue)
135
- })
136
-
137
- describe('prop "disabled"', () => {
138
- test('value "false"', () => {
139
- const { container } = render(<TextInput />)
140
- const input = findInput(container)
141
- expect(input.disabled).toEqual(false)
142
- })
143
-
144
- test('value "true"', () => {
145
- const { container } = render(<TextInput disabled={true} />)
146
- const input = findInput(container)
147
- expect(input.disabled).toEqual(true)
148
- })
149
- })
150
-
151
- describe('prop "editable"', () => {
152
- test('value "true"', () => {
153
- const { container } = render(<TextInput />)
154
- const input = findInput(container)
155
- expect(input.readOnly).toEqual(false)
156
- })
157
-
158
- test('value "false"', () => {
159
- const { container } = render(<TextInput editable={false} />)
160
- const input = findInput(container)
161
- expect(input.readOnly).toEqual(true)
162
- })
163
- })
164
-
165
- describe('prop "keyboardType"', () => {
166
- test('default value', () => {
167
- const { container } = render(<TextInput keyboardType="default" />)
168
- const input = findInput(container)
169
- expect(input.type).toEqual('text')
170
- })
171
-
172
- test('value "email-address"', () => {
173
- const { container } = render(<TextInput keyboardType="email-address" />)
174
- const input = findInput(container)
175
- expect(input.type).toEqual('email')
176
- })
177
-
178
- test('value "decimal-pad"', () => {
179
- const { container } = render(<TextInput keyboardType="decimal-pad" />)
180
- const input = findInput(container)
181
- expect(input.inputMode).toEqual('decimal')
182
- })
183
-
184
- test('value "number-pad"', () => {
185
- const { container } = render(<TextInput keyboardType="number-pad" />)
186
- const input = findInput(container)
187
- expect(input.inputMode).toEqual('numeric')
188
- })
189
-
190
- test('value "numeric"', () => {
191
- const { container } = render(<TextInput keyboardType="numeric" />)
192
- const input = findInput(container)
193
- expect(input.inputMode).toEqual('numeric')
194
- })
195
-
196
- test('value "phone-pad"', () => {
197
- const { container } = render(<TextInput keyboardType="phone-pad" />)
198
- const input = findInput(container)
199
- expect(input.type).toEqual('tel')
200
- })
201
-
202
- test('value "url"', () => {
203
- const { container } = render(<TextInput keyboardType="url" />)
204
- const input = findInput(container)
205
- expect(input.type).toEqual('url')
206
- })
207
- })
208
-
209
- test('prop "maxLength"', () => {
210
- let { container } = render(<TextInput />)
211
- let input = findInput(container)
212
- expect(input.getAttribute('maxLength')).toEqual(null)
213
- ;({ container } = render(<TextInput maxLength={10} />))
214
- input = findInput(container)
215
- expect(input.getAttribute('maxLength')).toEqual('10')
216
- })
217
-
218
- describe('prop "multiline"', () => {
219
- test('value "false"', () => {
220
- const { container } = render(<TextInput />)
221
- const input = findInput(container)
222
- expect(input).toBeDefined()
223
- })
224
-
225
- test('value "true"', () => {
226
- const { container } = render(<TextInput multiline />)
227
- const textarea = findTextArea(container)
228
- expect(textarea).toBeDefined()
229
- })
230
- })
231
-
232
- describe('prop "numberOfLines"', () => {
233
- test('without "multiline"', () => {
234
- const { container } = render(<TextInput numberOfLines={2} />)
235
- const input = findInput(container)
236
- const textarea = findTextArea(container)
237
- expect(input).toBeDefined()
238
- expect(textarea).toBeNull()
239
- })
240
-
241
- test('with "multiline"', () => {
242
- const { container } = render(<TextInput multiline numberOfLines={3} />)
243
- const textarea = findTextArea(container)
244
- expect(textarea.getAttribute('rows')).toEqual('3')
245
- })
246
- })
247
-
248
- test('prop "onBlur"', () => {
249
- const onBlur = jest.fn()
250
- const ref = React.createRef()
251
- act(() => {
252
- render(<TextInput onBlur={onBlur} ref={ref} />)
253
- })
254
- const target = createEventTarget(ref.current)
255
- const body = createEventTarget(document.body)
256
- act(() => {
257
- target.focus()
258
- body.focus({ relatedTarget: target.node })
259
- })
260
- expect(onBlur).toHaveBeenCalledTimes(1)
261
- expect(TextInput.State.currentlyFocusedField()).toBe(null)
262
- })
263
-
264
- test.skip('prop "onChange"', () => {
265
- const onChange = jest.fn()
266
- const { container } = render(<TextInput onChange={onChange} />)
267
- const input = findInput(container)
268
- // This doesn't cause ReactDOM to trigger 'change' event... ¯\_(ツ)_/¯
269
- input.dispatchEvent(new window.Event('change', { bubbles: true }))
270
- expect(onChange).toHaveBeenCalledTimes(1)
271
- })
272
-
273
- test.skip('prop "onChangeText"', () => {
274
- const onChangeText = jest.fn()
275
- const { container } = render(<TextInput onChangeText={onChangeText} />)
276
- const input = findInput(container)
277
- // This doesn't cause ReactDOM to trigger 'change' event... ¯\_(ツ)_/¯
278
- input.dispatchEvent(keydown({ key: 'a' }))
279
- input.dispatchEvent(new window.Event('change', { bubbles: true }))
280
- expect(onChangeText).toHaveBeenCalledTimes(1)
281
- expect(onChangeText).toBeCalledWith('a')
282
- })
283
-
284
- test('prop "onFocus"', () => {
285
- const onFocus = jest.fn()
286
- const ref = React.createRef()
287
- act(() => {
288
- render(<TextInput onFocus={onFocus} ref={ref} />)
289
- })
290
- const target = createEventTarget(ref.current)
291
- act(() => {
292
- target.focus()
293
- })
294
- expect(onFocus).toHaveBeenCalledTimes(1)
295
- target.node.focus()
296
- expect(TextInput.State.currentlyFocusedField()).toBe(target.node)
297
- })
298
-
299
- describe('prop "onKeyPress"', () => {
300
- test('arrow key', () => {
301
- const onKeyPress = jest.fn((e) => {
302
- e.persist()
303
- })
304
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
305
- const input = findInput(container)
306
- input.dispatchEvent(keydown({ key: 'ArrowLeft' }))
307
- expect(onKeyPress).toHaveBeenCalledTimes(1)
308
- expect(onKeyPress).toBeCalledWith(
309
- expect.objectContaining({
310
- nativeEvent: expect.objectContaining({
311
- altKey: false,
312
- ctrlKey: false,
313
- key: 'ArrowLeft',
314
- metaKey: false,
315
- shiftKey: false,
316
- target: expect.anything(),
317
- }),
318
- })
319
- )
320
- })
321
-
322
- test('backspace key', () => {
323
- const onKeyPress = jest.fn((e) => {
324
- e.persist()
325
- })
326
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
327
- const input = findInput(container)
328
- input.dispatchEvent(keydown({ key: 'Backspace' }))
329
- expect(onKeyPress).toHaveBeenCalledTimes(1)
330
- expect(onKeyPress).toBeCalledWith(
331
- expect.objectContaining({
332
- nativeEvent: expect.objectContaining({
333
- altKey: false,
334
- ctrlKey: false,
335
- key: 'Backspace',
336
- metaKey: false,
337
- shiftKey: false,
338
- target: expect.anything(),
339
- }),
340
- })
341
- )
342
- })
343
-
344
- test('enter key', () => {
345
- const onKeyPress = jest.fn((e) => {
346
- e.persist()
347
- })
348
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
349
- const input = findInput(container)
350
- input.dispatchEvent(keydown({ key: 'Enter' }))
351
- expect(onKeyPress).toHaveBeenCalledTimes(1)
352
- expect(onKeyPress).toBeCalledWith(
353
- expect.objectContaining({
354
- nativeEvent: expect.objectContaining({
355
- altKey: false,
356
- ctrlKey: false,
357
- key: 'Enter',
358
- metaKey: false,
359
- shiftKey: false,
360
- target: expect.anything(),
361
- }),
362
- })
363
- )
364
- })
365
-
366
- test('escape key', () => {
367
- const onKeyPress = jest.fn((e) => {
368
- e.persist()
369
- })
370
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
371
- const input = findInput(container)
372
- input.dispatchEvent(keydown({ key: 'Escape' }))
373
- expect(onKeyPress).toHaveBeenCalledTimes(1)
374
- expect(onKeyPress).toBeCalledWith(
375
- expect.objectContaining({
376
- nativeEvent: expect.objectContaining({
377
- altKey: false,
378
- ctrlKey: false,
379
- key: 'Escape',
380
- metaKey: false,
381
- shiftKey: false,
382
- target: expect.anything(),
383
- }),
384
- })
385
- )
386
- })
387
-
388
- test('space key', () => {
389
- const onKeyPress = jest.fn((e) => {
390
- e.persist()
391
- })
392
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
393
- const input = findInput(container)
394
- input.dispatchEvent(keydown({ key: ' ' }))
395
- expect(onKeyPress).toHaveBeenCalledTimes(1)
396
- expect(onKeyPress).toBeCalledWith(
397
- expect.objectContaining({
398
- nativeEvent: expect.objectContaining({
399
- altKey: false,
400
- ctrlKey: false,
401
- key: ' ',
402
- metaKey: false,
403
- shiftKey: false,
404
- target: expect.anything(),
405
- }),
406
- })
407
- )
408
- })
409
-
410
- test('tab key', () => {
411
- const onKeyPress = jest.fn((e) => {
412
- e.persist()
413
- })
414
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
415
- const input = findInput(container)
416
- input.dispatchEvent(keydown({ key: 'Tab' }))
417
- expect(onKeyPress).toHaveBeenCalledTimes(1)
418
- expect(onKeyPress).toBeCalledWith(
419
- expect.objectContaining({
420
- nativeEvent: expect.objectContaining({
421
- altKey: false,
422
- ctrlKey: false,
423
- key: 'Tab',
424
- metaKey: false,
425
- shiftKey: false,
426
- target: expect.anything(),
427
- }),
428
- })
429
- )
430
- })
431
-
432
- test('text key', () => {
433
- const onKeyPress = jest.fn((e) => {
434
- e.persist()
435
- })
436
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
437
- const input = findInput(container)
438
- input.dispatchEvent(keydown({ key: 'a' }))
439
- expect(onKeyPress).toHaveBeenCalledTimes(1)
440
- expect(onKeyPress).toBeCalledWith(
441
- expect.objectContaining({
442
- nativeEvent: expect.objectContaining({
443
- altKey: false,
444
- ctrlKey: false,
445
- key: 'a',
446
- metaKey: false,
447
- shiftKey: false,
448
- target: expect.anything(),
449
- }),
450
- })
451
- )
452
- })
453
-
454
- test('modifier keys are included', () => {
455
- const onKeyPress = jest.fn((e) => {
456
- e.persist()
457
- })
458
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
459
- const input = findInput(container)
460
- input.dispatchEvent(
461
- keydown({
462
- altKey: true,
463
- ctrlKey: true,
464
- metaKey: true,
465
- shiftKey: true,
466
- key: ' ',
467
- })
468
- )
469
- expect(onKeyPress).toHaveBeenCalledTimes(1)
470
- expect(onKeyPress).toBeCalledWith(
471
- expect.objectContaining({
472
- nativeEvent: expect.objectContaining({
473
- altKey: true,
474
- ctrlKey: true,
475
- key: ' ',
476
- metaKey: true,
477
- shiftKey: true,
478
- target: expect.anything(),
479
- }),
480
- })
481
- )
482
- })
483
-
484
- test('meta key + Enter calls "onKeyPress"', () => {
485
- const onKeyPress = jest.fn((e) => {
486
- e.persist()
487
- })
488
- const { container } = render(<TextInput onKeyPress={onKeyPress} />)
489
- const input = findInput(container)
490
- input.dispatchEvent(
491
- keydown({
492
- metaKey: true,
493
- key: 'Enter',
494
- })
495
- )
496
- expect(onKeyPress).toHaveBeenCalledTimes(1)
497
- })
498
- })
499
-
500
- describe('prop "onSelectionChange"', () => {
501
- test('is called on select', () => {
502
- const { container } = render(
503
- <TextInput defaultValue="12345" onSelectionChange={onSelectionChange} />
504
- )
505
- const input = findInput(container)
506
- input.selectionStart = 0
507
- input.selectionEnd = 3
508
- input.dispatchEvent(new window.Event('select', {}))
509
- function onSelectionChange(e) {
510
- expect(e.nativeEvent.selection.end).toEqual(3)
511
- expect(e.nativeEvent.selection.start).toEqual(0)
512
- }
513
- })
514
-
515
- test.skip('is called on change', () => {
516
- const onSelectionChange = jest.fn()
517
- const { container } = render(<TextInput onSelectionChange={onSelectionChange} />)
518
- const input = findInput(container)
519
- // This doesn't cause ReactDOM to trigger 'change' event... ¯\_(ツ)_/¯
520
- input.dispatchEvent(new window.Event('input', { bubbles: true }))
521
- expect(onSelectionChange).toHaveBeenCalledTimes(1)
522
- })
523
- })
524
-
525
- describe('prop "onSubmitEditing"', () => {
526
- test('single-line input', (done) => {
527
- const { container } = render(
528
- <TextInput defaultValue="12345" onSubmitEditing={onSubmitEditing} />
529
- )
530
- const input = findInput(container)
531
- input.dispatchEvent(keydown({ key: 'Enter' }))
532
- function onSubmitEditing(e) {
533
- expect(e.nativeEvent.target).toBeDefined()
534
- expect(e.nativeEvent.text).toBe('12345')
535
- done()
536
- }
537
- })
538
-
539
- test('single-line input while composing', () => {
540
- const onSubmitEditing = jest.fn()
541
- const { container } = render(
542
- <TextInput defaultValue="12345" onSubmitEditing={onSubmitEditing} />
543
- )
544
- const input = findInput(container)
545
- input.dispatchEvent(keydown({ key: 'Enter', isComposing: true, keyCode: 13 }))
546
- input.dispatchEvent(keydown({ key: 'Enter', isComposing: false, keyCode: 229 }))
547
- expect(onSubmitEditing).not.toHaveBeenCalled()
548
- })
549
-
550
- test('multi-line input', () => {
551
- const onSubmitEditing = jest.fn()
552
- const { container } = render(
553
- <TextInput defaultValue="12345" multiline onSubmitEditing={onSubmitEditing} />
554
- )
555
- const textarea = findTextArea(container)
556
- textarea.dispatchEvent(keydown({ key: 'Enter' }))
557
- expect(onSubmitEditing).not.toHaveBeenCalled()
558
- })
559
-
560
- test('multi-line input with "blurOnSubmit" triggers "onSubmitEditing"', () => {
561
- const onSubmitEditing = jest.fn()
562
- const preventDefault = jest.fn()
563
-
564
- const { container } = render(
565
- <TextInput
566
- blurOnSubmit
567
- defaultValue="12345"
568
- multiline
569
- onSubmitEditing={onSubmitEditing}
570
- />
571
- )
572
- const textarea = findTextArea(container)
573
- textarea.dispatchEvent(keydown({ key: 'Enter', preventDefault, shiftKey: true }))
574
- // shift+enter should enter newline, not submit
575
- expect(onSubmitEditing).not.toHaveBeenCalledWith(
576
- expect.objectContaining({ shiftKey: true })
577
- )
578
- expect(preventDefault).not.toHaveBeenCalled()
579
-
580
- textarea.dispatchEvent(keydown({ key: 'Enter', preventDefault }))
581
- expect(onSubmitEditing).toHaveBeenCalledTimes(1)
582
- expect(preventDefault).toHaveBeenCalledTimes(1)
583
- })
584
- })
585
-
586
- test('prop "returnKeyType"', () => {
587
- const returnKeyType = 'previous'
588
- const { container } = render(<TextInput returnKeyType={returnKeyType} />)
589
- const input = findInput(container)
590
- expect(input.getAttribute('enterkeyhint')).toEqual(returnKeyType)
591
- })
592
-
593
- test('prop "secureTextEntry"', () => {
594
- let { container } = render(<TextInput secureTextEntry />)
595
- const input = findInput(container)
596
- expect(input.getAttribute('type')).toEqual('password')
597
- // ignored for multiline
598
- ;({ container } = render(<TextInput multiline secureTextEntry />))
599
- const textarea = findTextArea(container)
600
- expect(textarea.getAttribute('type')).toEqual(null)
601
- })
602
-
603
- describe('prop "selectTextOnFocus"', () => {
604
- testIfDocumentIsFocused('value "false"', () => {
605
- const { container } = render(<TextInput defaultValue={'text'} />)
606
- const input = findInput(container)
607
- input.focus()
608
- expect(input.selectionEnd).toEqual(4)
609
- expect(input.selectionStart).toEqual(4)
610
- })
611
-
612
- // testIfDocumentIsFocused('value "true"', () => {
613
- // const input = findNativeInput(mount(<TextInput defaultValue={'text'} selectTextOnFocus />));
614
- // input.node.focus()
615
- // assert.equal(input.node.selectionEnd, 4)
616
- // assert.equal(input.node.selectionStart, 0)
617
- // });
618
- })
619
-
620
- describe('prop "selection"', () => {
621
- test('set cursor location', () => {
622
- const cursorLocation = { start: 3, end: 3 }
623
- const { container: defaultContainer } = render(<TextInput defaultValue="12345" />)
624
- const inputDefaultSelection = findInput(defaultContainer)
625
- // default selection is at the end
626
- expect(inputDefaultSelection.selectionStart).toEqual(5)
627
- expect(inputDefaultSelection.selectionEnd).toEqual(5)
628
-
629
- const { container: customContainer } = render(
630
- <TextInput defaultValue="12345" selection={cursorLocation} />
631
- )
632
- const inputCustomSelection = findInput(customContainer)
633
- // custom selection sets cursor at custom position
634
- expect(inputCustomSelection.selectionStart).toEqual(cursorLocation.start)
635
- expect(inputCustomSelection.selectionEnd).toEqual(cursorLocation.end)
636
- })
637
- })
638
-
639
- describe('prop "spellCheck"', () => {
640
- test('default value', () => {
641
- const { container } = render(<TextInput />)
642
- const input = findInput(container)
643
- expect(input.getAttribute('spellCheck')).toEqual('true')
644
- })
645
-
646
- test('inherit from "autoCorrect"', () => {
647
- const { container } = render(<TextInput autoCorrect={false} />)
648
- const input = findInput(container)
649
- expect(input.getAttribute('spellCheck')).toEqual('false')
650
- })
651
-
652
- test('value "false"', () => {
653
- const { container } = render(<TextInput spellCheck={false} />)
654
- const input = findInput(container)
655
- expect(input.getAttribute('spellCheck')).toEqual('false')
656
- })
657
- })
658
-
659
- test('prop "value"', () => {
660
- const value = 'value'
661
- const { container } = render(<TextInput value={value} />)
662
- const input = findInput(container)
663
- expect(input.value).toEqual(value)
664
- })
665
-
666
- describe('imperative methods', () => {
667
- test('node.clear()', () => {
668
- const ref = React.createRef()
669
- render(<TextInput ref={ref} />)
670
- expect(typeof ref.current.clear).toBe('function')
671
- })
672
-
673
- test('node.isFocused()', () => {
674
- const ref = React.createRef()
675
- render(<TextInput ref={ref} />)
676
- expect(typeof ref.current.isFocused).toBe('function')
677
- })
678
- })
679
- })