Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto resize search bar #590

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions components/SearchPageJumbotron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { useRef, useEffect, memo } from 'react';
import { useRouter } from 'next/router';
import { t } from 'ttag';
import { makeStyles, withStyles } from '@material-ui/core/styles';
import { Tabs, Tab, Box, Container } from '@material-ui/core';
import { Tabs, Tab, Box, Container, TextareaAutosize } from '@material-ui/core';
import SearchIcon from '@material-ui/icons/Search';

const useStyles = makeStyles(theme => ({
jumbotron: {
background: '#202020',
},
search: {
alignSelf: 'flex-start',
color: theme.palette.common.white,
paddingRight: theme.spacing(3),
},
Expand Down Expand Up @@ -53,6 +54,7 @@ const useStyles = makeStyles(theme => ({
outline: 'none',
color: theme.palette.common.white,
background: 'transparent',
paddingRight: theme.spacing(4),
},
submit: {
display: 'none',
Expand Down Expand Up @@ -95,7 +97,7 @@ function SearchPageJumbotron() {
});
};

const { q } = query;
const { q = '' } = query;
useEffect(() => {
textareaRef.current.value = q;
}, [q]);
Expand All @@ -109,11 +111,18 @@ function SearchPageJumbotron() {
<form onSubmit={onSearch} className={classes.form}>
<h2 className={classes.search}>{t`Searching`}</h2>
<Box flex={1} className={classes.inputArea}>
<textarea
<TextareaAutosize
ref={textareaRef}
name="search"
className={classes.input}
rows={1}
minRows={1}
onKeyDown={e => {
// enter to trigger search, so disable default line breaking
if (e.key == 'Enter') {
ydcjeff marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();
e.target.form.requestSubmit();
}
}}
/>
<button type="submit" className={classes.submit}>
<SearchIcon />
Expand Down
Loading