Skip to content
+

Simple Tree View - Focus

Learn how to focus Tree View items.

Imperative API

To use the apiRef object, you need to initialize it using the useSimpleTreeViewApiRef() hook as follows:

const apiRef = useSimpleTreeViewApiRef();

return <SimpleTreeView apiRef={apiRef} items={ITEMS} />;

When your component first renders, apiRef.current is undefined. After the initial render, apiRef holds methods to interact imperatively with the Tree View.

Focus a specific item

Use the focusItem() API method to focus a specific item.

apiRef.current.focusItem(
  // The DOM event that triggers the change
  event,
  // The id of the item to focus
  itemId,
);

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.