Skip to content

Commit

Permalink
add default value to tags
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-hardman committed Oct 16, 2020
1 parent 21255da commit b2d99f0
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/components/FormElements/FormElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ export const FormInput: React.FC<FormInputProps> = ({

return (
<div className={cx([styles.formItem, className])}>

<label htmlFor={name} className={styles.label}>
{label}
</label>

<label htmlFor={name} className={styles.label}>
{label}
</label>

<input
id={name}
name={name}
Expand Down Expand Up @@ -79,11 +78,10 @@ export const FormTextArea: React.FC<FormTextAreaProps> = ({

return (
<div className={cx([styles.formItem, className])}>

<label htmlFor={name} className={styles.label}>
{label}
</label>

<label htmlFor={name} className={styles.label}>
{label}
</label>

<textarea
id={name}
name={name}
Expand Down Expand Up @@ -313,6 +311,7 @@ export const FormTagSelector: React.FC<TagSelectorProps> = ({
name,
inputClassName,
tagClassName,
defaultValue
}) => {
const { setValue, register } = useFormContext("TagSelector");

Expand Down Expand Up @@ -352,6 +351,8 @@ export const FormTagSelector: React.FC<TagSelectorProps> = ({

useEffect(() => {
register(name);
setTags(defaultValue as string[]);
setValue(name, defaultValue as string[]);
}, []);

const Tags: React.FC = () => (
Expand All @@ -364,7 +365,7 @@ export const FormTagSelector: React.FC<TagSelectorProps> = ({
aria-label={`Delete ${tag}`}
onClick={(event) => deleteTag(event, tag)}
>
<Icon name="cross" />
<Icon name="cross" />
</button>
</div>
))}
Expand All @@ -376,10 +377,7 @@ export const FormTagSelector: React.FC<TagSelectorProps> = ({
<div className={styles.label}>
<label htmlFor={name}>{label}</label>
</div>
<div
className={cx(styles.tagComponent, className)}
onClick={handleClick}
>
<div className={cx(styles.tagComponent, className)} onClick={handleClick}>
<div className={styles.tags}>
{tags && <Tags />}
<input
Expand Down

0 comments on commit b2d99f0

Please sign in to comment.