Skip to content

Commit

Permalink
Delay initial mount
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 3, 2024
1 parent 26d95a3 commit d87151e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/sidebar/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState, type ReactElement } from 'react'
import { useCallback, useEffect, useState, type ReactElement } from 'react'
import { Box, Divider, Drawer } from '@mui/material'
import ChevronRight from '@mui/icons-material/ChevronRight'

Expand All @@ -14,6 +14,7 @@ import MyAccounts from '@/features/myAccounts'

const Sidebar = (): ReactElement => {
const [isDrawerOpen, setIsDrawerOpen] = useState<boolean>(false)
const [modalProps, setModalProps] = useState({ keepMounted: false })

const onDrawerToggle = useCallback(() => {
setIsDrawerOpen((isOpen) => {
Expand All @@ -25,6 +26,13 @@ const Sidebar = (): ReactElement => {

const closeDrawer = useCallback(() => setIsDrawerOpen(false), [])

// Mount the drawer 600ms after the page load, and keep it mounted
useEffect(() => {
setTimeout(() => {
setModalProps({ keepMounted: true })
}, 600)
}, [])

return (
<div data-testid="sidebar-container" className={css.container}>
<div className={css.scroll}>
Expand Down Expand Up @@ -58,13 +66,7 @@ const Sidebar = (): ReactElement => {

<IndexingStatus />
</div>
<Drawer
variant="temporary"
anchor="left"
open={isDrawerOpen}
onClose={onDrawerToggle}
ModalProps={{ keepMounted: true }}
>
<Drawer variant="temporary" anchor="left" open={isDrawerOpen} onClose={onDrawerToggle} ModalProps={modalProps}>
<div className={css.drawer}>
<MyAccounts onLinkClick={closeDrawer} isSidebar></MyAccounts>
</div>
Expand Down

0 comments on commit d87151e

Please sign in to comment.