diff --git a/web-frontend/src/elements/basic/Input.tsx b/web-frontend/src/elements/basic/Input.tsx index 0087e23..664ab9a 100644 --- a/web-frontend/src/elements/basic/Input.tsx +++ b/web-frontend/src/elements/basic/Input.tsx @@ -3,6 +3,7 @@ import './Input.scss'; import { ChangeEvent, CSSProperties, + KeyboardEvent, RefObject, useCallback, useMemo, @@ -10,7 +11,9 @@ import { type InputProps = { type: React.HTMLInputTypeAttribute; - onChange: Function; + // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-explicit-any + onChange: (value: any) => void; + onKeyDown: () => void; defaultValue?: string | number; label?: string; min?: number; @@ -26,6 +29,7 @@ type InputProps = { function Input({ type, onChange, + onKeyDown, defaultValue, label, min, @@ -50,6 +54,15 @@ function Input({ [onChange, type], ); + const handleOnKeyDown = useCallback( + (e: KeyboardEvent) => { + if (e.key === 'Enter') { + onKeyDown(); + } + }, + [onKeyDown], + ); + return useMemo( () => (
@@ -58,6 +71,7 @@ function Input({ ref={ref} type={type} onChange={handleOnChange} + onKeyDown={handleOnKeyDown} defaultValue={defaultValue} placeholder={placeholder} min={min} @@ -77,6 +91,7 @@ function Input({ defaultValue, fontStyle, handleOnChange, + handleOnKeyDown, inputWidth, label, max, diff --git a/web-frontend/src/elements/routes/pages/accession/Accession.tsx b/web-frontend/src/elements/routes/pages/accession/Accession.tsx index 182fbbd..efa6e9a 100644 --- a/web-frontend/src/elements/routes/pages/accession/Accession.tsx +++ b/web-frontend/src/elements/routes/pages/accession/Accession.tsx @@ -58,6 +58,13 @@ function Accession() { setIsRequesting(false); }, []); + const handleOnClick = useCallback(() => { + navigate({ + pathname: routes.accession.path, + search: `?${createSearchParams({ id: accession })}`, + }); + }, [accession, navigate]); + const recordView = useMemo( () => record ? ( @@ -86,16 +93,12 @@ function Accession() { defaultValue={accession && accession !== '' ? accession : undefined} label="Search for accession: " onChange={(acc: string) => setAccession(acc.trim())} + onKeyDown={handleOnClick} inputWidth="300px" />
), - [accession, isRequesting, navigate, recordView], + [accession, handleOnClick, isRequesting, recordView], ); return accessionView;