Skip to content

Commit

Permalink
feat(app-signup): add empty option in SelectInput
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Dec 31, 2020
1 parent 2389fbe commit 4ea0e1d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ type Props = {
onChange: React.ChangeEventHandler<HTMLSelectElement>;
disabled?: boolean;
errorMessage?: string | null;
emptyOption?: boolean;
emptyOptionLabel?: string;
};

const SelectInput: React.FC<Props> = ({ value, name, label, onChange, options, errorMessage, disabled }) => {
const SelectInput: React.FC<Props> = ({
value,
name,
label,
onChange,
options,
errorMessage,
disabled,
emptyOption,
emptyOptionLabel,
}) => {
return (
<div className="column">
<label htmlFor={name}>{label}</label>
<div className="row">
{emptyOption && emptyOptionLabel ? (
<option key="" value="">
{emptyOptionLabel}
</option>
) : null}
<select disabled={disabled || options.length === 0} name={name} id={name} value={value} onChange={onChange}>
{options.map(o => {
const value = typeof o === 'string' ? o : o.value;
Expand Down
6 changes: 5 additions & 1 deletion packages/game-app/src/_shared/form/FormSelect/FormSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const FormSelect: React.FC<Props> = ({ name, label, options, disabled }) => {
}
}, [error, t]);

const emptyOptionLabel = t('general.emptyOptionLabel');

const renderInput = useCallback(
(props: ControllerRenderProps) => {
return (
Expand All @@ -31,10 +33,12 @@ const FormSelect: React.FC<Props> = ({ name, label, options, disabled }) => {
onChange={props.onChange}
disabled={disabled}
errorMessage={translatedError}
emptyOption
emptyOptionLabel={emptyOptionLabel}
/>
);
},
[translatedError, label, options, disabled],
[translatedError, label, options, disabled, emptyOptionLabel],
);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/game-app/src/assets/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const translations = {
errors: {
required: 'This field is required',
},
emptyOptionLabel: 'Select an option',
},
};

Expand Down
8 changes: 7 additions & 1 deletion packages/game-app/src/signup/components/Signup/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ type Props = {};

const Signup: React.FC<Props> = () => {
const methods = useForm<SignupInfo>({
defaultValues: {},
defaultValues: {
role: '',
email: '',
password: '',
devOpsMaturity: '',
repeatPassword: '',
},
mode: 'onBlur',
resolver: yupResolver(signupValidationSchema),
});
Expand Down

0 comments on commit 4ea0e1d

Please sign in to comment.