-
Notifications
You must be signed in to change notification settings - Fork 42
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
Feature/combobox pageup and pagedown #3158
Changes from all commits
abe85e6
04ec307
ab49f11
d7d89d4
d8badb8
7252e8d
0b2d872
f545135
bbaa81f
4787f13
fa61611
bcfd178
a3b8350
5cadfaf
4600f02
f6184c6
6184d07
215f9e7
378b340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@navikt/ds-react": patch | ||
"@navikt/ds-css": patch | ||
--- | ||
|
||
Combobox: Support PageUp/PageDown in dropdown list. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,14 +134,6 @@ const Input = forwardRef<HTMLInputElement, InputProps>( | |
case "Accept": | ||
onEnter(e); | ||
break; | ||
case "Home": | ||
toggleIsListOpen(false); | ||
virtualFocus.moveFocusToTop(); | ||
break; | ||
case "End": | ||
toggleIsListOpen(true); | ||
virtualFocus.moveFocusToBottom(); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
@@ -202,6 +194,24 @@ const Input = forwardRef<HTMLInputElement, InputProps>( | |
} | ||
virtualFocus.moveFocusUp(); | ||
} | ||
} else if (e.key === "Home") { | ||
e.preventDefault(); | ||
virtualFocus.moveFocusToTop(); | ||
} else if (e.key === "End") { | ||
e.preventDefault(); | ||
if (virtualFocus.activeElement === null || !isListOpen) { | ||
toggleIsListOpen(true); | ||
} | ||
virtualFocus.moveFocusToBottom(); | ||
} else if (e.key === "PageUp") { | ||
e.preventDefault(); | ||
virtualFocus.moveFocusUpBy(6); | ||
} else if (e.key === "PageDown") { | ||
e.preventDefault(); | ||
if (virtualFocus.activeElement === null || !isListOpen) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check this for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Maybe. I am unsure if there is a problem with actually doing this. One thing is ArrowDown/-Up, which the user could press-and-hold, but Home/End and PageUp/-Down shouldn't cause a performance hit even IF this causes any updates. Another thing is an inconsistency where ArrowUp from the first element and pressing Home will both close the list, whereas PageUp will stop on the first element. Should we make this more consistent? |
||
toggleIsListOpen(true); | ||
} | ||
virtualFocus.moveFocusDownBy(6); | ||
} | ||
}, | ||
[ | ||
|
@@ -230,10 +240,9 @@ const Input = forwardRef<HTMLInputElement, InputProps>( | |
} else if (filteredOptions.length === 0) { | ||
toggleIsListOpen(false); | ||
} | ||
virtualFocus.moveFocusToTop(); | ||
onChange(newValue); | ||
}, | ||
[filteredOptions.length, virtualFocus, onChange, toggleIsListOpen], | ||
[filteredOptions.length, onChange, toggleIsListOpen], | ||
); | ||
|
||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funket som bare det! (ref det du kommenterte om), var copy paste fra kode over 😎. Tror jeg liker at det er lik behaviour på tvers av alle pagineringsmuligheter 🤔.