(e: KeyboardEvent)
| 156 | // We can also explicitly catch PageUp/Down if we want smooth scroll or specific behavior, |
| 157 | // but native usually handles this perfectly. Let's explicitly ensure it behaves well. |
| 158 | const onKeyDown = (e: KeyboardEvent) => { |
| 159 | // If user is focused on an input inside the scroll view, don't hijack keys |
| 160 | if (document.activeElement && ["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement.tagName)) { |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | const next = scrollKey(e) |
| 165 | if (!next) return |
| 166 | |
| 167 | const scrollAmount = viewportRef.clientHeight * 0.8 |
| 168 | const lineAmount = 40 |
| 169 | |
| 170 | switch (next) { |
| 171 | case "page-down": |
| 172 | e.preventDefault() |
| 173 | viewportRef.scrollBy({ top: scrollAmount, behavior: "smooth" }) |
| 174 | break |
| 175 | case "page-up": |
| 176 | e.preventDefault() |
| 177 | viewportRef.scrollBy({ top: -scrollAmount, behavior: "smooth" }) |
| 178 | break |
| 179 | case "home": |
| 180 | e.preventDefault() |
| 181 | viewportRef.scrollTo({ top: 0, behavior: "smooth" }) |
| 182 | break |
| 183 | case "end": |
| 184 | e.preventDefault() |
| 185 | viewportRef.scrollTo({ top: viewportRef.scrollHeight, behavior: "smooth" }) |
| 186 | break |
| 187 | case "up": |
| 188 | e.preventDefault() |
| 189 | viewportRef.scrollBy({ top: -lineAmount, behavior: "smooth" }) |
| 190 | break |
| 191 | case "down": |
| 192 | e.preventDefault() |
| 193 | viewportRef.scrollBy({ top: lineAmount, behavior: "smooth" }) |
| 194 | break |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return ( |
| 199 | <div |
no test coverage detected