Skip to content

Commit

Permalink
feat(map-accessibility): Fix popover issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-azma committed Feb 20, 2024
1 parent af2cabf commit c6222d8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/geoview-core/src/ui/popover/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from 'react';
import { Popover as MaterialPopover, PopoverProps } from '@mui/material';

/**
Expand All @@ -7,5 +9,23 @@ import { Popover as MaterialPopover, PopoverProps } from '@mui/material';
* @returns {JSX.Element} returns popover component
*/
export function Popover(props: PopoverProps): JSX.Element {
const arrowKeyCodes: string[] = ['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLefts', 'Space'];
const { open } = props;

const handleKeyDown = (event: KeyboardEvent) => {
if (arrowKeyCodes.includes(event.code as string)) {
// disbale the default behaviour of key down if it's part of 'ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft', or 'Space'
event.preventDefault();
}
};

useEffect(() => {
if (open) {
window.addEventListener('keydown', handleKeyDown);
}
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [open]);
return <MaterialPopover {...props} />;
}

0 comments on commit c6222d8

Please sign in to comment.