"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = RovingTabIndex;
var _element = require("@wordpress/element");
var _rovingTabIndexContext = require("./roving-tab-index-context");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Provider for adding roving tab index behaviors to tree grid structures.
 *
 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/components/src/tree-grid/README.md
 */function RovingTabIndex({
  children
}) {
  const [lastFocusedElement, setLastFocusedElement] = (0, _element.useState)();

  // Use `useMemo` to avoid creation of a new object for the providerValue
  // on every render. Only create a new object when the `lastFocusedElement`
  // value changes.
  const providerValue = (0, _element.useMemo)(() => ({
    lastFocusedElement,
    setLastFocusedElement
  }), [lastFocusedElement]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_rovingTabIndexContext.RovingTabIndexProvider, {
    value: providerValue,
    children: children
  });
}
//# sourceMappingURL=roving-tab-index.js.map