Skip to content

Commit e3f33b9

Browse files
author
ComputelessComputer
committed
stop wrapping search arrow navigation
1 parent 8690290 commit e3f33b9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/components/layout/AppLayout.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,21 @@ export default function AppLayout() {
224224

225225
if (globalSearchOpen && globalSearchResults.length > 0 && event.key === "ArrowDown") {
226226
event.preventDefault();
227-
setGlobalSearchSelectedIndex((prev,) => (prev + 1) % globalSearchResults.length);
227+
setGlobalSearchSelectedIndex((prev,) => {
228+
const lastIndex = globalSearchResults.length - 1;
229+
if (prev < 0) return 0;
230+
if (prev >= lastIndex) return lastIndex;
231+
return prev + 1;
232+
},);
228233
return;
229234
}
230235

231236
if (globalSearchOpen && globalSearchResults.length > 0 && event.key === "ArrowUp") {
232237
event.preventDefault();
233-
setGlobalSearchSelectedIndex((prev,) => (
234-
prev <= 0 ? globalSearchResults.length - 1 : prev - 1
235-
));
238+
setGlobalSearchSelectedIndex((prev,) => {
239+
if (prev <= 0) return 0;
240+
return prev - 1;
241+
},);
236242
return;
237243
}
238244

0 commit comments

Comments
 (0)