Ariakit
/

Examples

API

Styling

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, links, or settings. For example, a dropdown to access a set of commands to edit a document or a list of settings to configure part of an application.

Like the native <select> element, the Select button's text reflects the selected option (the value). The button should also have a label alongside the value, even if it's visually hidden. When the SelectPopover opens, the selected item will be focused and brought into view. If your design requires these features, use Select.

On the other hand, MenuButton can only display a label, not hold a value. The label is usually a static call to action. Opening the Menu won't automatically focus on a checked MenuItemCheckbox or MenuItemRadio, which are commonly used for settings.

Stay tuned

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

No spam. Unsubscribe anytime. Read latest issue