Skip to content

Incubator.TextField - expose retainValidationSpace #2631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/incubator/TextField/ValidationMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const ValidationMessage = ({
validationMessage,
enableErrors,
validationMessageStyle,
retainSpace,
retainValidationSpace,
validate,
testID
}: ValidationMessageProps) => {
const context = useContext(FieldContext);

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

if (!enableErrors || (!retainSpace && context.isValid)) {
if (!enableErrors || (!retainValidationSpace && context.isValid)) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions src/incubator/TextField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const TextField = (props: InternalTextFieldProps) => {
enableErrors, // TODO: rename to enableValidation
validationMessageStyle,
validationMessagePosition = ValidationMessagePosition.BOTTOM,
retainValidationSpace = true,
// Char Counter
showCharCounter,
charCounterStyle,
Expand Down Expand Up @@ -140,7 +141,7 @@ const TextField = (props: InternalTextFieldProps) => {
validate={others.validate}
validationMessage={others.validationMessage}
validationMessageStyle={_validationMessageStyle}
retainSpace={retainTopMessageSpace}
retainValidationSpace={retainValidationSpace && retainTopMessageSpace}
testID={`${props.testID}.validationMessage`}
/>
)}
Expand Down Expand Up @@ -195,7 +196,7 @@ const TextField = (props: InternalTextFieldProps) => {
validate={others.validate}
validationMessage={others.validationMessage}
validationMessageStyle={_validationMessageStyle}
retainSpace
retainValidationSpace={retainValidationSpace}
testID={`${props.testID}.validationMessage`}
/>
)}
Expand Down
6 changes: 6 additions & 0 deletions src/incubator/TextField/textField.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"description": "The position of the validation message (top/bottom)"
},
{"name": "validationMessageStyle", "type": "TextStyle", "description": "Custom style for the validation message"},
{
"name": "retainValidationSpace",
"type": "boolean",
"description": "Keep the validation space even if there is no validation message",
"default": "true"
},
{"name": "validateOnStart", "type": "boolean", "description": "Should validate when the TextField mounts"},
{"name": "validateOnChange", "type": "boolean", "description": "Should validate when the TextField value changes"},
{"name": "validateOnBlur", "type": "boolean", "description": "Should validate when losing focus of TextField"},
Expand Down
5 changes: 4 additions & 1 deletion src/incubator/TextField/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export interface ValidationMessageProps {
* Custom style for the validation message
*/
validationMessageStyle?: StyleProp<TextStyle>;
retainSpace?: boolean;
/**
* Keep the validation space even if there is no validation message
*/
retainValidationSpace?: boolean;
validate?: FieldStateProps['validate'];
testID?: string;
}
Expand Down