Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix closing select dropdwon when clicking outside the component #207

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/components/Navbar/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
dispatch(
updatePchainAddress({ address: getPchainAddress(), walletName: getNameOfWallet() }),
)
}, [auth])

Check warning on line 50 in src/components/Navbar/Account.tsx

View workflow job for this annotation

GitHub Actions / yarn-build

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array
const handleKeyDown = e => {
e.stopPropagation()
}
Expand Down Expand Up @@ -113,20 +113,22 @@
!account ? (
<Typography>Account</Typography>
) : (
<Box onClick={() => setOpen(v => !v)}>
<LoadAccountMenu type="" />
</Box>
<LoadAccountMenu type="" />
)
}
renderValue={() =>
account ? (
<Box onClick={() => setOpen(v => !v)}>
renderValue={() => (
<Box
onClick={() => {
setOpen(v => !v)
}}
>
{!account ? (
<Typography>Account</Typography>
) : (
<LoadAccountMenu type="" />
</Box>
) : (
<Typography>Account</Typography>
)
}
)}
</Box>
)}
sx={{
maxWidth: '13rem',
'.MuiOutlinedInput-notchedOutline': { border: 'none' },
Expand All @@ -136,6 +138,9 @@
handleKeyDown(e)
}}
MenuProps={{
onClose: () => {
setOpen(v => !v)
},
onClick: e => {
e.preventDefault()
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar/AliasPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AliasPicker = ({
setOpenSelect,
}: {
handleKeyDown: (e: any) => void
setOpenSelect: React.Dispatch<React.SetStateAction<boolean>>
setOpenSelect?: React.Dispatch<React.SetStateAction<boolean>>
}) => {
const [open, setOpen] = useState(false)
const [load, setLoad] = useState(false)
Expand All @@ -38,7 +38,7 @@ const AliasPicker = ({
}
const handleCloseModal = () => {
setOpen(false)
setOpenSelect(v => !v)
if (setOpenSelect) setOpenSelect(v => !v)
}
useEffect(() => {
showButton()
Expand Down
8 changes: 6 additions & 2 deletions src/components/Navbar/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import React, { Dispatch, SetStateAction } from 'react'
import store from 'wallet/store'
import useWidth from '../../hooks/useWidth'

export default function ThemeSwitcher({ setOpen }: { setOpen: Dispatch<SetStateAction<boolean>> }) {
export default function ThemeSwitcher({
setOpen,
}: {
setOpen?: Dispatch<SetStateAction<boolean>>
}) {
const { isDesktop, isMobile } = useWidth()
const dispatch = useAppDispatch()
const theme = useTheme()
Expand All @@ -23,7 +27,7 @@ export default function ThemeSwitcher({ setOpen }: { setOpen: Dispatch<SetStateA
changeTheme(currentTheme === 'light' ? 'dark' : 'light')
store.commit('updateTheme')
dispatch(toggleTheme())
setOpen(v => !v)
if (setOpen) setOpen(v => !v)
}

return (
Expand Down
Loading