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:
parent
f6a1c13234
commit
d6c9ad528b
@ -28,13 +28,6 @@ const Form: React.FC<{
|
||||
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
|
||||
function onSuggestionCompleted(name: string): void {
|
||||
setInputValue(name);
|
||||
@ -44,6 +37,7 @@ const Form: React.FC<{
|
||||
|
||||
function onSubmitQuery(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
(e.target as HTMLFormElement).blur();
|
||||
if (!inputValue || inputValue === '') {
|
||||
return;
|
||||
}
|
||||
@ -59,9 +53,11 @@ const Form: React.FC<{
|
||||
|
||||
return (
|
||||
<InputContainer>
|
||||
<Logo to="/" onClick={onLogoClick}>
|
||||
<InputHeader>
|
||||
<Logo to="/">
|
||||
<LogoImage src="/logo.svg" />
|
||||
</Logo>
|
||||
</InputHeader>
|
||||
<form onSubmit={onSubmitQuery} action="/s" role="search">
|
||||
<InputView
|
||||
onChange={onInputChange}
|
||||
@ -79,6 +75,7 @@ const Form: React.FC<{
|
||||
};
|
||||
|
||||
export default Form;
|
||||
|
||||
const InputContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@ -96,12 +93,15 @@ const InputContainer = styled.div`
|
||||
}
|
||||
`;
|
||||
|
||||
const Logo = styled(Link)`
|
||||
const InputHeader = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
margin-top: 5px;
|
||||
justify-content: center;
|
||||
margin: 12px 0 5px 0;
|
||||
`;
|
||||
|
||||
const Logo = styled(Link)`
|
||||
cursor: pointer;
|
||||
|
||||
${mobile} {
|
||||
|
@ -301,8 +301,9 @@ const Item = styled.div<{delay: number}>`
|
||||
}
|
||||
|
||||
${mobile} {
|
||||
margin: 10px 0 0;
|
||||
font-size: 1.3rem;
|
||||
margin: 5px 0 0;
|
||||
padding-bottom: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
`;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user