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

Add SiteSearch Type-Ahead #332

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e9921d8
base implementation of typeahead on sitesearch bar
Foxcapades Jun 27, 2023
c8d86c5
formatting
Foxcapades Jun 27, 2023
cc9329d
in to of
Foxcapades Jun 28, 2023
752cbfd
minor style updates
Foxcapades Jun 28, 2023
c627397
remove unrelated changes from diff
Foxcapades Jun 28, 2023
df4ea5d
remove unrelated changes from diff
Foxcapades Jun 28, 2023
2f97b2e
remove unrelated changes from diff
Foxcapades Jun 28, 2023
c085807
remove unrelated changes from diff
Foxcapades Jun 28, 2023
26a0c80
remove unrelated changes from diff
Foxcapades Jun 28, 2023
ae3c1e2
remove unrelated changes from diff
Foxcapades Jun 28, 2023
e970f13
remove unrelated changes from diff
Foxcapades Jun 28, 2023
88c5736
comments
Foxcapades Jun 28, 2023
9320592
comments
Foxcapades Jun 28, 2023
8c020ad
comments
Foxcapades Jun 28, 2023
eb538b3
add box-shadow
Foxcapades Jun 28, 2023
d0dbd18
remove hardcoded url
Foxcapades Jun 28, 2023
9832345
position: relative on form
Foxcapades Jun 28, 2023
7b606ea
fix double button rounded corners
Foxcapades Jun 28, 2023
c307e11
undo unrelated diff
Foxcapades Jun 28, 2023
c871454
remove border radius default on butons
Foxcapades Jun 28, 2023
55eff25
formatting
Foxcapades Jun 29, 2023
55e96b3
fix click-out handler
Foxcapades Jun 29, 2023
83035c0
Merge branch 'main' into typeahead
Foxcapades Jun 29, 2023
5839103
add missing placeholder text
Foxcapades Jul 18, 2023
de19cd6
Merge branch 'main' into typeahead
Foxcapades Jul 18, 2023
4ebb42f
replace api client with FetchClient based class
Foxcapades Jul 18, 2023
5b360da
Merge remote-tracking branch 'origin/main' into typeahead
dmfalke Sep 1, 2023
b5cc1f8
Update styling based on changes to site search input DOM
dmfalke Sep 1, 2023
5feeac1
Merge remote-tracking branch 'origin/main' into typeahead
dmfalke Sep 6, 2023
372dfc7
Merge remote-tracking branch 'origin/main' into typeahead
dmfalke Sep 7, 2023
1279b0d
Add search history menu to site search input (#482)
dmfalke Sep 11, 2023
8e4ea27
Merge remote-tracking branch 'origin/main' into typeahead
dmfalke Sep 11, 2023
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ dist
!.yarn/releases
!.yarn/sdks
!.yarn/versions


# IDEs
.idea/
4 changes: 2 additions & 2 deletions packages/libs/web-common/src/App/Header/HeaderNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class HeaderNav extends React.Component {
maxWidth: '35em',
}}
>
<SiteSearchInput />
<SiteSearchInput siteSearchURL={siteSearchServiceUrl} />
</div>
)}
</div>
Expand Down Expand Up @@ -212,7 +212,7 @@ class HeaderNav extends React.Component {
fontSize: '1.2em',
}}
>
<SiteSearchInput />
<SiteSearchInput siteSearchURL={siteSearchServiceUrl} />
</div>
)}
<div style={{ display: 'flex' }}>
Expand Down
80 changes: 68 additions & 12 deletions packages/libs/web-common/src/components/SiteSearch/SiteSearch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
min-height: 4.25em;
align-items: center;
flex-wrap: wrap;

.PaginationMenu {
margin: auto;

Expand All @@ -89,24 +89,79 @@
align-items: flex-start;
position: relative;
}

