import _extends from "@babel/runtime-corejs2/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose"; import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose"; import classNames from 'classnames'; import keycode from 'keycode'; import React, { cloneElement } from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import all from 'prop-types-extra/lib/all'; import warning from 'warning'; import { bsClass, bsStyles, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils'; import createChainedFunction from './utils/createChainedFunction'; import ValidComponentChildren from './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.any, /** * Marks the child NavItem with a matching `href` prop as active. */ activeHref: PropTypes.string, /** * NavItems are be positioned vertically. */ stacked: PropTypes.bool, justified: all(PropTypes.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.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.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.bool, /** * Float the Nav to the right. When `navbar` is `true` the appropriate * contextual classes are added as well. */ pullRight: PropTypes.bool, /** * Float the Nav to the left. When `navbar` is `true` the appropriate * contextual classes are added as well. */ pullLeft: PropTypes.bool }; var defaultProps = { justified: false, pullRight: false, pullLeft: false, stacked: false }; var contextTypes = { $bs_navbar: PropTypes.shape({ bsClass: PropTypes.string, onSelect: PropTypes.func }), $bs_tabContainer: PropTypes.shape({ activeKey: PropTypes.any, onSelect: PropTypes.func.isRequired, getTabId: PropTypes.func.isRequired, getPaneId: PropTypes.func.isRequired }) }; var Nav = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(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.find(children, function (child) { return _this.isActive(child, activeKey, activeHref); }); var childrenArray = ValidComponentChildren.toArray(children); var activeChildIndex = childrenArray.indexOf(activeChild); var childNodes = ReactDOM.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" ? warning(this.props.activeKey == null && !this.props.activeHref, 'Specifying a `