|
|
@@ -1,13 +1,16 @@
|
|
1
|
1
|
import React, { forwardRef, useCallback, useState } from 'react';
|
|
2
|
2
|
import {
|
|
3
|
3
|
KeyboardTypeOptions,
|
|
4
|
|
- NativeSyntheticEvent, ReturnKeyTypeOptions,
|
|
|
4
|
+ NativeSyntheticEvent,
|
|
|
5
|
+ ReturnKeyTypeOptions,
|
|
5
|
6
|
StyleProp,
|
|
6
|
7
|
Text,
|
|
7
|
8
|
TextInput,
|
|
8
|
9
|
TextInputChangeEventData,
|
|
9
|
|
- TextInputFocusEventData, TextInputKeyPressEventData,
|
|
|
10
|
+ TextInputFocusEventData,
|
|
|
11
|
+ TextInputKeyPressEventData,
|
|
10
|
12
|
TextInputSubmitEditingEventData,
|
|
|
13
|
+ TextStyle,
|
|
11
|
14
|
TouchableOpacity,
|
|
12
|
15
|
View,
|
|
13
|
16
|
ViewStyle
|
|
|
@@ -25,8 +28,16 @@ interface IProps extends IInputProps {
|
|
25
|
28
|
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters' | undefined;
|
|
26
|
29
|
autoFocus?: boolean;
|
|
27
|
30
|
blurOnSubmit?: boolean | undefined;
|
|
|
31
|
+ bottomLabel?: string;
|
|
28
|
32
|
customStyles?: ICustomStyles;
|
|
29
|
33
|
editable?: boolean | undefined;
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * The id to set on the input element.
|
|
|
37
|
+ * This is required because we need it internally to tie the input to its
|
|
|
38
|
+ * info (label, error) so that screen reader users don't get lost.
|
|
|
39
|
+ */
|
|
|
40
|
+ id?: string;
|
|
30
|
41
|
keyboardType?: KeyboardTypeOptions;
|
|
31
|
42
|
maxLength?: number | undefined;
|
|
32
|
43
|
minHeight?: number | string | undefined;
|
|
|
@@ -52,11 +63,13 @@ const Input = forwardRef<TextInput, IProps>(({
|
|
52
|
63
|
autoCapitalize,
|
|
53
|
64
|
autoFocus,
|
|
54
|
65
|
blurOnSubmit,
|
|
|
66
|
+ bottomLabel,
|
|
55
|
67
|
clearable,
|
|
56
|
68
|
customStyles,
|
|
57
|
69
|
disabled,
|
|
58
|
70
|
error,
|
|
59
|
71
|
icon,
|
|
|
72
|
+ id,
|
|
60
|
73
|
keyboardType,
|
|
61
|
74
|
label,
|
|
62
|
75
|
maxLength,
|
|
|
@@ -106,7 +119,7 @@ const Input = forwardRef<TextInput, IProps>(({
|
|
106
|
119
|
onSubmitEditing?.(text);
|
|
107
|
120
|
}, [ onSubmitEditing ]);
|
|
108
|
121
|
|
|
109
|
|
- return (<View style = { [ styles.inputContainer, customStyles?.container ] }>
|
|
|
122
|
+ return (<View style = { [ styles.inputContainer, customStyles?.container ] as StyleProp<ViewStyle> }>
|
|
110
|
123
|
{label && <Text style = { styles.label }>{ label }</Text>}
|
|
111
|
124
|
<View style = { styles.fieldContainer as StyleProp<ViewStyle> }>
|
|
112
|
125
|
{icon && <Icon
|
|
|
@@ -121,6 +134,7 @@ const Input = forwardRef<TextInput, IProps>(({
|
|
121
|
134
|
autoFocus = { autoFocus }
|
|
122
|
135
|
blurOnSubmit = { blurOnSubmit }
|
|
123
|
136
|
editable = { !disabled }
|
|
|
137
|
+ id = { id }
|
|
124
|
138
|
keyboardType = { keyboardType }
|
|
125
|
139
|
maxLength = { maxLength }
|
|
126
|
140
|
|
|
|
@@ -145,11 +159,11 @@ const Input = forwardRef<TextInput, IProps>(({
|
|
145
|
159
|
clearable && styles.clearableInput,
|
|
146
|
160
|
customStyles?.input,
|
|
147
|
161
|
disabled && styles.inputDisabled,
|
|
148
|
|
- error && styles.inputError,
|
|
149
|
|
- focused && styles.inputFocused,
|
|
150
|
162
|
icon && styles.iconInput,
|
|
151
|
|
- multiline && styles.inputMultiline
|
|
152
|
|
- ] }
|
|
|
163
|
+ multiline && styles.inputMultiline,
|
|
|
164
|
+ focused && styles.inputFocused,
|
|
|
165
|
+ error && styles.inputError
|
|
|
166
|
+ ] as StyleProp<TextStyle> }
|
|
153
|
167
|
textContentType = { textContentType }
|
|
154
|
168
|
value = { typeof value === 'number' ? `${value}` : value } />
|
|
155
|
169
|
{ clearable && !disabled && value !== '' && (
|
|
|
@@ -163,6 +177,20 @@ const Input = forwardRef<TextInput, IProps>(({
|
|
163
|
177
|
</TouchableOpacity>
|
|
164
|
178
|
)}
|
|
165
|
179
|
</View>
|
|
|
180
|
+ {
|
|
|
181
|
+ bottomLabel && (
|
|
|
182
|
+ <View>
|
|
|
183
|
+ <Text
|
|
|
184
|
+ id = { `${id}-description` }
|
|
|
185
|
+ style = { [
|
|
|
186
|
+ styles.bottomLabel,
|
|
|
187
|
+ error && styles.bottomLabelError
|
|
|
188
|
+ ] }>
|
|
|
189
|
+ { bottomLabel }
|
|
|
190
|
+ </Text>
|
|
|
191
|
+ </View>
|
|
|
192
|
+ )
|
|
|
193
|
+ }
|
|
166
|
194
|
</View>);
|
|
167
|
195
|
});
|
|
168
|
196
|
|