Skip to content

Commit

Permalink
ui v2: fix searchfield bugs (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlettperry authored Dec 14, 2020
1 parent ca43472 commit df36498
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions frontend/packages/core/src/AppLayout/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ const InputField = styled(TextField)({
background: "#e7e7ea",
},
"&:active": {
background:
"linear-gradient(0deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.85)), #0D1030;",
background: "#DBDBE0",
},
},
},
});

// search's result options container
const ResultGrid = styled(Grid)({
height: "inherit",
padding: "12px 16px 12px 16px",
});

// search's result options
const ResultLabel = styled(Typography)({
color: "#0d1030",
Expand Down Expand Up @@ -100,6 +105,7 @@ const Popper = styled(MuiPopper)({
},
".MuiAutocomplete-option": {
height: "48px",
padding: "0px",
},
".MuiAutocomplete-option[data-focus='true']": {
background: "#ebedfb",
Expand Down Expand Up @@ -168,11 +174,11 @@ interface ResultProps {
}

const Result: React.FC<ResultProps> = ({ option, handleSelection }) => (
<Grid container alignItems="center" onClick={handleSelection}>
<ResultGrid container alignItems="center" onClick={handleSelection}>
<Grid item xs>
<ResultLabel>{option.label}</ResultLabel>
</Grid>
</Grid>
</ResultGrid>
);

const filterResults = (searchOptions: SearchIndex[], state: FilterOptionsState<SearchIndex>) => {
Expand Down Expand Up @@ -239,6 +245,15 @@ const SearchField: React.FC = () => {
setOpen(false);
};

// If workflow selected by pressing enter/return,
// update the open state to collapse search bar to search icon
function handleListKeyDown(event) {
if (event.key === "Enter") {
event.preventDefault();
setOpen(false);
}
}

return (
<Grid container alignItems="center">
{open ? (
Expand All @@ -261,6 +276,7 @@ const SearchField: React.FC = () => {
popupIcon={<CustomCloseIcon />}
forcePopupIcon={!!showOptions}
noOptionsText="No results found"
onKeyDown={handleListKeyDown}
/>
</ClickAwayListener>
) : (
Expand Down

0 comments on commit df36498

Please sign in to comment.