Ariakit
/

Code examples

Optional Props


accessibleWhenDisabled

boolean | undefined

Indicates whether the element should be focusable even when it is disabled.

This is important when discoverability is a concern. For example:

A toolbar in an editor contains a set of special smart paste functions that are disabled when the clipboard is empty or when the function is not applicable to the current content of the clipboard. It could be helpful to keep the disabled buttons focusable if the ability to discover their functionality is primarily via their presence on the toolbar.

Learn more on Focusability of disabled controls.

Live examples


alwaysVisible

boolean | undefined = false

Determines whether the content element should remain visible even when the open state is false. If this prop is set to true, the hidden prop and the display: none style will not be applied, unless explicitly set otherwise.

This prop is particularly useful when using third-party animation libraries such as Framer Motion or React Spring, where the element needs to be visible for exit animations to work.

Live examples


autoFocus

boolean | undefined = false

Automatically focuses the element upon mounting, similar to the native autoFocus prop. This addresses an issue where the element with the native autoFocus attribute might receive focus before React effects are executed.

The autoFocus prop can also be used with Focusable elements within a Dialog component, establishing the initial focus as the dialog opens.

Live examples


composite

boolean | undefined = true

Determines if the component should act as a composite widget. This prop needs to be set to false when merging various composite widgets where only one should function in that manner.

If disabled, this component will stop managing focus and keyboard navigation for its items and itself. Additionally, composite ARIA attributes won't be applied. These responsibilities should be taken over by another composite component.

Note: In most cases, this prop doesn't need to be set manually. For example, when composing Menu with Combobox or Select with Combobox, this prop will be set to false automatically on the Menu and SelectPopover components so the Combobox component can take over the composite widget responsibilities.

Live examples


disabled

boolean | undefined = false

Determines if the element is disabled. This sets the aria-disabled attribute accordingly, enabling support for all elements, including those that don't support the native disabled attribute.

This feature can be combined with the accessibleWhenDisabled prop to make disabled elements still accessible via keyboard.

Live examples


focusable

boolean | undefined = true

Determines if Focusable features should be active on non-native focusable elements.

Note: This prop only turns off the additional features provided by the Focusable component. Non-native focusable elements will lose their focusability entirely. However, native focusable elements will retain their inherent focusability, but without added features such as improved autoFocus, accessibleWhenDisabled, onFocusVisible, etc.

Live examples


focusOnMove

boolean | undefined = true

Determines if the active composite item should receive focus (or virtual focus if the virtualFocus option is enabled) when moving through items. This typically happens when navigating through items with arrow keys, but it can also happen when calling the move method directly.

Unlike the composite prop, this option doesn't disable the entire composite widget behavior. It only stops this component from managing focus when navigating through items.

Note: If you want to control the behavior only when arrow keys are pressed, use the moveOnKeyPress prop instead.


moveOnKeyPress

BooleanOrCallback<React.KeyboardEvent<HTMLElement>> | undefined = true

Determines whether the composite widget should move focus to an item when arrow keys are pressed, given that the composite element is focused and there's no active item.

Note: To entirely disable focus moving within a composite widget, you can use the focusOnMove prop instead. If you want to control the behavior only when arrow keys are pressed, where focusOnMove may not be applicable, this prop must be set on composite items as well.

Code examples


onFocusVisible

BivariantCallback<(event: React.SyntheticEvent<HTMLElement, Event>) => void> | undefined

Custom event handler invoked when the element gains focus through keyboard interaction or a key press occurs while the element is in focus. This is the programmatic equivalent of the data-focus-visible attribute.

Live examples


render

RenderProp<React.HTMLAttributes<any> & React.RefAttributes<any>> | React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined

Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged.

Check out the Composition guide for more details.


store

MenuStore<MenuStoreValues> | undefined

Object returned by the useMenuStore hook. If not provided, the closest MenuProvider component's context will be used.


typeahead

boolean | undefined = true

When enabled, pressing printable character keys will move focus to the next composite item that starts with the entered characters.

Follow updates

Join 1,000+ subscribers and receive monthly updates with the latest improvements on API Reference.

Read latest issue

No Spam. Unsubscribe at any time.