Skip to content

Commit 5c6753f

Browse files
Merge pull request #153 from PEC-CSS/fix/end-event-ux
added Loader and keyboard navigation
2 parents dbe3d02 + f9346bd commit 5c6753f

File tree

5 files changed

+374
-175
lines changed

5 files changed

+374
-175
lines changed

components/common/EventPopup/AcmEventHeads.tsx

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default function AcmEventHeads({ teamTitle, pills, setPills, setEmptyErro
2121
const [showSearchResults, setShowSearchResults] = useState(true)
2222
const { data: session } = useSession();
2323
const token = getCookieData(session).data.token
24+
const [cursor, setCursor] = useState(-1)
25+
const [mousePointer, setMousePointer] = useState(-1)
2426

2527
const searchUsersApi = useCallback((pattern: string) => {
2628
getMatchingUsersApi(pattern, token)
@@ -66,6 +68,7 @@ export default function AcmEventHeads({ teamTitle, pills, setPills, setEmptyErro
6668
setNameSearchValue("")
6769
setDebouncedValue("")
6870
setSearchResult([])
71+
setCursor(-1)
6972
setEmptyError(false)
7073
setPills((prevState) => {
7174
return [...prevState, pill];
@@ -89,9 +92,32 @@ export default function AcmEventHeads({ teamTitle, pills, setPills, setEmptyErro
8992
const handleBlur = () => {
9093
setTimeout ( () => {
9194
setShowSearchResults(false)
95+
setCursor(-1)
9296
}, 500)
9397
}
9498

99+
const keyboardNavigation = (e: React.KeyboardEvent<HTMLInputElement>) => {
100+
if (e.key === "Enter") {
101+
if (cursor < searchResult.length && cursor != -1) {
102+
addUserToPills(searchResult[cursor])
103+
}
104+
}
105+
if (e.key === "ArrowUp") {
106+
if (cursor > 0) {
107+
setCursor( cursor => cursor - 1)
108+
}
109+
}
110+
if (e.key === "ArrowDown") {
111+
if (cursor < searchResult.length - 1) {
112+
setCursor( cursor => cursor + 1)
113+
}
114+
}
115+
if (e.key === "Escape") {
116+
setShowSearchResults(false)
117+
setCursor(-1)
118+
}
119+
}
120+
95121
return (
96122
<div className={styles['acm-event-heads-container']}>
97123
<div className={styles.pillInputDiv}>
@@ -103,26 +129,45 @@ export default function AcmEventHeads({ teamTitle, pills, setPills, setEmptyErro
103129
className={styles.pillInput}
104130
placeholder={`Search ${teamTitle}*`}
105131
onBlur={handleBlur}
132+
onKeyDown={keyboardNavigation}
106133
/>
107134
</div>
108135

109136
<div>
110137
{
111138
showSearchResults &&
112-
<div className={styles['pills-container']}>
113-
{searchResult.map((pill: Pill) =>
114-
<div
139+
<ul className={styles['pills-container']}>
140+
{searchResult.map((pill: Pill) => {
141+
const idxOfPill = searchResult.indexOf(pill)
142+
return <div
115143
onClick={() => addUserToPills(pill)}
116144
key={pill.email}
117-
className={styles['pill']}
145+
style={{
146+
backgroundColor: cursor === idxOfPill || mousePointer === idxOfPill ? "#0a69da" : "white",
147+
color: cursor === idxOfPill || mousePointer === idxOfPill ? "white" : "black",
148+
padding: '10px',
149+
margin: 0,
150+
cursor: 'pointer'
151+
}}
152+
onMouseEnter={() => setCursor(searchResult.indexOf(pill))}
153+
onMouseLeave={() => setCursor(-1)}
118154
>
119155
{pill.name}
120-
<p>
156+
<p
157+
style={{
158+
color: cursor === searchResult.indexOf(pill) || mousePointer === idxOfPill ? "white" : "grey",
159+
fontSize: 'small',
160+
overflow: 'clip',
161+
margin: 0
162+
}}
163+
>
121164
{pill.email}
122165
</p>
123166
</div>
167+
}
168+
124169
)}
125-
</div>
170+
</ul>
126171
}
127172
</div>
128173
</div>

0 commit comments

Comments
 (0)