Styling the active item

When browsing the list with a keyboard (or hovering over items with the mouse when the focusOnHover prop is true), the active item element will have a data-active-item attribute. You can use this attribute to style the active item:

.menu-item[data-active-item] {
background-color: hsl(204 100% 40%);
color: white;

Learn more on the Styling guide.

Should I use Menu or Select?

Because they behave similarly, it may not be obvious when to use Menu and when to use Select. Here are some guidelines to help you decide:

  • Use Select when the purpose is to select a value from a list of options. For example, a dropdown to select a country from a list of countries.

  • Use Menu when the purpose is to access a set of commands, actions, or links. For example, a dropdown to access a set of commands to edit a document.

There are also some differences in how both components behave. Similarly to the native <select> element, the Select button's text will reflect the selected item. The button should also have a label in addition to the value. When the SelectPopover opens, the selected item will be focused and brought into view.

On the other hand, MenuButton can't hold a value, only a label, which won't reflect the active item. It's usually a static call to action.

Stay tuned

Join 1,000+ subscribers and receive monthly tips & updates on new Ariakit content.

No spam. Unsubscribe anytime. Read latest issue