nice search functionality
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Box, styled, Typography } from '@mui/material';
|
import { Box, Typography } from '@mui/material';
|
||||||
import { blueGrey } from '@mui/material/colors';
|
import { blueGrey } from '@mui/material/colors';
|
||||||
|
|
||||||
export default function KeyboardShortcutLabel({ label }: { label: string }) {
|
export default function KeyboardShortcutLabel({ label }: { label: string }) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useCallback, useRef } from 'react';
|
||||||
|
|
||||||
import { Container } from '@mui/system';
|
import { Container } from '@mui/system';
|
||||||
import { Avatar, Box, Grid, Input, Stack, Typography } from '@mui/material';
|
import { Avatar, Box, Grid, Input, Stack, Typography } from '@mui/material';
|
||||||
@@ -7,10 +7,20 @@ import { blueGrey } from '@mui/material/colors';
|
|||||||
import { FiSearch } from 'react-icons/fi';
|
import { FiSearch } from 'react-icons/fi';
|
||||||
import KeyboardShortcutLabel from './KeyboardShortcutLabel';
|
import KeyboardShortcutLabel from './KeyboardShortcutLabel';
|
||||||
import { useSnackbar } from 'notistack';
|
import { useSnackbar } from 'notistack';
|
||||||
|
import { useKey } from 'react-use';
|
||||||
|
|
||||||
export default function Terminal() {
|
export default function Terminal() {
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
|
const searchRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const onSearch = useCallback(() => {
|
||||||
|
enqueueSnackbar('search focused');
|
||||||
|
if (searchRef?.current) searchRef.current.focus();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useKey('Tab', onSearch);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={0}>
|
<Grid container spacing={0}>
|
||||||
<Grid
|
<Grid
|
||||||
@@ -56,7 +66,7 @@ export default function Terminal() {
|
|||||||
>
|
>
|
||||||
<FiSearch style={{ color: blueGrey[500] }} />
|
<FiSearch style={{ color: blueGrey[500] }} />
|
||||||
|
|
||||||
<Input placeholder={'Find or start a conversation'} />
|
<Input placeholder={'Find or start a conversation'} inputRef={searchRef} />
|
||||||
|
|
||||||
<KeyboardShortcutLabel label="tab" />
|
<KeyboardShortcutLabel label="tab" />
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
Reference in New Issue
Block a user