UNPKG

baseui

Version:

A React Component library implementing the Base design language

29 lines (26 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = FocusOnce; var React = _interopRequireWildcard(require("react")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ /** * Wrap an element in FocusOnce that would normally not receive tab focus. * This is useful for placing initial focus in a Modal or FocusLock. * */ function FocusOnce(props) { const [tabIndex, setTabIndex] = React.useState('0'); const child = React.Children.only(props.children); // @ts-expect-error todo(flow->ts): children type should restrict children to elements only return /*#__PURE__*/React.cloneElement(child, { tabIndex, onBlur: () => setTabIndex(null) }); }