"use strict"; var _interopRequireWildcard = require("@babel/runtime-corejs2/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _extends3 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutPropertiesLoose")); var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inheritsLoose")); var _classnames = _interopRequireDefault(require("classnames")); var _keycode = _interopRequireDefault(require("keycode")); var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _reactDom = _interopRequireDefault(require("react-dom")); var _all = _interopRequireDefault(require("prop-types-extra/lib/all")); var _warning = _interopRequireDefault(require("warning")); var _bootstrapUtils = require("./utils/bootstrapUtils"); var _createChainedFunction = _interopRequireDefault(require("./utils/createChainedFunction")); var _ValidComponentChildren = _interopRequireDefault(require("./utils/ValidComponentChildren")); // TODO: Should we expose `` as ``? // TODO: This `bsStyle` is very unlike the others. Should we rename it? // TODO: `pullRight` and `pullLeft` don't render right outside of `navbar`. // Consider renaming or replacing them. var propTypes = { /** * Marks the NavItem with a matching `eventKey` as active. Has a * higher precedence over `activeHref`. */ activeKey: _propTypes.default.any, /** * Marks the child NavItem with a matching `href` prop as active. */ activeHref: _propTypes.default.string, /** * NavItems are be positioned vertically. */ stacked: _propTypes.default.bool, justified: (0, _all.default)(_propTypes.default.bool, function (_ref) { var justified = _ref.justified, navbar = _ref.navbar; return justified && navbar ? Error('justified navbar `Nav`s are not supported') : null; }), /** * A callback fired when a NavItem is selected. * * ```js * function ( * Any eventKey, * SyntheticEvent event? * ) * ``` */ onSelect: _propTypes.default.func, /** * ARIA role for the Nav, in the context of a TabContainer, the default will * be set to "tablist", but can be overridden by the Nav when set explicitly. * * When the role is set to "tablist" NavItem focus is managed according to * the ARIA authoring practices for tabs: * https://www.w3.org/TR/2013/WD-wai-aria-practices-20130307/#tabpanel */ role: _propTypes.default.string, /** * Apply styling an alignment for use in a Navbar. This prop will be set * automatically when the Nav is used inside a Navbar. */ navbar: _propTypes.default.bool, /** * Float the Nav to the right. When `navbar` is `true` the appropriate * contextual classes are added as well. */ pullRight: _propTypes.default.bool, /** * Float the Nav to the left. When `navbar` is `true` the appropriate * contextual classes are added as well. */ pullLeft: _propTypes.default.bool }; var defaultProps = { justified: false, pullRight: false, pullLeft: false, stacked: false }; var contextTypes = { $bs_navbar: _propTypes.default.shape({ bsClass: _propTypes.default.string, onSelect: _propTypes.default.func }), $bs_tabContainer: _propTypes.default.shape({ activeKey: _propTypes.default.any, onSelect: _propTypes.default.func.isRequired, getTabId: _propTypes.default.func.isRequired, getPaneId: _propTypes.default.func.isRequired }) }; var Nav = /*#__PURE__*/ function (_React$Component) { (0, _inheritsLoose2.default)(Nav, _React$Component); function Nav() { return _React$Component.apply(this, arguments) || this; } var _proto = Nav.prototype; _proto.componentDidUpdate = function componentDidUpdate() { var _this = this; if (!this._needsRefocus) { return; } this._needsRefocus = false; var children = this.props.children; var _this$getActiveProps = this.getActiveProps(), activeKey = _this$getActiveProps.activeKey, activeHref = _this$getActiveProps.activeHref; var activeChild = _ValidComponentChildren.default.find(children, function (child) { return _this.isActive(child, activeKey, activeHref); }); var childrenArray = _ValidComponentChildren.default.toArray(children); var activeChildIndex = childrenArray.indexOf(activeChild); var childNodes = _reactDom.default.findDOMNode(this).children; var activeNode = childNodes && childNodes[activeChildIndex]; if (!activeNode || !activeNode.firstChild) { return; } activeNode.firstChild.focus(); }; _proto.getActiveProps = function getActiveProps() { var tabContainer = this.context.$bs_tabContainer; if (tabContainer) { process.env.NODE_ENV !== "production" ? (0, _warning.default)(this.props.activeKey == null && !this.props.activeHref, 'Specifying a `