question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating popover menus

See original GitHub issue

Hey, I’m looking to create popover menus with this kind of experience (from Shopify):

https://www.loom.com/share/2ae4312a24dc4a54800a898fe9477219

Some things to note:

  • Has an anchor button which toggles the state
  • Clicking away hides the menu

I would maybe be fine with using hover/focus state to handle it being open, too (it needs to also work on mobile browsers, though). It doesn’t necessarily need to be just onPress if that’s difficult.

Is something like this possible with the current API?

Added context

Another nice feature you’ll see in the video: if you click outside of the menu section onto somewhere else, the click event is still handled at the other spot you pressed. This can be easily achieved with a useClickAway(viewRef) function. This would be web-only behavior, since . That said, I think it could make sense to have in this library. (The clickaway feature would be a cherry on top. It isn’t a requirement for the menu behavior described above, so it’s fine if you’d like to go without it.)

Curious to hear your thoughts @eveningkid. Thanks again!

PS Another nice example of this is Vercel’s menu component, as well as their popover/tooltip.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
nandorojocommented, Apr 5, 2021

@eveningkid this looks great!

My final request: I’d like an API to be able to close the popover without necessarily controlling its state. Imagine you click one of the menu items. It’s not a click-away event, but it should close the popover imperatively.

Something like this would be nice:

const popover = useRef(null)

return <Popover ref={popover} content={<Menu onPressItem={() => popover.current?.close()} />} />

This would be simple to implement with useImperativeHandle under the hood.

A custom hook would be a nice touch, too, but not totally necessary. I’d build something like this in my own app if this lib doesn’t have one:

const [ref, { close }] = usePopover()

const onPressMenuItem = () => {
  close()
}

<Popover ref={ref} />
1reaction
eveningkidcommented, Apr 4, 2021

Alright, it should now be working with 0.3.0. You can try it using this snack.

I think this should give you more flexibility to create interactive menus!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Popover Menu - OutSystems 11 Documentation
Popover Menu. A container that opens when the user taps an element or a region. You can use it to provide contextual information...
Read more >
How to create popover menus using ... - Hacking with Swift
The solution is to use a UIPopoverPresentationController , which gets created for you when you try to access the popoverPresentationController ...
Read more >
Popovers - Presentation - Human Interface Guidelines - Design
A popover is a transient view that appears above other content onscreen when people click or tap a control or interactive area.
Read more >
Popovers - Bootstrap
Popovers rely on the 3rd party library Popper.js for positioning. · Popovers require the tooltip plugin as a dependency. · If you're building...
Read more >
ion-popover - Ionic Framework
When using ion-popover inline, you can nested popovers to create nested dropdown menus. When doing this, only the backdrop on the first popover...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found