Rework the search field behavior in the sidebar

We just tested it with another user an noticed some more issues:
* If the user is on the search route it should be reflected in the sidebar
* Clicking on the search icon alone should lead to the search page
This commit is contained in:
Oliver Sand
2020-11-20 16:20:13 +01:00
parent c587fa2089
commit 36b9dfd41c
2 changed files with 10 additions and 4 deletions
+9 -3
View File
@@ -26,7 +26,6 @@ import { IconComponent } from '@backstage/core-api';
import SearchIcon from '@material-ui/icons/Search';
import clsx from 'clsx';
import React, {
FC,
useContext,
useState,
KeyboardEventHandler,
@@ -212,9 +211,10 @@ export const SidebarItem = forwardRef<any, SidebarItemProps>(
type SidebarSearchFieldProps = {
onSearch: (input: string) => void;
to?: string;
};
export const SidebarSearchField: FC<SidebarSearchFieldProps> = props => {
export const SidebarSearchField = (props: SidebarSearchFieldProps) => {
const [input, setInput] = useState('');
const classes = useStyles();
@@ -229,12 +229,18 @@ export const SidebarSearchField: FC<SidebarSearchFieldProps> = props => {
setInput(ev.target.value);
};
const handleClick = (ev: React.MouseEvent<HTMLInputElement>) => {
// Clicking into the search fields shouldn't navigate to the search page
ev.preventDefault();
};
return (
<div className={classes.searchRoot}>
<SidebarItem icon={SearchIcon}>
<SidebarItem icon={SearchIcon} to={props.to}>
<TextField
placeholder="Search"
value={input}
onClick={handleClick}
onChange={handleInput}
onKeyDown={handleEnter}
className={classes.searchContainer}
@@ -31,5 +31,5 @@ export const SidebarSearch = () => {
[navigate],
);
return <SidebarSearchField onSearch={handleSearch} />;
return <SidebarSearchField onSearch={handleSearch} to="/search" />;
};