From 40a1bb4417a44427d501d4e8043f72930f72e498 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 26 Mar 2024 11:43:56 +1100 Subject: [PATCH] feat: add focustrap for dialog and focus-within for buttons --- package.json | 1 + ts/components/SessionWrapperModal.tsx | 117 +++++++++--------- ts/components/basic/SessionButton.tsx | 8 +- ts/components/basic/SessionRadio.tsx | 4 + .../conversation/SessionConversation.tsx | 14 +-- .../composition/CompositionButtons.tsx | 4 +- .../ConversationHeaderSelectionOverlay.tsx | 21 ++++ .../message-content/MessageContextMenu.tsx | 14 +-- .../conversation/right-panel/RightPanel.tsx | 2 + ts/components/dialog/SessionConfirm.tsx | 2 +- ts/components/icon/SessionIconButton.tsx | 17 +-- .../conversations/unsendingInteractions.ts | 18 +++ yarn.lock | 20 +++ 13 files changed, 151 insertions(+), 91 deletions(-) diff --git a/package.json b/package.json index be8c27d80..3bf68321b 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "emoji-mart": "^5.5.2", "filesize": "3.6.1", "firstline": "1.2.1", + "focus-trap-react": "^10.2.3", "fs-extra": "9.0.0", "glob": "7.1.2", "image-type": "^4.1.0", diff --git a/ts/components/SessionWrapperModal.tsx b/ts/components/SessionWrapperModal.tsx index c75a64c0d..fd2aaef87 100644 --- a/ts/components/SessionWrapperModal.tsx +++ b/ts/components/SessionWrapperModal.tsx @@ -1,5 +1,6 @@ -import React, { useRef } from 'react'; import classNames from 'classnames'; +import FocusTrap from 'focus-trap-react'; +import React, { useRef } from 'react'; import useKey from 'react-use/lib/useKey'; import { SessionIconButton } from './icon'; @@ -63,68 +64,72 @@ export const SessionWrapperModal = (props: SessionWrapperModalType) => { }; return ( -
-
-
- {showHeader ? ( -
-
- {showExitIcon ? ( - - ) : null} + +
+ {/* FocusTrap needs a button always mounted as a start, which is apparently not our case */} +