Menu

A reusable dropdown with custom elements and Popover API
📰

A reusable dropdown with custom elements and Popover API

DEV Community: javascript·Rails Designer·3 days ago
#wTBKiAtb
#devtojavascript#devto#dev#contextmenu#panel
Reading 0:00
15s threshold

A dropdown looks like a problem solved by many already. But it is not too difficult to build your own and allows to make them exactly how you want them to be. It has to open next to its trigger, flip when there’s no room, stay inside the viewport, move focus into the panel, cycle through its items with the arrow keys, close on Escape and disappear when you click somewhere else.

Then there’s the part I find most useful: the same panel should also work as a right-click context menu, opening where the pointer is instead on a button.

That’s a handful of behaviors together.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.