Skip to content

Commit

Permalink
fix(form-field): add required prop
Browse files Browse the repository at this point in the history
  • Loading branch information
morewings committed Jul 27, 2024
1 parent ae8fb0d commit 488ea06
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/FormField/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import classes from './FormField.module.css';
export type Props = DataAttributes &
LibraryProps & {
children: ReactElement;
/** Set text label */
label: string;
/** Set hint text to be displayed below input */
hint?: string;
/**
* Renders * character after label indicating required input status.
* Also set automatically when required input provided.
*/
required?: boolean;
};

export const FormField = forwardRef<HTMLDivElement, Props>(
({className, children, label, hint, ...nativeProps}, ref) => {
({className, children, label, hint, required, ...nativeProps}, ref) => {
const inputProps = Children.only(children).props;
const id = useInternalId(inputProps.id);
const childrenWithProps = inputProps.id
Expand All @@ -24,7 +31,9 @@ export const FormField = forwardRef<HTMLDivElement, Props>(
return (
<div {...nativeProps} ref={ref} className={classNames(classes.wrapper, className)}>
<label
className={classNames(classes.label, {[classes.required]: inputProps.required})}
className={classNames(classes.label, {
[classes.required]: inputProps.required || required,
})}
htmlFor={id}>
{label}
</label>
Expand Down

0 comments on commit 488ea06

Please sign in to comment.