-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make bindHover/bindFocus work correctly together
fix #102
- Loading branch information
1 parent
c4251fd
commit f7172be
Showing
6 changed files
with
328 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react' | ||
import HoverMenu from 'material-ui-popup-state/HoverMenu' | ||
import MenuItem from '@mui/material/MenuItem' | ||
import Button from '@mui/material/Button' | ||
import { | ||
usePopupState, | ||
bindFocus, | ||
bindHover, | ||
bindMenu, | ||
} from 'material-ui-popup-state/hooks' | ||
|
||
const HoverFocusMenu = () => { | ||
const popupState = usePopupState({ | ||
variant: 'popover', | ||
popupId: 'demoMenu', | ||
}) | ||
return ( | ||
<React.Fragment> | ||
<Button | ||
variant="contained" | ||
{...bindHover(popupState)} | ||
{...bindFocus(popupState)} | ||
> | ||
Hover or focus to open Menu | ||
</Button> | ||
<HoverMenu | ||
{...bindMenu(popupState)} | ||
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }} | ||
transformOrigin={{ vertical: 'top', horizontal: 'left' }} | ||
> | ||
<MenuItem onClick={popupState.close}>Cake</MenuItem> | ||
<MenuItem onClick={popupState.close}>Death</MenuItem> | ||
</HoverMenu> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default HoverFocusMenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
import HoverMenu from 'material-ui-popup-state/HoverMenu' | ||
import MenuItem from '@mui/material/MenuItem' | ||
import Button from '@mui/material/Button' | ||
import PopupState, { | ||
bindHover, | ||
bindFocus, | ||
bindMenu, | ||
} from 'material-ui-popup-state' | ||
|
||
const HoverFocusMenu = () => ( | ||
<PopupState variant="popover" popupId="demoMenu"> | ||
{(popupState) => ( | ||
<React.Fragment> | ||
<Button | ||
variant="contained" | ||
{...bindHover(popupState)} | ||
{...bindFocus(popupState)} | ||
> | ||
Hover or focus to open Menu | ||
</Button> | ||
<HoverMenu | ||
{...bindMenu(popupState)} | ||
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }} | ||
transformOrigin={{ vertical: 'top', horizontal: 'left' }} | ||
> | ||
<MenuItem onClick={popupState.close}>Cake</MenuItem> | ||
<MenuItem onClick={popupState.close}>Death</MenuItem> | ||
</HoverMenu> | ||
</React.Fragment> | ||
)} | ||
</PopupState> | ||
) | ||
|
||
export default HoverFocusMenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.