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 && ( <>