Skip to content

Commit

Permalink
feat(components): indicate error on wrong mutation filter input #156
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Apr 24, 2024
1 parent fdf11c5 commit b5e39c7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/src/preact/mutationFilter/mutation-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const MutationFilter: FunctionComponent<MutationFilterProps> = () => {
aminoAcidInsertions: [],
});
const [inputValue, setInputValue] = useState('');
const [isError, setIsError] = useState(false);
const formRef = useRef<HTMLFormElement>(null);

const handleSubmit = (event: Event) => {
Expand All @@ -37,6 +38,7 @@ export const MutationFilter: FunctionComponent<MutationFilterProps> = () => {
const parsedMutation = parseAndValidateMutation(inputValue, referenceGenome);

if (parsedMutation === null) {
setIsError(true);
return;
}

Expand Down Expand Up @@ -76,6 +78,7 @@ export const MutationFilter: FunctionComponent<MutationFilterProps> = () => {

const handleInputChange = (event: Event) => {
setInputValue((event.target as HTMLInputElement).value);
setIsError(false);
};

return (
Expand All @@ -87,7 +90,7 @@ export const MutationFilter: FunctionComponent<MutationFilterProps> = () => {
/>

<form className='mt-2 w-full' onSubmit={handleSubmit} ref={formRef}>
<label className='input input-bordered flex items-center gap-2'>
<label className={`input flex items-center gap-2 ${isError ? 'input-error' : 'input-bordered'}`}>
<input
className='grow min-w-0'
type='text'
Expand Down

0 comments on commit b5e39c7

Please sign in to comment.