Skip to content
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

#5709 fix: Form.Control validation both true and false #6700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/FormControl.tsx
Expand Up @@ -21,8 +21,7 @@ export interface FormControlProps
value?: string | string[] | number;
onChange?: React.ChangeEventHandler<FormControlElement>;
type?: string;
isValid?: boolean;
isInvalid?: boolean;
validState?:boolean
}

const propTypes = {
Expand Down Expand Up @@ -95,11 +94,9 @@ const propTypes = {
*/
id: PropTypes.string,

/** Add "valid" validation styles to the control */
isValid: PropTypes.bool,
/** Add "validState" validation to check if field is in a valid state. This is useful for styles to the control */
validState: PropTypes.bool,

/** Add "invalid" validation styles to the control and accompanying label */
isInvalid: PropTypes.bool,
};

const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =
Expand All @@ -112,8 +109,7 @@ const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =
htmlSize,
id,
className,
isValid = false,
isInvalid = false,
validState = true,
plaintext,
readOnly,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
Expand Down Expand Up @@ -144,8 +140,7 @@ const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =
plaintext ? `${bsPrefix}-plaintext` : bsPrefix,
size && `${bsPrefix}-${size}`,
type === 'color' && `${bsPrefix}-color`,
isValid && 'is-valid',
isInvalid && 'is-invalid',
validState ? 'is-valid' : 'is-invalid'
)}
/>
);
Expand Down