&--SearchBox {
display: flex;
justify-content: space-between;
border-radius: 1.5em;
overflow: hidden;
position: relative;

&:focus-within {
box-shadow: 0 0 3pt 2pt #0067f4;
}

input {
border: none !important;
border-radius: 0;
padding: .4em .9em !important;
div.type-ahead {
width: 100%;
&:focus {
outline: none;

div.type-ahead-input {
position: relative;

input {
border: none !important;
border-radius: 1.5em 0 0 1.5em;
padding: 0.4em 0.9em !important;
width: 100%;

&:focus {
outline: none;
}
}

input:first-child {
position: relative;
background: #00000000 !important;
z-index: 1;
}

input:nth-child(2) {
position: absolute;
top: 0;
left: 0;
z-index: 0;
color: gray;
}
}

ul.type-ahead-hints {
margin: 0.2em 0 0 0;
padding: 0;
list-style: none;
position: absolute;
background: #ededed;
overflow: hidden;
width: 100%;
border-radius: 1em;
box-shadow: 0 0 1em rgba(0, 48, 76, 0.5);

li.type-ahead-hint {
padding: 0.2em 0 0.2em 1em;
text-align: left;

&:focus,
&:active,
&:hover {
background: #DEDEDE;
}

&:first-child {
padding-top: 0.4em;
}

&:last-child {
padding-bottom: 0.4em;
}
}

}
}

Expand All @@ -121,6 +176,10 @@
padding-left: .9em;
padding-right: 1em;

&:last-child {
border-radius: 0 1.5em 1.5em 0;
}

&:not(:last-of-type) {
border-right: 1px solid #00000042;
}
Expand Down Expand Up @@ -150,7 +209,6 @@
}
}


&--CountsContainer {
grid-area: counts;
justify-self: end;
Expand Down Expand Up @@ -431,7 +489,6 @@
background: #1345bd;
color: white;
}

}
&Text {
margin: .25em 1.5em;
Expand Down Expand Up @@ -488,4 +545,3 @@
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ import { makeClassNameHelper, wrappable } from '@veupathdb/wdk-client/lib/Utils/
import { SITE_SEARCH_ROUTE, SEARCH_TERM_PARAM, DOCUMENT_TYPE_PARAM, ORGANISM_PARAM, FILTERS_PARAM } from './SiteSearchConstants';

import './SiteSearch.scss';
import { TypeAheadInput } from './TypeAheadInput';

const cx = makeClassNameHelper("SiteSearch");

const preventEventWith = (callback: () => void) => (event: React.FormEvent) => {
event.preventDefault();
callback();
}
};

export interface Props {
placeholderText?: string;
siteSearchURL: string;
}

export const SiteSearchInput = wrappable(function ({ placeholderText }: Props) {
export const SiteSearchInput = wrappable(function ({
placeholderText,
siteSearchURL,
}: Props) {
const location = useLocation();
const history = useHistory();
const inputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -47,7 +52,7 @@ export const SiteSearchInput = wrappable(function ({ placeholderText }: Props) {
const queryString = `q=${encodeURIComponent(inputRef.current?.value || '')}`;
onSearch(queryString);
}, [ onSearch ]);

const [ lastSearchQueryString, setLastSearchQueryString] = useSessionBackedState<string>(
'',
'ebrc/site-search/last-query-string',
Expand All @@ -62,7 +67,7 @@ export const SiteSearchInput = wrappable(function ({ placeholderText }: Props) {
}, [ location ]);

return (
<form ref={formRef} action={SITE_SEARCH_ROUTE} onSubmit={preventEventWith(handleSubmitWithFilters)} className={cx("--SearchBox")}>
<form ref={formRef} action={SITE_SEARCH_ROUTE} onSubmit={preventEventWith(handleSubmitWithFilters)} className={cx("--SearchBox")} autoComplete="off">
{docType && <input type="hidden" name={DOCUMENT_TYPE_PARAM} value={docType}/>}
{organisms.map(organism => <input key={organism} type="hidden" name={ORGANISM_PARAM} value={organism}/>)}
{fields.map(field => <input key={field} type="hidden" name={FILTERS_PARAM} value={field}/>)}
Expand All @@ -71,15 +76,7 @@ export const SiteSearchInput = wrappable(function ({ placeholderText }: Props) {
<button className="reset" type="button" onClick={handleSubmitWithoutFilters}>Clear filters</button>
</Tooltip>
) : null}
<input
ref={inputRef}
type="input"
onFocus={e => e.target.select()}
name={SEARCH_TERM_PARAM}
key={searchString}
defaultValue={searchString}
placeholder={placeholderText}
/>
<TypeAheadInput siteSearchURL={siteSearchURL} inputReference={inputRef} searchString={searchString} />
{location.pathname !== SITE_SEARCH_ROUTE && lastSearchQueryString && (
<Tooltip content="Go back to your last search result">
<button className="back" type="button" onClick={() => onSearch(lastSearchQueryString)}>
Expand Down
Loading