-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pc/modals: FormErrorMessage that always takes up space (#2379)
- Loading branch information
1 parent
13a90a1
commit 327a6e1
Showing
4 changed files
with
41 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Box, | ||
FormErrorMessage as ChakraFormErrorMessage, | ||
forwardRef, | ||
useFormControlContext, | ||
} from "@fidesui/react"; | ||
|
||
/** | ||
* This is a thin wrapper around Chakra's FormErrorMessage that leaves room for the error message | ||
* even when the field is valid. This prevents the form from changing height when validation runs, | ||
* which can be annoying on blur. | ||
* | ||
* Chakra Source: | ||
* https://github.com/chakra-ui/chakra-ui/blob/%40chakra-ui/react%401.8.8/packages/form-control/src/form-error.tsx | ||
*/ | ||
export const FormErrorMessage: typeof ChakraFormErrorMessage = forwardRef( | ||
(props, ref) => { | ||
const field = useFormControlContext(); | ||
if (!field?.isInvalid) { | ||
return <Box mt={2} minH={4} />; | ||
} | ||
|
||
return <ChakraFormErrorMessage ref={ref} {...props} />; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters