Skip to content

Commit 28ce1a6

Browse files
CG-4370 improve autocomplete (#31)
- made some small changes
2 parents 3bd8017 + e4ab03e commit 28ce1a6

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

samples/musicfestival-frontend-react/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"@graphql-codegen/typescript": "^2.7.3",
1010
"@graphql-codegen/typescript-operations": "^2.5.3",
1111
"@graphql-codegen/typescript-react-query": "^4.0.1",
12-
"@mui/material": "^5.13.3",
1312
"@tanstack/react-query": "^4.6.0",
1413
"@testing-library/jest-dom": "^5.14.1",
1514
"@testing-library/react": "^13.0.0",

samples/musicfestival-frontend-react/src/App.css

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/musicfestival-frontend-react/src/components/SearchButton.tsx

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Autocomplete, TextField } from "@mui/material";
21
import { useState } from "react";
32
import { useSearchParams } from "react-router-dom";
43
import { ArtistAutocompleteQuery, useArtistAutocompleteQuery } from "../generated";
@@ -31,7 +30,7 @@ function SearchButton(): JSX.Element {
3130

3231
function onValueChange(event: any){
3332
setSearchValue(event.target.value);
34-
event.target.value != "" && event.target.value !== undefined ? setIsShown(true) : setIsShown(false);
33+
event.target.value !== undefined ? setIsShown(true) : setIsShown(false);
3534
}
3635

3736
function onAutoClick(event: any){
@@ -41,51 +40,39 @@ function SearchButton(): JSX.Element {
4140

4241
return (
4342
<div>
44-
<div className="nav-table-cell">
45-
<input className="search-input" type="text" id="search-input" placeholder="Search"
46-
onKeyPress={(event) => {search(event, 'keypress')}} value={searchValue} onChange={onValueChange} />
43+
<div className="nav-table-cell autocomplete">
44+
<input className="search-input"
45+
type="text"
46+
id="search-input"
47+
placeholder="Search"
48+
onKeyPress={(event) => {search(event, 'keypress')}}
49+
value={searchValue}
50+
onChange={onValueChange}
51+
onFocus={() => setIsShown(true)}
52+
onBlur={() =>
53+
setTimeout(() => {
54+
setIsShown(false);
55+
}, 150)
56+
} />
4757
<a className="search-icon" onClick={(event) => {search(event, 'buttonclick')}}>
4858
<i className="fa fa-search"></i>
4959
</a>
50-
51-
{/* <Autocomplete
52-
sx={{
53-
display: 'inline-block',
54-
'& input': {
55-
width: 200,
56-
bgcolor: 'background.paper',
57-
color: (theme) =>
58-
theme.palette.getContrastText(theme.palette.background.paper),
59-
},
60-
}}
61-
id="custom-input-demo"
62-
options={stringArr}
63-
renderInput={(params) => (
64-
<div ref={params.InputProps.ref}>
65-
<input className="search-input" type="text" id="search-input" placeholder="Search"
66-
onKeyPress={(event) => {search(event, 'keypress')}} value={searchValue} onChange={onValueChange} {...params.inputProps} />
67-
<a className="search-icon" onClick={(event) => {search(event, 'buttonclick')}}>
68-
<i className="fa fa-search"></i>
69-
</a>
70-
</div>
71-
)}
72-
/> */}
73-
<div className="autocomplete-block" style={isShown ? {display: "inherit"}: {display: "none"}}>
74-
{
75-
autocompleteData?.ArtistDetailsPage?.autocomplete?.ArtistName?.map((name) => {
76-
return(
77-
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
78-
)
79-
})
80-
}
81-
{
82-
autocompleteData?.ArtistDetailsPage?.autocomplete?.StageName?.map((name) => {
83-
return(
84-
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
85-
)
86-
})
87-
}
88-
</div>
60+
<div className="autocomplete-block" style={isShown ? {display: "inherit"}: {display: "none"}}>
61+
{
62+
autocompleteData?.ArtistDetailsPage?.autocomplete?.ArtistName?.map((name) => {
63+
return(
64+
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
65+
)
66+
})
67+
}
68+
{
69+
autocompleteData?.ArtistDetailsPage?.autocomplete?.StageName?.map((name) => {
70+
return(
71+
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
72+
)
73+
})
74+
}
75+
</div>
8976
</div>
9077
</div>
9178
);

0 commit comments

Comments
 (0)