Skip to content

Commit 5f0ade6

Browse files
authored
Incubator.TextField - expose retainValidationSpace (#2631)
1 parent 45a768e commit 5f0ade6

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/incubator/TextField/ValidationMessage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const ValidationMessage = ({
99
validationMessage,
1010
enableErrors,
1111
validationMessageStyle,
12-
retainSpace,
12+
retainValidationSpace,
1313
validate,
1414
testID
1515
}: ValidationMessageProps) => {
1616
const context = useContext(FieldContext);
1717

1818
const style = useMemo(() => [styles.validationMessage, validationMessageStyle], [validationMessageStyle]);
1919

20-
if (!enableErrors || (!retainSpace && context.isValid)) {
20+
if (!enableErrors || (!retainValidationSpace && context.isValid)) {
2121
return null;
2222
}
2323

src/incubator/TextField/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const TextField = (props: InternalTextFieldProps) => {
6969
enableErrors, // TODO: rename to enableValidation
7070
validationMessageStyle,
7171
validationMessagePosition = ValidationMessagePosition.BOTTOM,
72+
retainValidationSpace = true,
7273
// Char Counter
7374
showCharCounter,
7475
charCounterStyle,
@@ -140,7 +141,7 @@ const TextField = (props: InternalTextFieldProps) => {
140141
validate={others.validate}
141142
validationMessage={others.validationMessage}
142143
validationMessageStyle={_validationMessageStyle}
143-
retainSpace={retainTopMessageSpace}
144+
retainValidationSpace={retainValidationSpace && retainTopMessageSpace}
144145
testID={`${props.testID}.validationMessage`}
145146
/>
146147
)}
@@ -195,7 +196,7 @@ const TextField = (props: InternalTextFieldProps) => {
195196
validate={others.validate}
196197
validationMessage={others.validationMessage}
197198
validationMessageStyle={_validationMessageStyle}
198-
retainSpace
199+
retainValidationSpace={retainValidationSpace}
199200
testID={`${props.testID}.validationMessage`}
200201
/>
201202
)}

src/incubator/TextField/textField.api.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
"description": "The position of the validation message (top/bottom)"
4444
},
4545
{"name": "validationMessageStyle", "type": "TextStyle", "description": "Custom style for the validation message"},
46+
{
47+
"name": "retainValidationSpace",
48+
"type": "boolean",
49+
"description": "Keep the validation space even if there is no validation message",
50+
"default": "true"
51+
},
4652
{"name": "validateOnStart", "type": "boolean", "description": "Should validate when the TextField mounts"},
4753
{"name": "validateOnChange", "type": "boolean", "description": "Should validate when the TextField value changes"},
4854
{"name": "validateOnBlur", "type": "boolean", "description": "Should validate when losing focus of TextField"},

src/incubator/TextField/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ export interface ValidationMessageProps {
112112
* Custom style for the validation message
113113
*/
114114
validationMessageStyle?: StyleProp<TextStyle>;
115-
retainSpace?: boolean;
115+
/**
116+
* Keep the validation space even if there is no validation message
117+
*/
118+
retainValidationSpace?: boolean;
116119
validate?: FieldStateProps['validate'];
117120
testID?: string;
118121
}

0 commit comments

Comments
 (0)