1
0
mirror of https://github.com/uetchy/namae.git synced 2025-07-01 22:10:04 +09:00

fix: blur search field when form submitted

This commit is contained in:
uetchy 2020-07-29 18:56:05 +09:00 committed by uetchy
parent f6a1c13234
commit d6c9ad528b
2 changed files with 141 additions and 140 deletions

View File

@ -28,13 +28,6 @@ const Form: React.FC<{
setInputValue(e.currentTarget.value); setInputValue(e.currentTarget.value);
} }
// clear input form and focus on it
function onLogoClick(): void {
setInputValue('');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
inputRef.current!.focus();
}
// invoke when user clicked one of the suggested items // invoke when user clicked one of the suggested items
function onSuggestionCompleted(name: string): void { function onSuggestionCompleted(name: string): void {
setInputValue(name); setInputValue(name);
@ -44,6 +37,7 @@ const Form: React.FC<{
function onSubmitQuery(e: React.FormEvent) { function onSubmitQuery(e: React.FormEvent) {
e.preventDefault(); e.preventDefault();
(e.target as HTMLFormElement).blur();
if (!inputValue || inputValue === '') { if (!inputValue || inputValue === '') {
return; return;
} }
@ -59,9 +53,11 @@ const Form: React.FC<{
return ( return (
<InputContainer> <InputContainer>
<Logo to="/" onClick={onLogoClick}> <InputHeader>
<Logo to="/">
<LogoImage src="/logo.svg" /> <LogoImage src="/logo.svg" />
</Logo> </Logo>
</InputHeader>
<form onSubmit={onSubmitQuery} action="/s" role="search"> <form onSubmit={onSubmitQuery} action="/s" role="search">
<InputView <InputView
onChange={onInputChange} onChange={onInputChange}
@ -79,6 +75,7 @@ const Form: React.FC<{
}; };
export default Form; export default Form;
const InputContainer = styled.div` const InputContainer = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -96,12 +93,15 @@ const InputContainer = styled.div`
} }
`; `;
const Logo = styled(Link)` const InputHeader = styled.div`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
margin-bottom: 12px; justify-content: center;
margin-top: 5px; margin: 12px 0 5px 0;
`;
const Logo = styled(Link)`
cursor: pointer; cursor: pointer;
${mobile} { ${mobile} {

View File

@ -301,8 +301,9 @@ const Item = styled.div<{delay: number}>`
} }
${mobile} { ${mobile} {
margin: 10px 0 0; margin: 5px 0 0;
font-size: 1.3rem; padding-bottom: 0;
font-size: 1rem;
} }
`; `;