mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 16:58:47 +01:00
Attempt to fix lost focus when closing nav menu
This commit is contained in:
parent
753789c0c7
commit
a52bd7ca5d
1 changed files with 9 additions and 14 deletions
|
@ -1,11 +1,5 @@
|
||||||
import {
|
import { ControlledMenu, MenuDivider, MenuItem } from '@szhsin/react-menu';
|
||||||
ControlledMenu,
|
import { useRef, useState } from 'preact/hooks';
|
||||||
MenuDivider,
|
|
||||||
MenuItem,
|
|
||||||
useClick,
|
|
||||||
useMenuState,
|
|
||||||
} from '@szhsin/react-menu';
|
|
||||||
import { useRef } from 'preact/hooks';
|
|
||||||
import { useLongPress } from 'use-long-press';
|
import { useLongPress } from 'use-long-press';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
|
@ -47,8 +41,7 @@ function NavMenu(props) {
|
||||||
);
|
);
|
||||||
|
|
||||||
const buttonRef = useRef();
|
const buttonRef = useRef();
|
||||||
const [menuState, toggleMenu] = useMenuState();
|
const [menuState, setMenuState] = useState(undefined);
|
||||||
const anchorProps = useClick(menuState.state, toggleMenu);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -59,7 +52,9 @@ function NavMenu(props) {
|
||||||
moreThanOneAccount ? 'with-avatar' : ''
|
moreThanOneAccount ? 'with-avatar' : ''
|
||||||
} ${open ? 'active' : ''}`}
|
} ${open ? 'active' : ''}`}
|
||||||
style={{ position: 'relative' }}
|
style={{ position: 'relative' }}
|
||||||
{...anchorProps}
|
onClick={() => {
|
||||||
|
setMenuState((state) => (!state ? 'open' : undefined));
|
||||||
|
}}
|
||||||
onContextMenu={(e) => {
|
onContextMenu={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
states.showAccounts = true;
|
states.showAccounts = true;
|
||||||
|
@ -78,17 +73,17 @@ function NavMenu(props) {
|
||||||
<Icon icon="menu" size={moreThanOneAccount ? 's' : 'l'} />
|
<Icon icon="menu" size={moreThanOneAccount ? 's' : 'l'} />
|
||||||
</button>
|
</button>
|
||||||
<ControlledMenu
|
<ControlledMenu
|
||||||
{...menuState}
|
state={menuState}
|
||||||
anchorRef={buttonRef}
|
anchorRef={buttonRef}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
toggleMenu(false);
|
setMenuState(undefined);
|
||||||
}}
|
}}
|
||||||
containerProps={{
|
containerProps={{
|
||||||
style: {
|
style: {
|
||||||
zIndex: 10,
|
zIndex: 10,
|
||||||
},
|
},
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
toggleMenu(false);
|
setMenuState(undefined);
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
portal={{
|
portal={{
|
||||||
|
|
Loading…
Reference in a new issue