npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@contentful/f36-menu

v4.65.5

Published

Forma 36: Menu component

Downloads

85,367

Readme


title: 'Menu' slug: /components/menu/ github: 'https://github.com/contentful/forma-36/tree/main/packages/components/menu' typescript: ./src/Menu.tsx,./src/MenuItem/MenuItem.tsx,./src/MenuList/MenuList.tsx storybook: 'https://f36-storybook.contentful.com/?path=/story/components-menu--basic'

Menu is a component that offers a list of choices to the user, such as a set of actions or links. Menu uses Popover component as a base.

Import

import { Menu } from '@contentful/f36-components';

Examples

You can use following components to build a menu:

  1. <Menu>: The main wrapper that provides nested components with all the context and state.
  2. <Menu.Trigger> The wrapper for the menu list trigger. Must be a direct child of <Menu>.
    NOTE: 🚨 Ensure that the component that you pass accepts ref. Consider using forwardRef for functional components.
  3. <Menu.List>: The wrapper for the menu items. Must be a direct child of <Menu>.
  4. <Menu.Item> The trigger that handles menu selection. Must be a direct child of <Menu.List>.
  5. <Menu.Divider> A visual separator for menu items.
  6. <Menu.SectionTitle> A title that you can use in the menu list.
  7. <Menu.ListHeader> The wrapper for one menu item that will be sticked to the top of the menu list. <Menu.Item> must be provided as a child.
  8. <Menu.ListFooter> The wrapper for one menu item that will be sticked to the bottom of the menu list. <Menu.Item> must be provided as a child.
  9. <Menu.Submenu> The wrapper for for submenu components. Structure of the children remains the same like in <Menu>, except you should use <Menu.SubmenuTrigger> instead of <Menu.Trigger>.
  10. <Menu.SubmenuTrigger> The wrapper for the submenu list trigger. Must be a direct child of <Menu.Submenu>.

Basic usage

With simple Button as a trigger

With Menu.SectionTitle and Menu.Divider

Controlled Menu

By default the Menu component is uncontrolled. So when user clicks on the trigger, the menu opens/closes. But you can control it by passing isOpen prop and onClose, onOpen callbacks.

Controlled Menu with custom trigger onClick callback

In most cases, you will use the controlled approach. But if you have to provide your own toggle menu logic on the trigger component, you can do this by providing onClick callback on trigger component and omitting onOpen callback on the Menu component.

With Menu list maximum height

With active and disabled items

With icons on menu items

With menu open by default

With sticky header and footer

With React Router links

With predefined focused menu item

With submenu

By default props like closeOnSelect, closeOnBlur, closeOnEsc that you pass to Menu will be shared to all submenus but you can redefine them on any submenu by passing those props directly to that Submenu.

Props (API reference)

Menu

Menu.Item

Menu.List

Content guidelines

  • Use an interactive element such as button for Menu.Trigger

Accessibility

  • When the menu is opened, focus is moved to the first menu item. Or to the one that has isInitiallyFocused prop set to true.
  • When the menu is closed, focus returned back to the trigger element.
  • You can use arrow keys (ArrowUp and ArrowDown) to navigate through menu items.
  • When the menu is open, click on Esc key will close the popover. If you set closeOnEsc to false, it will not close.
  • When the menu is open, click outside menu or blurring out will close the menu. If you set closeOnBlur to false, it will not close.
  • All the necessary a11y attributes for Menu.List, Menu.Trigger and Menu.Item are provided.