Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Forbedrer hindring av escape-tast for å lukke utloggingsvarsel
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Dec 18, 2023
1 parent e3b9788 commit 9a5c89e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/komponenter/header/logoutWarning/LogoutWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export const LogoutWarning = () => {
} = useLoginStatus();
const [isOpen, setIsOpen] = React.useState(false);
const { language } = useSelector((state: AppState) => state.language);
const dialogRef = React.useRef<HTMLDialogElement>(null);

useEffect(() => {
const dialog = dialogRef.current;
if (!dialog) {
return;
}

window.addEventListener('keydown', onKeydownHandler);

return () => {
window.removeEventListener('keydown', onKeydownHandler);
};
}, [dialogRef.current]);

useEffect(() => {
if (isTokenExpiring || isSessionExpiring) {
Expand All @@ -34,8 +48,10 @@ export const LogoutWarning = () => {
setIsOpen(false);
};

const onBeforeCloseHandler = () => {
return false;
const onKeydownHandler = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
e.preventDefault();
}
};

if (typeof document === 'undefined') {
Expand Down Expand Up @@ -71,12 +87,12 @@ export const LogoutWarning = () => {
<Modal
open={isOpen}
onClose={onCloseHandler}
onBeforeClose={onBeforeCloseHandler}
header={{
heading: finnTekst(titleId, language, minutesToSessionEnd.toString()),
closeButton: false,
}}
className={classNames(styles.logoutWarning, isOpen && styles.visible)}
ref={dialogRef}
>
<Modal.Body className={styles.content}>
<BodyLong spacing>{finnTekst(textBodyId, language)}</BodyLong>
Expand Down

0 comments on commit 9a5c89e

Please sign in to comment.