From 9201f7a1180caf3505e0597253471d355e06e267 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 30 Dec 2022 20:37:57 +0800 Subject: [PATCH] First step in making things focusable --- src/app.jsx | 27 ++++++++++++++++++++++++--- src/components/account.jsx | 3 +-- src/components/modal.jsx | 14 +++++++++++++- src/components/status.jsx | 11 +++++++++-- src/index.css | 4 ++++ src/pages/home.jsx | 1 + src/pages/notifications.jsx | 7 ++++++- src/pages/status.jsx | 4 ++++ 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/app.jsx b/src/app.jsx index c2548ccb..5bf428de 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -298,6 +298,26 @@ export function App() { }, []); const [currentDeck, setCurrentDeck] = useState('home'); + const focusDeck = () => { + let timer = setTimeout(() => { + const page = document.getElementById(`${currentDeck}-page`); + console.log('focus', currentDeck, page); + if (page) { + page.focus(); + } + }, 100); + return () => clearTimeout(timer); + }; + useEffect(focusDeck, [currentDeck]); + useEffect(() => { + if ( + !snapStates.showCompose && + !snapStates.showSettings && + !snapStates.showAccount + ) { + focusDeck(); + } + }, [snapStates.showCompose, snapStates.showSettings, snapStates.showAccount]); useEffect(() => { // HACK: prevent this from running again due to HMR @@ -324,7 +344,7 @@ export function App() { return ( <> - {isLoggedIn && currentDeck && ( + {isLoggedIn && ( <>