@epignosis_llc/gnosis 6.8.0 → 6.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22617,7 +22617,7 @@ var TabsContent = function TabsContent(_ref) {
22617
22617
  }, content) : null;
22618
22618
  };
22619
22619
 
22620
- var _excluded$w = ["tabs", "stickyHeader", "selectedTab", "onChangeTab", "inlineEndComponent", "testIds"];
22620
+ var _excluded$w = ["tabs", "stickyHeader", "selectedTab", "controlled", "onChangeTab", "inlineEndComponent", "testIds"];
22621
22621
  var Tabs = function Tabs(_ref) {
22622
22622
  var _ref$tabs = _ref.tabs,
22623
22623
  tabs = _ref$tabs === void 0 ? [] : _ref$tabs,
@@ -22625,24 +22625,39 @@ var Tabs = function Tabs(_ref) {
22625
22625
  stickyHeader = _ref$stickyHeader === void 0 ? false : _ref$stickyHeader,
22626
22626
  _ref$selectedTab = _ref.selectedTab,
22627
22627
  selectedTab = _ref$selectedTab === void 0 ? 0 : _ref$selectedTab,
22628
+ _ref$controlled = _ref.controlled,
22629
+ controlled = _ref$controlled === void 0 ? false : _ref$controlled,
22628
22630
  onChangeTab = _ref.onChangeTab,
22629
22631
  inlineEndComponent = _ref.inlineEndComponent,
22630
22632
  testIds = _ref.testIds,
22631
22633
  rest = _objectWithoutProperties$1(_ref, _excluded$w);
22632
22634
  var _useState = React.useState(selectedTab),
22633
22635
  _useState2 = _slicedToArray$1(_useState, 2),
22634
- activeTab = _useState2[0],
22635
- setActiveTab = _useState2[1];
22636
- var tabsLength = tabs.length - 1;
22636
+ internalActiveTab = _useState2[0],
22637
+ setInternalActiveTab = _useState2[1];
22638
+ // Tabs without content are not rendered, so every index (selection, bounds, keyboard,
22639
+ // arrows) refers to this filtered collection — matching what onChangeTab emits.
22640
+ var tabsWithContent = tabs.filter(function (tab) {
22641
+ return tab.content;
22642
+ });
22643
+ var tabsLength = tabsWithContent.length - 1;
22637
22644
  var tabsNavEl = React.useRef(null);
22638
22645
  var _useState3 = React.useState(false),
22639
22646
  _useState4 = _slicedToArray$1(_useState3, 2),
22640
22647
  isOverflowActive = _useState4[0],
22641
22648
  setIsOverflowActive = _useState4[1];
22642
22649
  var dir = document.dir;
22650
+ var clampTabIndex = function clampTabIndex(index) {
22651
+ if (index < 0) return 0;
22652
+ if (index > tabsLength) return tabsLength;
22653
+ return index;
22654
+ };
22655
+ var activeTab = controlled ? clampTabIndex(selectedTab) : internalActiveTab;
22643
22656
  var onSelectTab = function onSelectTab(index) {
22644
22657
  scrollToTab(index);
22645
- setActiveTab(index);
22658
+ if (!controlled) {
22659
+ setInternalActiveTab(index);
22660
+ }
22646
22661
  onChangeTab && onChangeTab(index);
22647
22662
  };
22648
22663
  var showLeftArrow = function showLeftArrow() {
@@ -22651,33 +22666,21 @@ var Tabs = function Tabs(_ref) {
22651
22666
  };
22652
22667
  var handLeftArrowClick = function handLeftArrowClick() {
22653
22668
  if (activeTab > 0) {
22654
- scrollToTab(activeTab - 1);
22655
- setActiveTab(function (currentTab) {
22656
- return currentTab - 1;
22657
- });
22669
+ // Route through onSelectTab so controlled parents are notified of the new selection.
22670
+ onSelectTab(activeTab - 1);
22658
22671
  }
22659
22672
  };
22660
22673
  var showRightArrow = function showRightArrow() {
22661
- if (!isOverflowActive || !tabs.length) return false;
22674
+ if (!isOverflowActive || !tabsWithContent.length) return false;
22662
22675
  return activeTab < tabsLength;
22663
22676
  };
22664
22677
  var handRightArrowClick = function handRightArrowClick() {
22665
- if (tabs.length && activeTab < tabsLength) {
22666
- scrollToTab(activeTab + 1);
22667
- setActiveTab(function (currentTab) {
22668
- return currentTab + 1;
22669
- });
22678
+ if (tabsWithContent.length && activeTab < tabsLength) {
22679
+ onSelectTab(activeTab + 1);
22670
22680
  }
22671
22681
  };
22672
22682
  React.useEffect(function () {
22673
- var newSelectedTab = selectedTab;
22674
- if (selectedTab < 0) {
22675
- newSelectedTab = 0;
22676
- }
22677
- if (selectedTab > tabsLength) {
22678
- newSelectedTab = tabsLength;
22679
- }
22680
- setActiveTab(newSelectedTab);
22683
+ setInternalActiveTab(clampTabIndex(selectedTab));
22681
22684
  }, [selectedTab]);
22682
22685
  React.useEffect(function () {
22683
22686
  toggleTabsArrow();
@@ -22706,15 +22709,9 @@ var Tabs = function Tabs(_ref) {
22706
22709
  };
22707
22710
  var handleKeyDown = function handleKeyDown(e, index) {
22708
22711
  if (e.key === "ArrowRight" && index < tabsLength) {
22709
- // If next tab is undefined, do nothing
22710
- if (tabs[index + 1].content) {
22711
- onSelectTab(index + 1);
22712
- }
22712
+ onSelectTab(index + 1);
22713
22713
  } else if (e.key === "ArrowLeft" && index > 0) {
22714
- // If prev tab is undefined, do nothing
22715
- if (tabs[index - 1].content) {
22716
- onSelectTab(index - 1);
22717
- }
22714
+ onSelectTab(index - 1);
22718
22715
  }
22719
22716
  };
22720
22717
  return jsx("section", _extends$s({
@@ -22743,9 +22740,7 @@ var Tabs = function Tabs(_ref) {
22743
22740
  ref: tabsNavEl
22744
22741
  }, (testIds === null || testIds === void 0 ? void 0 : testIds.nav) && {
22745
22742
  "data-testid": testIds.nav
22746
- }), tabs.filter(function (tab) {
22747
- return tab.content;
22748
- }).map(function (_ref2, index) {
22743
+ }), tabsWithContent.map(function (_ref2, index) {
22749
22744
  var title = _ref2.title,
22750
22745
  id = _ref2.id;
22751
22746
  return jsx(TabsNavItem, {
@@ -22777,9 +22772,7 @@ var Tabs = function Tabs(_ref) {
22777
22772
  role: "region"
22778
22773
  }, (testIds === null || testIds === void 0 ? void 0 : testIds.content) && {
22779
22774
  "data-testid": testIds.content
22780
- }), tabs.filter(function (tab) {
22781
- return tab.content;
22782
- }).map(function (_ref3, index) {
22775
+ }), tabsWithContent.map(function (_ref3, index) {
22783
22776
  var content = _ref3.content;
22784
22777
  return jsx(TabsContent, {
22785
22778
  key: index,