Fix radio inputs intercept arrow keys

This commit is contained in:
Lim Chee Aun 2024-08-29 16:47:40 +08:00
parent 41af07c440
commit f3895d09e3

View file

@ -822,6 +822,22 @@ function Catchup() {
}, },
); );
const handleArrowKeys = useCallback((e) => {
const activeElement = document.activeElement;
const isRadio =
activeElement?.tagName === 'INPUT' && activeElement.type === 'radio';
const isArrowKeys =
e.key === 'ArrowDown' ||
e.key === 'ArrowUp' ||
e.key === 'ArrowLeft' ||
e.key === 'ArrowRight';
if (isArrowKeys && isRadio) {
// Note: page scroll won't trigger on first arrow key press due to this. Subsequent presses will.
activeElement.blur();
return;
}
}, []);
return ( return (
<div <div
ref={(node) => { ref={(node) => {
@ -883,7 +899,7 @@ function Catchup() {
</div> </div>
</div> </div>
</header> </header>
<main> <main onKeyDown={handleArrowKeys}>
{uiState === 'start' && ( {uiState === 'start' && (
<div class="catchup-start"> <div class="catchup-start">
<h1> <h1>