bianic-ui 2.14.0 → 2.15.0-beta.0

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.
Files changed (116) hide show
  1. package/dist/cjs/index.js +1121 -164
  2. package/dist/cjs/lib.css +1 -1
  3. package/dist/cjs/types/components/Button/ContextualButton/ContextualButton.d.ts +4 -1
  4. package/dist/cjs/types/components/Button/ContextualButton/config.d.ts +4 -0
  5. package/dist/cjs/types/components/Button/index.d.ts +1 -0
  6. package/dist/cjs/types/components/FileTree/TreeItem.d.ts +3 -2
  7. package/dist/cjs/types/components/FileTree/configs.d.ts +7 -0
  8. package/dist/cjs/types/components/FileTree/types.d.ts +1 -0
  9. package/dist/cjs/types/components/Forms/DatePicker/DateInputDisplay.d.ts +4 -1
  10. package/dist/cjs/types/components/Forms/DatePicker/PickerCalendar/components/DateDisplay.d.ts +4 -1
  11. package/dist/cjs/types/components/Forms/DatePicker/PickerCalendar/components/PickerContent.d.ts +2 -1
  12. package/dist/cjs/types/components/Forms/DatePicker/PickerCalendar/components/SinglePicker.d.ts +2 -1
  13. package/dist/cjs/types/components/Forms/DatePicker/PickerCalendar/hooks/useGridKeyboard.d.ts +11 -0
  14. package/dist/cjs/types/components/Forms/Dropdown/DropdownItem.d.ts +1 -1
  15. package/dist/cjs/types/components/Forms/DropdownItem/Custom.d.ts +3 -1
  16. package/dist/cjs/types/components/Forms/DropdownItem/Default.d.ts +3 -1
  17. package/dist/cjs/types/components/Forms/LiveSearch/hooks/useLiveSearch.d.ts +2 -0
  18. package/dist/cjs/types/components/Forms/LiveSearch/utils/dropdownUtils.d.ts +7 -2
  19. package/dist/cjs/types/components/Forms/SelectInput/index.d.ts +1 -1
  20. package/dist/cjs/types/components/Forms/TagLabelInput/hooks/useLiveSearch.d.ts +2 -0
  21. package/dist/cjs/types/components/Forms/TagLabelInput/utils/dropdownUtils.d.ts +7 -2
  22. package/dist/cjs/types/components/Menu/MenuItem.d.ts +1 -1
  23. package/dist/cjs/types/components/Table/TableFilter/TableFilterButton.d.ts +4 -0
  24. package/dist/cjs/types/components/Table/TableFilter/TableFilterPanel.d.ts +4 -0
  25. package/dist/cjs/types/components/Table/TableFilter/configs.d.ts +6 -0
  26. package/dist/cjs/types/components/Table/TableFilter/index.d.ts +3 -0
  27. package/dist/cjs/types/components/Table/TableFilter/types.d.ts +19 -0
  28. package/dist/cjs/types/components/Table/index.d.ts +2 -0
  29. package/dist/cjs/types/components/index.d.ts +4 -2
  30. package/dist/cjs/types/stories/Button/ContextualButton.stories.d.ts +90 -0
  31. package/dist/cjs/types/stories/Button/ContextualButton.test.stories.d.ts +28 -0
  32. package/dist/cjs/types/stories/FileTree/FileTree.test.stories.d.ts +40 -0
  33. package/dist/cjs/types/stories/FileTree/FileTreeSimulation.stories.d.ts +3 -0
  34. package/dist/cjs/types/stories/Form/DatePicker/DatePicker.test.stories.d.ts +50 -0
  35. package/dist/cjs/types/stories/Form/DatePicker/Datepicker.stories.d.ts +162 -2
  36. package/dist/cjs/types/stories/Form/DatePicker/YearPicker.stories.d.ts +2 -1
  37. package/dist/cjs/types/stories/Form/Dropdown/DropdownContainer.stories.d.ts +1 -0
  38. package/dist/cjs/types/stories/Form/Dropdown/DropdownContainer.test.stories.d.ts +8 -0
  39. package/dist/cjs/types/stories/Form/LiveSearch/Livesearch.stories.d.ts +2 -0
  40. package/dist/cjs/types/stories/Form/LiveSearch/Livesearch.test.stories.d.ts +7 -0
  41. package/dist/cjs/types/stories/Form/SelectInput/SelectInput.stories.d.ts +3 -0
  42. package/dist/cjs/types/stories/Form/SelectInput/SelectInput.test.stories.d.ts +30 -0
  43. package/dist/cjs/types/stories/Form/TagLabelInput/TagLabelInput.stories.d.ts +1 -0
  44. package/dist/cjs/types/stories/Form/TagLabelInput/TagLabelInput.test.stories.d.ts +28 -0
  45. package/dist/cjs/types/stories/Form/TextInput/TextInput.stories.d.ts +1 -0
  46. package/dist/cjs/types/stories/Form/TextInput/TextInput.test.stories.d.ts +26 -0
  47. package/dist/cjs/types/stories/Menu/Menu.test.stories.d.ts +28 -0
  48. package/dist/cjs/types/stories/Menu/NestedExample.stories.d.ts +2 -0
  49. package/dist/cjs/types/stories/Progress/Bar/ProgressBar.stories.d.ts +13 -0
  50. package/dist/cjs/types/stories/Progress/Bar/ProgressBarSimulation.stories.d.ts +6 -0
  51. package/dist/cjs/types/stories/Table/AppliedFilterExample.d.ts +3 -0
  52. package/dist/cjs/types/stories/Table/TableFilterButton.stories.d.ts +76 -0
  53. package/dist/cjs/types/stories/Table/TableFilterButton.test.stories.d.ts +28 -0
  54. package/dist/cjs/types/stories/Table/TableFilterPanel.stories.d.ts +122 -0
  55. package/dist/cjs/types/stories/Table/TableFilterPanel.test.stories.d.ts +39 -0
  56. package/dist/cjs/types/stories/Table/tableFilterSamples.d.ts +55 -0
  57. package/dist/cjs/types/utility/hooks/useListKeyboard.d.ts +14 -0
  58. package/dist/esm/index.js +1120 -165
  59. package/dist/esm/lib.css +1 -1
  60. package/dist/esm/types/components/Button/ContextualButton/ContextualButton.d.ts +4 -1
  61. package/dist/esm/types/components/Button/ContextualButton/config.d.ts +4 -0
  62. package/dist/esm/types/components/Button/index.d.ts +1 -0
  63. package/dist/esm/types/components/FileTree/TreeItem.d.ts +3 -2
  64. package/dist/esm/types/components/FileTree/configs.d.ts +7 -0
  65. package/dist/esm/types/components/FileTree/types.d.ts +1 -0
  66. package/dist/esm/types/components/Forms/DatePicker/DateInputDisplay.d.ts +4 -1
  67. package/dist/esm/types/components/Forms/DatePicker/PickerCalendar/components/DateDisplay.d.ts +4 -1
  68. package/dist/esm/types/components/Forms/DatePicker/PickerCalendar/components/PickerContent.d.ts +2 -1
  69. package/dist/esm/types/components/Forms/DatePicker/PickerCalendar/components/SinglePicker.d.ts +2 -1
  70. package/dist/esm/types/components/Forms/DatePicker/PickerCalendar/hooks/useGridKeyboard.d.ts +11 -0
  71. package/dist/esm/types/components/Forms/Dropdown/DropdownItem.d.ts +1 -1
  72. package/dist/esm/types/components/Forms/DropdownItem/Custom.d.ts +3 -1
  73. package/dist/esm/types/components/Forms/DropdownItem/Default.d.ts +3 -1
  74. package/dist/esm/types/components/Forms/LiveSearch/hooks/useLiveSearch.d.ts +2 -0
  75. package/dist/esm/types/components/Forms/LiveSearch/utils/dropdownUtils.d.ts +7 -2
  76. package/dist/esm/types/components/Forms/SelectInput/index.d.ts +1 -1
  77. package/dist/esm/types/components/Forms/TagLabelInput/hooks/useLiveSearch.d.ts +2 -0
  78. package/dist/esm/types/components/Forms/TagLabelInput/utils/dropdownUtils.d.ts +7 -2
  79. package/dist/esm/types/components/Menu/MenuItem.d.ts +1 -1
  80. package/dist/esm/types/components/Table/TableFilter/TableFilterButton.d.ts +4 -0
  81. package/dist/esm/types/components/Table/TableFilter/TableFilterPanel.d.ts +4 -0
  82. package/dist/esm/types/components/Table/TableFilter/configs.d.ts +6 -0
  83. package/dist/esm/types/components/Table/TableFilter/index.d.ts +3 -0
  84. package/dist/esm/types/components/Table/TableFilter/types.d.ts +19 -0
  85. package/dist/esm/types/components/Table/index.d.ts +2 -0
  86. package/dist/esm/types/components/index.d.ts +4 -2
  87. package/dist/esm/types/stories/Button/ContextualButton.stories.d.ts +90 -0
  88. package/dist/esm/types/stories/Button/ContextualButton.test.stories.d.ts +28 -0
  89. package/dist/esm/types/stories/FileTree/FileTree.test.stories.d.ts +40 -0
  90. package/dist/esm/types/stories/FileTree/FileTreeSimulation.stories.d.ts +3 -0
  91. package/dist/esm/types/stories/Form/DatePicker/DatePicker.test.stories.d.ts +50 -0
  92. package/dist/esm/types/stories/Form/DatePicker/Datepicker.stories.d.ts +162 -2
  93. package/dist/esm/types/stories/Form/DatePicker/YearPicker.stories.d.ts +2 -1
  94. package/dist/esm/types/stories/Form/Dropdown/DropdownContainer.stories.d.ts +1 -0
  95. package/dist/esm/types/stories/Form/Dropdown/DropdownContainer.test.stories.d.ts +8 -0
  96. package/dist/esm/types/stories/Form/LiveSearch/Livesearch.stories.d.ts +2 -0
  97. package/dist/esm/types/stories/Form/LiveSearch/Livesearch.test.stories.d.ts +7 -0
  98. package/dist/esm/types/stories/Form/SelectInput/SelectInput.stories.d.ts +3 -0
  99. package/dist/esm/types/stories/Form/SelectInput/SelectInput.test.stories.d.ts +30 -0
  100. package/dist/esm/types/stories/Form/TagLabelInput/TagLabelInput.stories.d.ts +1 -0
  101. package/dist/esm/types/stories/Form/TagLabelInput/TagLabelInput.test.stories.d.ts +28 -0
  102. package/dist/esm/types/stories/Form/TextInput/TextInput.stories.d.ts +1 -0
  103. package/dist/esm/types/stories/Form/TextInput/TextInput.test.stories.d.ts +26 -0
  104. package/dist/esm/types/stories/Menu/Menu.test.stories.d.ts +28 -0
  105. package/dist/esm/types/stories/Menu/NestedExample.stories.d.ts +2 -0
  106. package/dist/esm/types/stories/Progress/Bar/ProgressBar.stories.d.ts +13 -0
  107. package/dist/esm/types/stories/Progress/Bar/ProgressBarSimulation.stories.d.ts +6 -0
  108. package/dist/esm/types/stories/Table/AppliedFilterExample.d.ts +3 -0
  109. package/dist/esm/types/stories/Table/TableFilterButton.stories.d.ts +76 -0
  110. package/dist/esm/types/stories/Table/TableFilterButton.test.stories.d.ts +28 -0
  111. package/dist/esm/types/stories/Table/TableFilterPanel.stories.d.ts +122 -0
  112. package/dist/esm/types/stories/Table/TableFilterPanel.test.stories.d.ts +39 -0
  113. package/dist/esm/types/stories/Table/tableFilterSamples.d.ts +55 -0
  114. package/dist/esm/types/utility/hooks/useListKeyboard.d.ts +14 -0
  115. package/dist/index.d.ts +34 -6
  116. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -111,6 +111,8 @@ function TbCircleFilled (props) {
111
111
  return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":"2","strokeLinecap":"round","strokeLinejoin":"round"},"child":[{"tag":"path","attr":{"d":"M12 3a9 9 0 1 0 9 9"},"child":[]}]})(props);
112
112
  }function TbFolderOpen (props) {
113
113
  return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":"2","strokeLinecap":"round","strokeLinejoin":"round"},"child":[{"tag":"path","attr":{"d":"M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2"},"child":[]}]})(props);
114
+ }function TbFilter (props) {
115
+ return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":"2","strokeLinecap":"round","strokeLinejoin":"round"},"child":[{"tag":"path","attr":{"d":"M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227z"},"child":[]}]})(props);
114
116
  }function TbFile (props) {
115
117
  return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":"2","strokeLinecap":"round","strokeLinejoin":"round"},"child":[{"tag":"path","attr":{"d":"M14 3v4a1 1 0 0 0 1 1h4"},"child":[]},{"tag":"path","attr":{"d":"M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z"},"child":[]}]})(props);
116
118
  }function TbEye (props) {
@@ -539,11 +541,11 @@ var BUTTON_VARIANT_UNION = [
539
541
  'form-group',
540
542
  ];
541
543
  var RADIUS_UNION = ['default', 'full-rounded'];
542
- var SIZE_UNION = ['md', 'lg', 'sm', 'tn'];
544
+ var SIZE_UNION$1 = ['md', 'lg', 'sm', 'tn'];
543
545
  var Button = React.forwardRef(function (_a, ref) {
544
546
  var label = _a.label, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.radius, radius = _d === void 0 ? 'default' : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.variant, variant = _f === void 0 ? 'default' : _f, _g = _a.iconLeft, iconLeft = _g === void 0 ? null : _g, _h = _a.iconRight, iconRight = _h === void 0 ? null : _h, _j = _a.left, left = _j === void 0 ? null : _j, _k = _a.right, right = _k === void 0 ? null : _k, minWidth = _a.minWidth, _l = _a.iconSize, iconSize = _l === void 0 ? undefined : _l, props = __rest(_a, ["label", "className", "disabled", "radius", "size", "variant", "iconLeft", "iconRight", "left", "right", "minWidth", "iconSize"]);
545
547
  var validatedVariant = validUnion(variant, BUTTON_VARIANT_UNION);
546
- var validatedSize = validUnion(size, SIZE_UNION);
548
+ var validatedSize = validUnion(size, SIZE_UNION$1);
547
549
  var validatedRadius = validUnion(radius, RADIUS_UNION);
548
550
  var variantTextColorClasses = variantConfig$3[validatedVariant]
549
551
  .split(/\s+/)
@@ -1645,24 +1647,36 @@ function ButtonApp(_a) {
1645
1647
  return (React.createElement("button", __assign({ className: "button-app flex max-h-[30px] items-center justify-center px-[10px] pb-[8.3px] pt-[8.5px] font-arial text-size-tiny ".concat(colorConfig$2[color][buttonState], " ").concat(extended), type: "button", disabled: disabled }, rest), label));
1646
1648
  }
1647
1649
 
1650
+ var sizeUnion$6 = ['tn', 'sm'];
1651
+ var minHeightConfig$1 = {
1652
+ tn: 'min-h-[23px]',
1653
+ sm: 'min-h-[30px]',
1654
+ };
1655
+ var paddingConfig = {
1656
+ tn: 'p-[1px]',
1657
+ sm: 'px-1 py-[1px]',
1658
+ };
1648
1659
  var textColorConfig = {
1649
1660
  dark: 'text-primary-black disabled:text-bia-coolgrey-disabled',
1650
1661
  light: 'text-primary-white disabled:opacity-30',
1651
1662
  };
1652
1663
  var stateColorConfig = {
1653
- selected: 'bg-black/15 cursor-default',
1664
+ selected: 'bg-black/15 cursor-default focus-visible:border-bia-blue-disabled focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-bia-blue-disabled',
1654
1665
  default: 'enabled:hover:bg-black/10 enabled:focus-visible:border-bia-blue-disabled enabled:focus-visible:outline-2 enabled:focus-visible:-outline-offset-1 enabled:focus-visible:outline-bia-blue-disabled enabled:active:bg-black/15',
1655
1666
  };
1656
1667
 
1657
1668
  function ContextualButtonInner(_a, ref) {
1658
- var _b = _a.actionElement, actionElement = _b === void 0 ? undefined : _b, _c = _a.label, label = _c === void 0 ? '' : _c, _d = _a.icon, icon = _d === void 0 ? undefined : _d, _e = _a.variant, variant = _e === void 0 ? 'dark' : _e, disabled = _a.disabled, _f = _a.isSelected, isSelected = _f === void 0 ? false : _f, props = __rest(_a, ["actionElement", "label", "icon", "variant", "disabled", "isSelected"]);
1669
+ var _b = _a.actionElement, actionElement = _b === void 0 ? undefined : _b, _c = _a.label, label = _c === void 0 ? '' : _c, _d = _a.icon, icon = _d === void 0 ? undefined : _d, _e = _a.variant, variant = _e === void 0 ? 'dark' : _e, _f = _a.size, size = _f === void 0 ? 'tn' : _f, disabled = _a.disabled, _g = _a.isSelected, isSelected = _g === void 0 ? false : _g, _h = _a.isNotified, isNotified = _h === void 0 ? false : _h, props = __rest(_a, ["actionElement", "label", "icon", "variant", "size", "disabled", "isSelected", "isNotified"]);
1659
1670
  var textColor = textColorConfig[variant];
1660
1671
  if (isSelected) {
1661
1672
  textColor = variant === 'dark' ? 'text-primary-black' : 'text-primary-white';
1662
1673
  }
1663
1674
  var stateColor = stateColorConfig[isSelected ? 'selected' : 'default'];
1664
- return (React.createElement("button", __assign({ ref: ref, type: "button", className: "bianic-contextual-button box-border flex min-h-[23px] flex-row items-center rounded-radius-sm border border-transparent p-[1px] outline-none ".concat(stateColor, " ").concat(textColor) }, props, { disabled: disabled }),
1675
+ var notifiedClass = isNotified ? 'relative ' : '';
1676
+ var validSize = validUnion(size, sizeUnion$6);
1677
+ return (React.createElement("button", __assign({ ref: ref, type: "button", className: "bianic-contextual-button ".concat(notifiedClass, "box-border flex ").concat(minHeightConfig$1[validSize], " flex-row items-center rounded-radius-sm border border-transparent ").concat(paddingConfig[validSize], " outline-none ").concat(stateColor, " ").concat(textColor) }, props, { disabled: disabled }),
1665
1678
  icon,
1679
+ isNotified && (React.createElement("span", { "aria-hidden": "true", className: "absolute -right-[3px] -top-[3px] size-1.5 rounded-radius-full bg-bia-red" })),
1666
1680
  label && (React.createElement("div", { className: "label flex max-h-[46px] items-center gap-x-0.5 px-[5px] text-[12px] leading-none" },
1667
1681
  React.createElement("span", null, label),
1668
1682
  actionElement))));
@@ -1847,8 +1861,31 @@ function Divider(_a) {
1847
1861
  return (React.createElement("div", { className: "bianic-divider bg-bia-grey-light-50 ".concat(margin, " ").concat(config, " ").concat(className) }));
1848
1862
  }
1849
1863
 
1864
+ var TREE_ITEM_SIZES = ['sm', 'md'];
1865
+ var headerSizeConfig = {
1866
+ sm: '',
1867
+ md: 'py-[3px]',
1868
+ };
1869
+ var chevronIconSize = {
1870
+ sm: 18,
1871
+ md: 20,
1872
+ };
1873
+ var placeholderSizeConfig = {
1874
+ sm: 'min-w-[18px]',
1875
+ md: 'min-w-5',
1876
+ };
1877
+ var labelSizeConfig$1 = {
1878
+ sm: 'px-0.5 py-[0.5px] text-size-sm',
1879
+ md: 'min-h-5 px-[3px] text-size-base leading-5',
1880
+ };
1881
+ var childrenSizeConfig = {
1882
+ sm: 'gap-0.5 pl-[18px]',
1883
+ md: 'pl-5',
1884
+ };
1885
+
1850
1886
  function TreeItem(_a) {
1851
- var data = _a.data, expandedData = _a.expandedData, setExpandedData = _a.setExpandedData, dataMap = _a.dataMap, _b = _a.activeUnitId, activeUnitId = _b === void 0 ? undefined : _b, _c = _a.handleChevronClick, handleChevronClick = _c === void 0 ? undefined : _c, _d = _a.handleRightClick, handleRightClick = _d === void 0 ? undefined : _d, _e = _a.handleClick, handleClick = _e === void 0 ? undefined : _e;
1887
+ var data = _a.data, expandedData = _a.expandedData, setExpandedData = _a.setExpandedData, dataMap = _a.dataMap, _b = _a.activeUnitId, activeUnitId = _b === void 0 ? undefined : _b, _c = _a.size, size = _c === void 0 ? 'sm' : _c, _d = _a.handleChevronClick, handleChevronClick = _d === void 0 ? undefined : _d, _e = _a.handleRightClick, handleRightClick = _e === void 0 ? undefined : _e, _f = _a.handleClick, handleClick = _f === void 0 ? undefined : _f;
1888
+ var validSize = validUnion(size, TREE_ITEM_SIZES);
1852
1889
  var isExpanded = !!expandedData.get(data.id);
1853
1890
  var hasActiveDescendant = function (unit) {
1854
1891
  var _a;
@@ -1889,14 +1926,16 @@ function TreeItem(_a) {
1889
1926
  handleChevronClick === null || handleChevronClick === void 0 ? void 0 : handleChevronClick(data);
1890
1927
  };
1891
1928
  return (React.createElement("div", { className: "tree-item", role: "treeitem", "aria-expanded": data.children ? isExpanded : undefined, "aria-selected": activeUnitId === data.id },
1892
- React.createElement("div", { className: "tree-item-header flex items-center justify-start" },
1929
+ React.createElement("div", { className: cn$1('tree-item-header flex items-center justify-start', headerSizeConfig[validSize]) },
1893
1930
  data.children ? (React.createElement("button", { className: "tree-item-chevron", onClick: chevronClickHandler, type: "button", "aria-label": isExpanded ? 'Collapse' : 'Expand' },
1894
- React.createElement(TbChevronRight, { className: "chevron ".concat(isChevronActive ? 'text-bia-green hover:text-bia-green-light-10' : 'text-bia-coolgrey-light-50 hover:text-bia-coolgrey-light-20', " ").concat(isExpanded ? 'rotate-90' : ''), size: 18, "aria-hidden": "true" }))) : (React.createElement("div", { className: "chevron-placeholder aspect-square min-w-[18px]" })),
1895
- React.createElement("button", { className: "tree-item-label rounded-radius-sm px-0.5 py-[0.5px] text-start font-segoe text-size-sm font-normal text-bia-black ".concat(activeUnitId === data.id ? 'bg-bia-green-light-70' : 'hover:bg-bia-coolgrey-light-90'), onClick: clickItemHandler, type: "button", onContextMenu: function (e) {
1931
+ React.createElement(TbChevronRight, { className: "chevron ".concat(isChevronActive ? 'text-bia-green hover:text-bia-green-light-10' : 'text-bia-coolgrey-light-50 hover:text-bia-coolgrey-light-20', " ").concat(isExpanded ? 'rotate-90' : ''), size: chevronIconSize[validSize], "aria-hidden": "true" }))) : (React.createElement("div", { className: cn$1('chevron-placeholder aspect-square', placeholderSizeConfig[validSize]) })),
1932
+ React.createElement("button", { className: cn$1('tree-item-label rounded-radius-sm text-start font-segoe font-normal text-bia-black', labelSizeConfig$1[validSize], activeUnitId === data.id
1933
+ ? 'bg-bia-green-light-70'
1934
+ : 'hover:bg-bia-coolgrey-light-90'), onClick: clickItemHandler, type: "button", onContextMenu: function (e) {
1896
1935
  e.preventDefault();
1897
1936
  handleRightClick === null || handleRightClick === void 0 ? void 0 : handleRightClick(data);
1898
1937
  } }, data.label)),
1899
- isExpanded && data.children && (React.createElement("div", { className: "tree-item-children flex flex-col gap-0.5 rounded-radius-sm pl-[18px]", role: "group" }, data.children.map(function (childUnit) { return (React.createElement(TreeItem, { key: childUnit.id, data: childUnit, expandedData: expandedData, setExpandedData: setExpandedData, dataMap: dataMap, activeUnitId: activeUnitId, handleChevronClick: handleChevronClick, handleRightClick: handleRightClick, handleClick: handleClick })); })))));
1938
+ isExpanded && data.children && (React.createElement("div", { className: cn$1('tree-item-children flex flex-col rounded-radius-sm', childrenSizeConfig[validSize]), role: "group" }, data.children.map(function (childUnit) { return (React.createElement(TreeItem, { key: childUnit.id, data: childUnit, expandedData: expandedData, setExpandedData: setExpandedData, dataMap: dataMap, activeUnitId: activeUnitId, size: validSize, handleChevronClick: handleChevronClick, handleRightClick: handleRightClick, handleClick: handleClick })); })))));
1900
1939
  }
1901
1940
  var TreeItem$1 = React.memo(TreeItem);
1902
1941
 
@@ -2104,6 +2143,151 @@ var usePopupPosition = function (anchorRef, popupRef, position) {
2104
2143
  return [positionStyle, calcPosition];
2105
2144
  };
2106
2145
 
2146
+ // Internal helpers for keyboard navigation in dropdowns and menus (BIAN-259).
2147
+ // Not exported from any index file.
2148
+ // Top-level items of a list, matched against the existing markup:
2149
+ // - DropdownItem: `.bianic-dropdown-item > button`
2150
+ // - MenuItem: the `[role="button"]` child of each direct child div
2151
+ // - DefaultDropdownItem / CustomDropdownItem: direct `[role="button"]` children
2152
+ var ITEM_SELECTOR = [
2153
+ ':scope > .bianic-dropdown-item > button:not(:disabled)',
2154
+ ':scope > div > [role="button"]:not([aria-disabled="true"])',
2155
+ ':scope > [role="button"]:not([aria-disabled="true"])',
2156
+ ].join(', ');
2157
+ function getEnabledItems(list) {
2158
+ if (!list)
2159
+ return [];
2160
+ return Array.from(list.querySelectorAll(ITEM_SELECTOR));
2161
+ }
2162
+ // Wraps around. `current` -1 means nothing is highlighted.
2163
+ function nextIndex(current, delta, count) {
2164
+ if (count <= 0)
2165
+ return -1;
2166
+ if (current < 0)
2167
+ return delta > 0 ? 0 : count - 1;
2168
+ return (current + delta + count) % count;
2169
+ }
2170
+ // Highlight for the option picked by arrow keys in a form field list
2171
+ var OPTION_HIGHLIGHT_CLASS = '!bg-bia-blue-pastel outline outline-[3px] -outline-offset-[3px] outline-bia-blue-light-50';
2172
+ function getOptionId(baseId, index) {
2173
+ return "".concat(baseId, "-option-").concat(index);
2174
+ }
2175
+ function scrollOptionIntoView(id) {
2176
+ var _a, _b;
2177
+ (_b = (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(_a, { block: 'nearest' });
2178
+ }
2179
+ function isEditable(target) {
2180
+ if (!(target instanceof HTMLElement))
2181
+ return false;
2182
+ return (target.isContentEditable ||
2183
+ target instanceof HTMLTextAreaElement ||
2184
+ target instanceof HTMLSelectElement ||
2185
+ target instanceof HTMLInputElement);
2186
+ }
2187
+ // Open menus in the order they opened. Only one menu reacts to a key press.
2188
+ var openMenus = [];
2189
+ function holdsFocus(entry) {
2190
+ var _a, _b;
2191
+ var active = document.activeElement;
2192
+ if (!active || active === document.body)
2193
+ return false;
2194
+ return !!(((_a = entry.getList()) === null || _a === void 0 ? void 0 : _a.contains(active)) || ((_b = entry.getAnchor()) === null || _b === void 0 ? void 0 : _b.contains(active)));
2195
+ }
2196
+ function shouldReact(entry) {
2197
+ var focused = openMenus.filter(holdsFocus);
2198
+ if (focused.length > 0)
2199
+ return focused[focused.length - 1] === entry;
2200
+ return openMenus[openMenus.length - 1] === entry;
2201
+ }
2202
+ // Arrow keys, Escape and Tab for a menu that is open.
2203
+ // Enter and Space are handled by the items themselves.
2204
+ function useMenuKeyboard(_a) {
2205
+ var open = _a.open, onClose = _a.onClose, listRef = _a.listRef, _b = _a.anchorRef, anchorRef = _b === void 0 ? undefined : _b;
2206
+ var onCloseRef = React.useRef(onClose);
2207
+ onCloseRef.current = onClose;
2208
+ var returnFocusRef = React.useRef(null);
2209
+ var skipRestoreRef = React.useRef(false);
2210
+ var wasOpenRef = React.useRef(false);
2211
+ React.useEffect(function () {
2212
+ var _a, _b;
2213
+ if (!open) {
2214
+ if (wasOpenRef.current) {
2215
+ wasOpenRef.current = false;
2216
+ // Give focus back when it was lost on a hidden item
2217
+ var active_1 = document.activeElement;
2218
+ var list = listRef.current;
2219
+ var lost = !active_1 ||
2220
+ active_1 === document.body ||
2221
+ (list !== null && list.contains(active_1));
2222
+ var target = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : returnFocusRef.current;
2223
+ if (!skipRestoreRef.current && lost && (target === null || target === void 0 ? void 0 : target.isConnected)) {
2224
+ target.focus();
2225
+ }
2226
+ }
2227
+ return undefined;
2228
+ }
2229
+ wasOpenRef.current = true;
2230
+ skipRestoreRef.current = false;
2231
+ var active = document.activeElement;
2232
+ returnFocusRef.current =
2233
+ active && active !== document.body && !((_b = listRef.current) === null || _b === void 0 ? void 0 : _b.contains(active))
2234
+ ? active
2235
+ : null;
2236
+ var entry = {
2237
+ getList: function () { return listRef.current; },
2238
+ getAnchor: function () { var _a; return (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : null; },
2239
+ };
2240
+ openMenus.push(entry);
2241
+ var onKeyDown = function (e) {
2242
+ var _a;
2243
+ if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey)
2244
+ return;
2245
+ var key = e.key;
2246
+ if (key !== 'ArrowDown' &&
2247
+ key !== 'ArrowUp' &&
2248
+ key !== 'Escape' &&
2249
+ key !== 'Tab')
2250
+ return;
2251
+ if (!shouldReact(entry))
2252
+ return;
2253
+ if (key === 'Tab') {
2254
+ skipRestoreRef.current = true;
2255
+ onCloseRef.current();
2256
+ return;
2257
+ }
2258
+ if (key === 'Escape') {
2259
+ e.preventDefault();
2260
+ onCloseRef.current();
2261
+ return;
2262
+ }
2263
+ var list = listRef.current;
2264
+ if (!list)
2265
+ return;
2266
+ var target = e.target;
2267
+ var anchor = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current;
2268
+ if (isEditable(target) &&
2269
+ !list.contains(target) &&
2270
+ !(anchor === null || anchor === void 0 ? void 0 : anchor.contains(target)))
2271
+ return;
2272
+ var items = getEnabledItems(list);
2273
+ if (items.length === 0)
2274
+ return;
2275
+ e.preventDefault();
2276
+ var current = document.activeElement;
2277
+ var index = items.findIndex(function (item) { return item === current || item.contains(current); });
2278
+ var next = nextIndex(index, key === 'ArrowDown' ? 1 : -1, items.length);
2279
+ (_a = items[next]) === null || _a === void 0 ? void 0 : _a.focus();
2280
+ };
2281
+ document.addEventListener('keydown', onKeyDown);
2282
+ return function () {
2283
+ document.removeEventListener('keydown', onKeyDown);
2284
+ var at = openMenus.indexOf(entry);
2285
+ if (at >= 0)
2286
+ openMenus.splice(at, 1);
2287
+ };
2288
+ }, [open, listRef, anchorRef]);
2289
+ }
2290
+
2107
2291
  function MenuElementInner(_a) {
2108
2292
  var isTopFlat = _a.isTopFlat, children = _a.children, className = _a.className, zIndex = _a.zIndex, menuRef = _a.menuRef, onClose = _a.onClose, onClickItem = _a.onClickItem, _b = _a.style, style = _b === void 0 ? undefined : _b, _c = _a.onContextMenu, onContextMenu = _c === void 0 ? undefined : _c, restProps = __rest(_a, ["isTopFlat", "children", "className", "zIndex", "menuRef", "onClose", "onClickItem", "style", "onContextMenu"]);
2109
2293
  var radiusClass = "rounded-b-radius-sm ".concat(!isTopFlat && 'rounded-t-radius-sm');
@@ -2122,6 +2306,7 @@ function MenuContainer(_a) {
2122
2306
  var _b = _a.isTopFlat, isTopFlat = _b === void 0 ? false : _b, children = _a.children, _c = _a.open, open = _c === void 0 ? true : _c, _d = _a.onClose, onClose = _d === void 0 ? function () { } : _d, _e = _a.className, className = _e === void 0 ? '' : _e, _f = _a.isWithOverlay, isWithOverlay = _f === void 0 ? true : _f, _g = _a.zIndex, zIndex = _g === void 0 ? 100 : _g, _h = _a.onClickItem, onClickItem = _h === void 0 ? function () { } : _h, _j = _a.anchorRef, anchorRef = _j === void 0 ? undefined : _j, _k = _a.matchAnchorWidth, matchAnchorWidth = _k === void 0 ? undefined : _k, _l = _a.onContextMenu, onContextMenu = _l === void 0 ? undefined : _l, restProps = __rest(_a, ["isTopFlat", "children", "open", "onClose", "className", "isWithOverlay", "zIndex", "onClickItem", "anchorRef", "matchAnchorWidth", "onContextMenu"]);
2123
2307
  var MenuContainerRef = React.useRef(null);
2124
2308
  var positionStyle = usePopupPosition(anchorRef, MenuContainerRef)[0];
2309
+ useMenuKeyboard({ open: open, onClose: onClose, listRef: MenuContainerRef, anchorRef: anchorRef });
2125
2310
  var newStyle = React.useMemo(function () {
2126
2311
  var _a, _b;
2127
2312
  if (!(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current)) {
@@ -2186,9 +2371,12 @@ function MenuContainerNoAnchorInner(propsComp, ref) {
2186
2371
  var MenuContainerNoAnchor = React.forwardRef(MenuContainerNoAnchorInner);
2187
2372
 
2188
2373
  function MenuItem(_a) {
2189
- var _b = _a.className, className = _b === void 0 ? '' : _b, label = _a.label, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.caption, caption = _d === void 0 ? undefined : _d, _e = _a.isChecked, isChecked = _e === void 0 ? undefined : _e, _f = _a.onClose, onClose = _f === void 0 ? function () { } : _f, _g = _a.children, children = _g === void 0 ? undefined : _g, _h = _a.zIndex, zIndex = _h === void 0 ? 100 : _h, _j = _a.inheritedOnClick, inheritedOnClick = _j === void 0 ? function () { } : _j, _k = _a.disabled, disabled = _k === void 0 ? false : _k, props = __rest(_a, ["className", "label", "onClick", "caption", "isChecked", "onClose", "children", "zIndex", "inheritedOnClick", "disabled"]);
2190
- var _l = React.useState(false), isHovered = _l[0], setIsHovered = _l[1];
2191
- var _m = React.useState(false), isLeft = _m[0], setIsLeft = _m[1];
2374
+ var _b = _a.className, className = _b === void 0 ? '' : _b, label = _a.label, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.caption, caption = _d === void 0 ? undefined : _d, _e = _a.isChecked, isChecked = _e === void 0 ? undefined : _e, _f = _a.onClose, onClose = _f === void 0 ? function () { } : _f, _g = _a.children, children = _g === void 0 ? undefined : _g, _h = _a.zIndex, zIndex = _h === void 0 ? 100 : _h, _j = _a.inheritedOnClick, inheritedOnClick = _j === void 0 ? function () { } : _j, _k = _a.disabled, disabled = _k === void 0 ? false : _k, _l = _a.onKeyDown, consumerOnKeyDown = _l === void 0 ? undefined : _l, _m = _a.onFocus, consumerOnFocus = _m === void 0 ? undefined : _m, _o = _a.onBlur, consumerOnBlur = _o === void 0 ? undefined : _o, props = __rest(_a, ["className", "label", "onClick", "caption", "isChecked", "onClose", "children", "zIndex", "inheritedOnClick", "disabled", "onKeyDown", "onFocus", "onBlur"]);
2375
+ var _p = React.useState(false), isHovered = _p[0], setIsHovered = _p[1];
2376
+ var _q = React.useState(false), isKeyboardOpen = _q[0], setIsKeyboardOpen = _q[1];
2377
+ var _r = React.useState(false), isKeyFocused = _r[0], setIsKeyFocused = _r[1];
2378
+ var outerRef = React.useRef(null);
2379
+ var _s = React.useState(false), isLeft = _s[0], setIsLeft = _s[1];
2192
2380
  var isWithChecked = isChecked !== undefined;
2193
2381
  var leftPadding = isWithChecked ? 'pl-[5px]' : 'pl-[10px]';
2194
2382
  var rightPadding = caption || children ? 'pr-[5px]' : 'pr-[10px]';
@@ -2205,24 +2393,87 @@ function MenuItem(_a) {
2205
2393
  else
2206
2394
  setIsLeft(false);
2207
2395
  }
2208
- }, [isHovered]);
2396
+ }, [isHovered, isKeyboardOpen]);
2209
2397
  var translateClass = isLeft
2210
2398
  ? 'left-0 -translate-x-full'
2211
2399
  : 'right-0 translate-x-full';
2212
2400
  var currentZIndex = zIndex + 10;
2213
- return (React.createElement("div", { className: "group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[6px] last:rounded-b-radius-sm last:pb-[6px]", onMouseEnter: function () { return !disabled && setIsHovered(true); }, onMouseLeave: function () { return !disabled && setIsHovered(false); } },
2214
- React.createElement("div", __assign({ className: "relative flex items-center bg-bia-white py-[5px] ".concat(itemClass, " ").concat(disabled ? 'cursor-not-allowed' : 'hover:bg-bia-blue-pastel'), role: "button", "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, onClick: function (e) {
2401
+ var handleKeyDown = function (e) {
2402
+ if (e.target === e.currentTarget && !disabled) {
2403
+ var isActivateKey = e.key === 'Enter' || e.key === ' ';
2404
+ if (children && (isActivateKey || e.key === 'ArrowRight')) {
2405
+ e.preventDefault();
2406
+ setIsKeyboardOpen(true);
2407
+ requestAnimationFrame(function () {
2408
+ var _a;
2409
+ (_a = getEnabledItems(MenuContRef.current)[0]) === null || _a === void 0 ? void 0 : _a.focus();
2410
+ });
2411
+ }
2412
+ else if (!children && isActivateKey) {
2413
+ // Same code as a mouse click (R34)
2414
+ e.preventDefault();
2415
+ e.currentTarget.click();
2416
+ }
2417
+ }
2418
+ consumerOnKeyDown === null || consumerOnKeyDown === void 0 ? void 0 : consumerOnKeyDown(e);
2419
+ };
2420
+ var handleSubMenuKeyDown = function (e) {
2421
+ var _a, _b, _c;
2422
+ if (e.key === 'ArrowLeft' || e.key === 'Escape') {
2423
+ e.preventDefault();
2424
+ e.stopPropagation();
2425
+ setIsKeyboardOpen(false);
2426
+ setIsHovered(false);
2427
+ (_b = (_a = outerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(':scope > [role="button"]')) === null || _b === void 0 ? void 0 : _b.focus();
2428
+ }
2429
+ else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
2430
+ e.preventDefault();
2431
+ e.stopPropagation();
2432
+ var items = getEnabledItems(e.currentTarget);
2433
+ var index = items.findIndex(function (item) {
2434
+ return item === document.activeElement ||
2435
+ item.contains(document.activeElement);
2436
+ });
2437
+ (_c = items[nextIndex(index, e.key === 'ArrowDown' ? 1 : -1, items.length)]) === null || _c === void 0 ? void 0 : _c.focus();
2438
+ }
2439
+ };
2440
+ var handleFocus = function (e) {
2441
+ try {
2442
+ if (e.currentTarget.matches(':focus-visible'))
2443
+ setIsKeyFocused(true);
2444
+ }
2445
+ catch (_a) {
2446
+ // :focus-visible is not supported here, so there is no keyboard highlight
2447
+ }
2448
+ consumerOnFocus === null || consumerOnFocus === void 0 ? void 0 : consumerOnFocus(e);
2449
+ };
2450
+ var handleBlur = function (e) {
2451
+ setIsKeyFocused(false);
2452
+ consumerOnBlur === null || consumerOnBlur === void 0 ? void 0 : consumerOnBlur(e);
2453
+ };
2454
+ var keyFocusClass = isKeyFocused
2455
+ ? ' !bg-bia-blue-pastel outline outline-[3px] -outline-offset-[3px] outline-bia-blue-light-50'
2456
+ : '';
2457
+ return (React.createElement("div", { ref: outerRef, className: "group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[6px] last:rounded-b-radius-sm last:pb-[6px]", onMouseEnter: function () { return !disabled && setIsHovered(true); }, onMouseLeave: function () { return !disabled && setIsHovered(false); }, onBlur: function (e) {
2458
+ // Focus left the whole item, so close a sub-menu opened by keyboard
2459
+ if (!e.currentTarget.contains(e.relatedTarget))
2460
+ setIsKeyboardOpen(false);
2461
+ } },
2462
+ React.createElement("div", __assign({ className: "relative flex items-center bg-bia-white py-[5px] ".concat(itemClass, " ").concat(disabled ? 'cursor-not-allowed' : 'hover:bg-bia-blue-pastel').concat(keyFocusClass), role: "button", "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, onClick: function (e) {
2215
2463
  if (disabled)
2216
2464
  return;
2217
2465
  inheritedOnClick();
2218
2466
  onClick(e);
2219
- }, onKeyDown: function () { }, style: { zIndex: currentZIndex + 15 } }, props),
2467
+ }, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, style: { zIndex: currentZIndex + 15 } }, props),
2220
2468
  isWithChecked && (React.createElement("div", { className: "mr-[5px] aspect-square w-[14px]" }, isChecked && React.createElement(TbCheck, { className: "text-primary-black", size: 14 }))),
2221
2469
  React.createElement("span", { className: "whitespace-nowrap font-arial text-[11px] ".concat(disabled ? 'text-bia-coolgrey-light-50' : 'text-bia-black') }, label),
2222
2470
  React.createElement("div", { className: "ml-auto flex items-center" },
2223
2471
  children && (React.createElement(TbChevronRight, { className: "ml-[10px] text-bia-coolgrey" })),
2224
2472
  children === undefined && caption && (React.createElement("span", { className: "ml-[30px] whitespace-nowrap text-[11px] ".concat(disabled ? 'text-bia-coolgrey-light-50' : 'text-bia-coolgrey') }, caption)))),
2225
- children && !disabled && (React.createElement(MenuContainerNoAnchor, { open: isHovered, onClose: onClose, className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), ref: MenuContRef, zIndex: currentZIndex + 10, onClickItem: function () { return inheritedOnClick(); } }, children))));
2473
+ children && !disabled && (React.createElement(MenuContainerNoAnchor, { open: isHovered || isKeyboardOpen, onKeyDown: handleSubMenuKeyDown, onClose: function () {
2474
+ setIsKeyboardOpen(false);
2475
+ onClose();
2476
+ }, className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), ref: MenuContRef, zIndex: currentZIndex + 10, onClickItem: function () { return inheritedOnClick(); } }, children))));
2226
2477
  }
2227
2478
 
2228
2479
  var TooltipItem = function (_a) {
@@ -2316,14 +2567,8 @@ function FormLabel(_a) {
2316
2567
 
2317
2568
  function PasswordIcon(_a) {
2318
2569
  var isShow = _a.isShow, showHandler = _a.showHandler, iconSize = _a.iconSize, disabled = _a.disabled;
2319
- var iconColor = disabled ? '#8c8ca6' : '#5E5EEA';
2320
- if (isShow) {
2321
- return (React.createElement(TbEye, { onClick: function () { return showHandler(false); }, style: {
2322
- fontSize: iconSize,
2323
- color: iconColor,
2324
- } }));
2325
- }
2326
- return (React.createElement(TbEyeOff, { onClick: function () { return showHandler(true); }, style: { fontSize: iconSize, color: iconColor } }));
2570
+ var iconColor = disabled ? 'text-bia-coolgrey' : 'text-bia-blue';
2571
+ return (React.createElement("button", { type: "button", "aria-label": isShow ? 'Hide password' : 'Show password', disabled: disabled, onClick: function () { return showHandler(!isShow); }, className: "flex items-center rounded focus-visible:outline focus-visible:outline-[3px] focus-visible:outline-offset-0 focus-visible:outline-bia-blue-light-50 ".concat(iconColor) }, isShow ? (React.createElement(TbEye, { size: iconSize, "aria-hidden": "true" })) : (React.createElement(TbEyeOff, { size: iconSize, "aria-hidden": "true" }))));
2327
2572
  }
2328
2573
 
2329
2574
  function ValidationIcon(_a) {
@@ -2598,16 +2843,27 @@ var sizeConfig$8 = {
2598
2843
 
2599
2844
  /* eslint-disable @typescript-eslint/no-explicit-any */
2600
2845
  function CustomDropdownItem(_a) {
2601
- var _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.isSelected, isSelected = _e === void 0 ? false : _e, _f = _a.options, options = _f === void 0 ? [] : _f, _g = _a.children, children = _g === void 0 ? undefined : _g;
2602
- var _h = React.useState(false), isHovered = _h[0], setisHovered = _h[1];
2603
- var _j = React.useState(false), isHoveredSubMenu = _j[0], setIsHoveredSubMenu = _j[1];
2846
+ var _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.isSelected, isSelected = _e === void 0 ? false : _e, _f = _a.isHighlighted, isHighlighted = _f === void 0 ? false : _f, _g = _a.id, id = _g === void 0 ? undefined : _g, _h = _a.options, options = _h === void 0 ? [] : _h, _j = _a.children, children = _j === void 0 ? undefined : _j;
2847
+ var _k = React.useState(false), isHovered = _k[0], setisHovered = _k[1];
2848
+ var _l = React.useState(false), isHoveredSubMenu = _l[0], setIsHoveredSubMenu = _l[1];
2604
2849
  var isOpenDropdown = isHovered || isHoveredSubMenu;
2605
2850
  var selectedClass = isSelected ? 'font-semibold' : 'font-normal';
2606
- var _k = sizeConfig$8[size], containerClass = _k.container, item = _k.item;
2851
+ var _m = sizeConfig$8[size], containerClass = _m.container, item = _m.item;
2607
2852
  var itemClass = "".concat(item, " ").concat(selectedClass, " ").concat(className);
2608
2853
  var isExistSubDropdown = options.length !== 0;
2609
- return (React.createElement("div", { className: "relative w-full focus-visible:outline-bia-blue-light-50 ".concat(containerClass), tabIndex: 0, role: "button", onClick: function (e) { return onClick(e); }, onMouseEnter: function () { return setisHovered(true); }, onMouseLeave: function () { return setisHovered(false); }, onKeyDown: function () { } },
2610
- React.createElement("div", { className: "flex select-none flex-col hover:bg-bia-blue-light-90 active:bg-bia-blue-light-80 ".concat(itemClass) },
2854
+ var highlightOuterClass = isHighlighted
2855
+ ? ' outline outline-[3px] -outline-offset-[3px] outline-bia-blue-light-50'
2856
+ : '';
2857
+ var highlightInnerClass = isHighlighted ? ' bg-bia-blue-light-90' : '';
2858
+ return (React.createElement("div", { id: id, className: "relative w-full focus-visible:outline-bia-blue-light-50 ".concat(containerClass).concat(highlightOuterClass), tabIndex: 0, role: "button", onClick: function (e) { return onClick(e); }, onMouseEnter: function () { return setisHovered(true); }, onMouseLeave: function () { return setisHovered(false); }, onKeyDown: function (e) {
2859
+ if (e.target !== e.currentTarget)
2860
+ return;
2861
+ if (e.key === 'Enter' || e.key === ' ') {
2862
+ e.preventDefault();
2863
+ e.currentTarget.click();
2864
+ }
2865
+ } },
2866
+ React.createElement("div", { className: "flex select-none flex-col hover:bg-bia-blue-light-90 active:bg-bia-blue-light-80 ".concat(itemClass).concat(highlightInnerClass) },
2611
2867
  children,
2612
2868
  isExistSubDropdown && (React.createElement(TbChevronRight, { className: "float-right text-bia-grey" }))),
2613
2869
  isOpenDropdown && options && isExistSubDropdown && (React.createElement("div", { className: "absolute right-0 top-0 z-50 w-full translate-x-full rounded-md border border-bia-grey-dark-10 bg-primary-white shadow-lg", onMouseEnter: function () { return setIsHoveredSubMenu(true); }, onMouseLeave: function () { return setIsHoveredSubMenu(false); } }, options.map(function (option) {
@@ -2617,16 +2873,27 @@ function CustomDropdownItem(_a) {
2617
2873
 
2618
2874
  /* eslint-disable @typescript-eslint/no-explicit-any */
2619
2875
  function DefaultDropdownItem(_a) {
2620
- var _b = _a.className, className = _b === void 0 ? '' : _b, label = _a.label, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.isSelected, isSelected = _e === void 0 ? false : _e, _f = _a.options, options = _f === void 0 ? [] : _f, _g = _a.caption, caption = _g === void 0 ? '' : _g;
2621
- var _h = React.useState(false), isHovered = _h[0], setisHovered = _h[1];
2622
- var _j = React.useState(false), isHoveredSubMenu = _j[0], setIsHoveredSubMenu = _j[1];
2876
+ var _b = _a.className, className = _b === void 0 ? '' : _b, label = _a.label, _c = _a.onClick, onClick = _c === void 0 ? function () { } : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.isSelected, isSelected = _e === void 0 ? false : _e, _f = _a.isHighlighted, isHighlighted = _f === void 0 ? false : _f, _g = _a.id, id = _g === void 0 ? undefined : _g, _h = _a.options, options = _h === void 0 ? [] : _h, _j = _a.caption, caption = _j === void 0 ? '' : _j;
2877
+ var _k = React.useState(false), isHovered = _k[0], setisHovered = _k[1];
2878
+ var _l = React.useState(false), isHoveredSubMenu = _l[0], setIsHoveredSubMenu = _l[1];
2623
2879
  var isOpenDropdown = isHovered || isHoveredSubMenu;
2624
2880
  var selectedClass = isSelected ? 'font-semibold' : 'font-normal';
2625
- var _k = sizeConfig$8[size], containerClass = _k.container, item = _k.item;
2881
+ var _m = sizeConfig$8[size], containerClass = _m.container, item = _m.item;
2626
2882
  var itemClass = "".concat(item, " ").concat(selectedClass, " ").concat(className);
2627
2883
  var isExistSubDropdown = options.length !== 0;
2628
- return (React.createElement("div", { className: "relative w-full focus-visible:outline-bia-blue-light-50 ".concat(containerClass), tabIndex: 0, role: "button", onClick: function (e) { return onClick(e); }, onMouseEnter: function () { return setisHovered(true); }, onMouseLeave: function () { return setisHovered(false); }, onKeyDown: function () { } },
2629
- React.createElement("div", { className: "flex select-none flex-col hover:bg-bia-blue-light-90 active:bg-bia-blue-light-80 ".concat(itemClass) },
2884
+ var highlightOuterClass = isHighlighted
2885
+ ? ' outline outline-[3px] -outline-offset-[3px] outline-bia-blue-light-50'
2886
+ : '';
2887
+ var highlightInnerClass = isHighlighted ? ' bg-bia-blue-light-90' : '';
2888
+ return (React.createElement("div", { id: id, className: "relative w-full focus-visible:outline-bia-blue-light-50 ".concat(containerClass).concat(highlightOuterClass), tabIndex: 0, role: "button", onClick: function (e) { return onClick(e); }, onMouseEnter: function () { return setisHovered(true); }, onMouseLeave: function () { return setisHovered(false); }, onKeyDown: function (e) {
2889
+ if (e.target !== e.currentTarget)
2890
+ return;
2891
+ if (e.key === 'Enter' || e.key === ' ') {
2892
+ e.preventDefault();
2893
+ e.currentTarget.click();
2894
+ }
2895
+ } },
2896
+ React.createElement("div", { className: "flex select-none flex-col hover:bg-bia-blue-light-90 active:bg-bia-blue-light-80 ".concat(itemClass).concat(highlightInnerClass) },
2630
2897
  React.createElement("span", null,
2631
2898
  label,
2632
2899
  isExistSubDropdown && (React.createElement(TbChevronRight, { className: "float-right text-bia-grey" }))),
@@ -2677,6 +2944,7 @@ function DropdownContainer(propsComp) {
2677
2944
  if (open)
2678
2945
  recalcPosition();
2679
2946
  }, [open, recalcPosition]);
2947
+ useMenuKeyboard({ open: open, onClose: onClose, listRef: dropdownRef, anchorRef: anchorRef });
2680
2948
  var newStyle = React.useMemo(function () {
2681
2949
  var _a, _b, _c;
2682
2950
  if (!(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current)) {
@@ -2725,17 +2993,97 @@ var getItemLabel = function (value) {
2725
2993
  };
2726
2994
 
2727
2995
  var sizeUnion$3 = ['md', 'sm'];
2996
+ var getOptionKey$1 = function (option) {
2997
+ return isObjectWithLabel(option) && option.id != null
2998
+ ? String(option.id)
2999
+ : getItemLabel(option);
3000
+ };
2728
3001
  function SelectInput(_a) {
2729
3002
  var _b;
2730
- var _c = _a.descText, descText = _c === void 0 ? undefined : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.id, id = _f === void 0 ? undefined : _f, _g = _a.isValid, isValid = _g === void 0 ? null : _g, _h = _a.label, label = _h === void 0 ? undefined : _h, _j = _a.options, options = _j === void 0 ? [] : _j, _k = _a.readOnly, readOnly = _k === void 0 ? false : _k, _l = _a.required, required = _l === void 0 ? false : _l, _m = _a.selected, selected = _m === void 0 ? undefined : _m, _o = _a.setSelected, setSelected = _o === void 0 ? function () { } : _o, _p = _a.onClickDropdown, onClickDropdown = _p === void 0 ? function () { } : _p, _q = _a.children, children = _q === void 0 ? undefined : _q, _r = _a.dropContProps, _s = _r === void 0 ? {} : _r, _t = _s.className, dropContClassName = _t === void 0 ? '' : _t, restDropContProps = __rest(_s, ["className"]), props = __rest(_a, ["descText", "disabled", "size", "id", "isValid", "label", "options", "readOnly", "required", "selected", "setSelected", "onClickDropdown", "children", "dropContProps"]);
2731
- var _u = React.useState(false), isOpen = _u[0], setIsOpen = _u[1];
3003
+ var _c = _a.descText, descText = _c === void 0 ? undefined : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.id, id = _f === void 0 ? undefined : _f, _g = _a.isValid, isValid = _g === void 0 ? null : _g, _h = _a.label, label = _h === void 0 ? undefined : _h, _j = _a.options, options = _j === void 0 ? [] : _j, _k = _a.readOnly, readOnly = _k === void 0 ? false : _k, _l = _a.required, required = _l === void 0 ? false : _l, _m = _a.selected, selected = _m === void 0 ? undefined : _m, _o = _a.setSelected, setSelected = _o === void 0 ? function () { } : _o, _p = _a.onClickDropdown, onClickDropdown = _p === void 0 ? function () { } : _p, _q = _a.children, children = _q === void 0 ? undefined : _q, _r = _a.dropContProps, _s = _r === void 0 ? {} : _r, _t = _s.className, dropContClassName = _t === void 0 ? '' : _t, restDropContProps = __rest(_s, ["className"]), _u = _a.onKeyDown, consumerOnKeyDown = _u === void 0 ? undefined : _u, props = __rest(_a, ["descText", "disabled", "size", "id", "isValid", "label", "options", "readOnly", "required", "selected", "setSelected", "onClickDropdown", "children", "dropContProps", "onKeyDown"]);
3004
+ var _v = React.useState(false), isOpen = _v[0], setIsOpen = _v[1];
3005
+ // Option picked by arrow keys (-1 = none)
3006
+ var _w = React.useState(-1), highlightedIndex = _w[0], setHighlightedIndex = _w[1];
3007
+ var baseId = React.useId();
2732
3008
  var validatedSize = validUnion(size, sizeUnion$3);
2733
- var _v = sizeConfig$9[validatedSize], searchSize = _v.searchSize, iconSize = _v.iconSize;
3009
+ var _x = sizeConfig$9[validatedSize], searchSize = _x.searchSize, iconSize = _x.iconSize;
2734
3010
  var inputRef = React.useRef(null);
2735
3011
  var selectedLabel = selected !== undefined && isObjectWithLabel(selected)
2736
3012
  ? ((_b = selected.label) !== null && _b !== void 0 ? _b : '')
2737
3013
  : selected;
2738
3014
  var optionsRef = React.useRef(null);
3015
+ React.useEffect(function () {
3016
+ if (!isOpen)
3017
+ setHighlightedIndex(-1);
3018
+ }, [isOpen]);
3019
+ // Enabled top-level children, in order (the arrow keys skip disabled ones)
3020
+ var enabledChildren = children === undefined
3021
+ ? []
3022
+ : React.Children.toArray(children).filter(function (child) {
3023
+ return React.isValidElement(child) &&
3024
+ !child.props.disabled;
3025
+ });
3026
+ var optionCount = children === undefined ? options.length : enabledChildren.length;
3027
+ var activeIndex = isOpen && highlightedIndex >= 0 && highlightedIndex < optionCount
3028
+ ? highlightedIndex
3029
+ : -1;
3030
+ var activeId = activeIndex >= 0 ? getOptionId(baseId, activeIndex) : undefined;
3031
+ React.useEffect(function () {
3032
+ if (activeId)
3033
+ scrollOptionIntoView(activeId);
3034
+ }, [activeId]);
3035
+ var getSelectedIndex = function () {
3036
+ if (children === undefined) {
3037
+ return options.findIndex(function (option) { return JSON.stringify(option) === JSON.stringify(selected); });
3038
+ }
3039
+ return enabledChildren.findIndex(function (child) {
3040
+ var childValue = child
3041
+ .props.value;
3042
+ return (isObjectWithLabel(selected) &&
3043
+ isObjectWithLabel(childValue) &&
3044
+ selected.id === childValue.id);
3045
+ });
3046
+ };
3047
+ // Opens the list and highlights the selected option, or the first / last one
3048
+ var openByKeyboard = function (delta) {
3049
+ setIsOpen(true);
3050
+ var selectedIndex = getSelectedIndex();
3051
+ if (delta < 0)
3052
+ setHighlightedIndex(optionCount - 1);
3053
+ else
3054
+ setHighlightedIndex(optionCount > 0 ? Math.max(selectedIndex, 0) : -1);
3055
+ };
3056
+ var handleKeyDown = function (e) {
3057
+ var _a;
3058
+ if (!disabled) {
3059
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
3060
+ e.preventDefault();
3061
+ var delta = e.key === 'ArrowDown' ? 1 : -1;
3062
+ if (!isOpen)
3063
+ openByKeyboard(delta);
3064
+ else
3065
+ setHighlightedIndex(nextIndex(activeIndex, delta, optionCount));
3066
+ }
3067
+ else if (e.key === 'Enter' || e.key === ' ') {
3068
+ if (!isOpen) {
3069
+ e.preventDefault();
3070
+ openByKeyboard(1);
3071
+ }
3072
+ else if (e.key === 'Enter' && activeId) {
3073
+ e.preventDefault();
3074
+ (_a = document.getElementById(activeId)) === null || _a === void 0 ? void 0 : _a.click();
3075
+ }
3076
+ }
3077
+ else if (e.key === 'Escape' && isOpen) {
3078
+ e.preventDefault();
3079
+ setIsOpen(false);
3080
+ }
3081
+ else if (e.key === 'Tab' && isOpen) {
3082
+ setIsOpen(false);
3083
+ }
3084
+ }
3085
+ consumerOnKeyDown === null || consumerOnKeyDown === void 0 ? void 0 : consumerOnKeyDown(e);
3086
+ };
2739
3087
  var descColor = 'text-primary-cool';
2740
3088
  var isExistValidation = isValid !== null && isValid !== undefined;
2741
3089
  if (!disabled && isExistValidation && isValid)
@@ -2743,46 +3091,55 @@ function SelectInput(_a) {
2743
3091
  if (!disabled && isExistValidation && !isValid)
2744
3092
  descColor = 'text-bia-red';
2745
3093
  var disabledClass = disabled ? 'cursor-not-allowed' : '';
3094
+ var enabledPosition = 0;
2746
3095
  return (React.createElement("div", { className: "bianic-fgc-container bianic-text-input-container field-group flex w-full flex-col gap-y-2" },
2747
3096
  label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
2748
3097
  React.createElement("div", { className: "group relative w-full ".concat(disabledClass) },
2749
- React.createElement("input", __assign({ className: "bianic-fgc-target field peer w-full cursor-pointer rounded border border-bia-grey-dark-10 bg-primary-white pe-8 focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:cursor-not-allowed disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(searchSize), onClick: function () { return setIsOpen(!isOpen); }, value: selectedLabel, readOnly: true, id: id, disabled: disabled, ref: inputRef }, props)),
3098
+ React.createElement("input", __assign({ className: "bianic-fgc-target field peer w-full cursor-pointer rounded border border-bia-grey-dark-10 bg-primary-white pe-8 focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:cursor-not-allowed disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(searchSize), onClick: function () { return setIsOpen(!isOpen); }, value: selectedLabel, readOnly: true, id: id, disabled: disabled, ref: inputRef, onKeyDown: handleKeyDown, "aria-activedescendant": activeId }, props)),
2750
3099
  React.createElement("div", { className: "pointer-events-none absolute inset-y-0 flex items-center pl-3 text-bia-coolgrey peer-disabled:text-bia-coolgrey-light-50 ".concat(iconSize) }, isOpen ? React.createElement(TbChevronUp, null) : React.createElement(TbChevronDown, null)),
2751
3100
  children === undefined && isOpen && (
2752
3101
  // Consumer-provided click-catcher; each rendered option below is its own interactive control
2753
3102
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
2754
- React.createElement("div", { className: "absolute z-10 w-full rounded-b-md border border-bia-grey-dark-10 bg-primary-white shadow-lg", ref: optionsRef, onClick: onClickDropdown }, options.map(function (option) {
3103
+ React.createElement("div", { className: "absolute z-10 w-full rounded-b-md border border-bia-grey-dark-10 bg-primary-white shadow-lg", ref: optionsRef, onClick: onClickDropdown }, options.map(function (option, index) {
2755
3104
  var isSelected = JSON.stringify(option) === JSON.stringify(selected);
2756
3105
  var optionCaption = isObjectWithLabel(option)
2757
3106
  ? option.caption
2758
3107
  : '';
2759
- return isObjectWithLabel(option) && option.custom ? (React.createElement(CustomDropdownItem, { caption: optionCaption, size: validatedSize, isSelected: isSelected, onClick: function () {
3108
+ return isObjectWithLabel(option) && option.custom ? (React.createElement(CustomDropdownItem, { key: getOptionKey$1(option), isHighlighted: index === activeIndex, id: index === activeIndex ? activeId : undefined, caption: optionCaption, size: validatedSize, isSelected: isSelected, onClick: function () {
2760
3109
  setSelected === null || setSelected === void 0 ? void 0 : setSelected(option);
2761
3110
  setIsOpen(false);
2762
- } }, option.custom)) : (React.createElement(DefaultDropdownItem, { label: getItemLabel(option), caption: optionCaption, size: validatedSize, isSelected: isSelected, onClick: function () {
3111
+ } }, option.custom)) : (React.createElement(DefaultDropdownItem, { key: getOptionKey$1(option), isHighlighted: index === activeIndex, id: index === activeIndex ? activeId : undefined, label: getItemLabel(option), caption: optionCaption, size: validatedSize, isSelected: isSelected, onClick: function () {
2763
3112
  setSelected === null || setSelected === void 0 ? void 0 : setSelected(option);
2764
3113
  setIsOpen(false);
2765
3114
  } }));
2766
3115
  }))),
2767
3116
  children && isOpen && (React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, className: "bianic-livesearch-dropdown absolute z-10 mt-1 w-full overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none ".concat(dropContClassName), anchorRef: inputRef, matchAnchorWidth: "min" }, restDropContProps), React.Children.map(children, function (child) {
2768
3117
  if (React.isValidElement(child)) {
3118
+ var isDisabledChild = child.props
3119
+ .disabled;
3120
+ var position = isDisabledChild ? -1 : enabledPosition;
3121
+ if (!isDisabledChild)
3122
+ enabledPosition += 1;
3123
+ var highlightProps = position >= 0 && position === activeIndex
3124
+ ? {
3125
+ className: cn$1(child.props.className, OPTION_HIGHLIGHT_CLASS),
3126
+ id: activeId,
3127
+ }
3128
+ : {};
2769
3129
  // Consumer-supplied children are expected to carry a `value`
2770
3130
  // prop matching the DropdownItem convention, but arbitrary
2771
3131
  // JSX children have no statically-known prop shape.
2772
3132
  var childValue_1 = child.props
2773
3133
  .value;
2774
- return React.cloneElement(child, {
2775
- isSelected: isObjectWithLabel(selected) &&
3134
+ return React.cloneElement(child, __assign({ isSelected: isObjectWithLabel(selected) &&
2776
3135
  isObjectWithLabel(childValue_1) &&
2777
- selected.id === childValue_1.id,
2778
- onClick: function () {
3136
+ selected.id === childValue_1.id, onClick: function () {
2779
3137
  // Same trust boundary as before: consumer children are
2780
3138
  // expected to always carry a value, matching the exact
2781
3139
  // runtime behavior this already had.
2782
3140
  setSelected === null || setSelected === void 0 ? void 0 : setSelected(childValue_1);
2783
3141
  setIsOpen(false);
2784
- },
2785
- });
3142
+ } }, highlightProps));
2786
3143
  }
2787
3144
  return child;
2788
3145
  })))),
@@ -2835,9 +3192,12 @@ function DropdownContNoAnchorInner(propsComp, ref) {
2835
3192
  var DropdownContNoAnchor = React.forwardRef(DropdownContNoAnchorInner);
2836
3193
 
2837
3194
  function DropdownItem(_a) {
2838
- var _b = _a.children, children = _b === void 0 ? undefined : _b, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.onClickItem, onClickItem = _d === void 0 ? function () { } : _d, _e = _a.onClose, onClose = _e === void 0 ? function () { } : _e, _f = _a.size, size = _f === void 0 ? 'md' : _f, _g = _a.value, value = _g === void 0 ? '' : _g, content = _a.content, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.zIndex, zIndex = _j === void 0 ? 100 : _j, props = __rest(_a, ["children", "className", "onClickItem", "onClose", "size", "value", "content", "disabled", "zIndex"]);
2839
- var _k = React.useState(false), isHovered = _k[0], setIsHovered = _k[1];
2840
- var _l = React.useState(false), isLeft = _l[0], setIsLeft = _l[1];
3195
+ var _b = _a.children, children = _b === void 0 ? undefined : _b, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.onClickItem, onClickItem = _d === void 0 ? function () { } : _d, _e = _a.onClose, onClose = _e === void 0 ? function () { } : _e, _f = _a.size, size = _f === void 0 ? 'md' : _f, _g = _a.value, value = _g === void 0 ? '' : _g, content = _a.content, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.zIndex, zIndex = _j === void 0 ? 100 : _j, _k = _a.onKeyDown, consumerOnKeyDown = _k === void 0 ? undefined : _k, _l = _a.onFocus, consumerOnFocus = _l === void 0 ? undefined : _l, _m = _a.onBlur, consumerOnBlur = _m === void 0 ? undefined : _m, props = __rest(_a, ["children", "className", "onClickItem", "onClose", "size", "value", "content", "disabled", "zIndex", "onKeyDown", "onFocus", "onBlur"]);
3196
+ var _o = React.useState(false), isHovered = _o[0], setIsHovered = _o[1];
3197
+ var _p = React.useState(false), isKeyboardOpen = _p[0], setIsKeyboardOpen = _p[1];
3198
+ var _q = React.useState(false), isKeyFocused = _q[0], setIsKeyFocused = _q[1];
3199
+ var _r = React.useState(false), isLeft = _r[0], setIsLeft = _r[1];
3200
+ var outerRef = React.useRef(null);
2841
3201
  var fontClass = fontConfig[size] || fontConfig.md;
2842
3202
  var itemSizeClass = itemSizeConfig[size] || itemSizeConfig.md;
2843
3203
  var itemClass = "".concat(itemSizeClass, " ").concat(fontClass, " ").concat(className);
@@ -2855,16 +3215,71 @@ function DropdownItem(_a) {
2855
3215
  else
2856
3216
  setIsLeft(false);
2857
3217
  }
2858
- }, [isHovered]);
3218
+ }, [isHovered, isKeyboardOpen]);
2859
3219
  var translateClass = isLeft
2860
3220
  ? 'left-0 -translate-x-full'
2861
3221
  : 'right-0 translate-x-full';
2862
3222
  var currentZIndex = zIndex + 10;
2863
- return (React.createElement("div", { className: "bianic-dropdown-item group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[5px] last:rounded-b-radius-sm last:pb-[5px]", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } },
2864
- React.createElement("button", __assign({ className: "relative flex w-full !min-w-fit items-center justify-start whitespace-nowrap bg-bia-white px-[15px] py-[5px] text-left text-bia-black disabled:cursor-not-allowed disabled:text-bia-coolgrey-light-50 hover:[&:not(:disabled)]:bg-bia-blue-pastel ".concat(itemClass), style: { zIndex: currentZIndex + 15 }, onClick: function (e) { return onClickItem(e, value); }, onKeyDown: function () { }, disabled: disabled, type: "button" }, props),
3223
+ var handleKeyDown = function (e) {
3224
+ if (children && (e.key === 'ArrowRight' || e.key === 'Enter')) {
3225
+ e.preventDefault();
3226
+ setIsKeyboardOpen(true);
3227
+ requestAnimationFrame(function () {
3228
+ var _a;
3229
+ (_a = getEnabledItems(DropdownContRef.current)[0]) === null || _a === void 0 ? void 0 : _a.focus();
3230
+ });
3231
+ }
3232
+ consumerOnKeyDown === null || consumerOnKeyDown === void 0 ? void 0 : consumerOnKeyDown(e);
3233
+ };
3234
+ var handleSubMenuKeyDown = function (e) {
3235
+ var _a, _b, _c;
3236
+ if (e.key === 'ArrowLeft' || e.key === 'Escape') {
3237
+ e.preventDefault();
3238
+ e.stopPropagation();
3239
+ setIsKeyboardOpen(false);
3240
+ setIsHovered(false);
3241
+ (_b = (_a = outerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(':scope > button')) === null || _b === void 0 ? void 0 : _b.focus();
3242
+ }
3243
+ else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
3244
+ e.preventDefault();
3245
+ e.stopPropagation();
3246
+ var items = getEnabledItems(e.currentTarget);
3247
+ var index = items.findIndex(function (item) {
3248
+ return item === document.activeElement ||
3249
+ item.contains(document.activeElement);
3250
+ });
3251
+ (_c = items[nextIndex(index, e.key === 'ArrowDown' ? 1 : -1, items.length)]) === null || _c === void 0 ? void 0 : _c.focus();
3252
+ }
3253
+ };
3254
+ var handleFocus = function (e) {
3255
+ try {
3256
+ if (e.currentTarget.matches(':focus-visible'))
3257
+ setIsKeyFocused(true);
3258
+ }
3259
+ catch (_a) {
3260
+ // :focus-visible is not supported here, so there is no keyboard highlight
3261
+ }
3262
+ consumerOnFocus === null || consumerOnFocus === void 0 ? void 0 : consumerOnFocus(e);
3263
+ };
3264
+ var handleBlur = function (e) {
3265
+ setIsKeyFocused(false);
3266
+ consumerOnBlur === null || consumerOnBlur === void 0 ? void 0 : consumerOnBlur(e);
3267
+ };
3268
+ var keyFocusClass = isKeyFocused
3269
+ ? ' !bg-bia-blue-pastel outline outline-[3px] -outline-offset-[3px] outline-bia-blue-light-50'
3270
+ : '';
3271
+ return (React.createElement("div", { ref: outerRef, className: "bianic-dropdown-item group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[5px] last:rounded-b-radius-sm last:pb-[5px]", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onBlur: function (e) {
3272
+ // Focus left the whole item, so close a sub-menu opened by keyboard
3273
+ if (!e.currentTarget.contains(e.relatedTarget))
3274
+ setIsKeyboardOpen(false);
3275
+ } },
3276
+ React.createElement("button", __assign({ className: "relative flex w-full !min-w-fit items-center justify-start whitespace-nowrap bg-bia-white px-[15px] py-[5px] text-left text-bia-black disabled:cursor-not-allowed disabled:text-bia-coolgrey-light-50 hover:[&:not(:disabled)]:bg-bia-blue-pastel ".concat(itemClass).concat(keyFocusClass), style: { zIndex: currentZIndex + 15 }, onClick: function (e) { return onClickItem(e, value); }, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, disabled: disabled, type: "button" }, props),
2865
3277
  content,
2866
3278
  React.createElement("div", { className: "ml-auto flex items-center" }, children && (React.createElement(TbChevronRight, { className: "ml-[10px] text-bia-coolgrey", size: chevronSize })))),
2867
- children && (React.createElement(DropdownContNoAnchor, { className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), onClose: onClose, open: isHovered, onClickItem: function (e, itemValue) { return onClickItem(e, itemValue); }, size: size, ref: DropdownContRef, zIndex: currentZIndex + 10 }, children))));
3279
+ children && (React.createElement(DropdownContNoAnchor, { className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), onClose: function () {
3280
+ setIsKeyboardOpen(false);
3281
+ onClose();
3282
+ }, onKeyDown: handleSubMenuKeyDown, open: isHovered || isKeyboardOpen, onClickItem: function (e, itemValue) { return onClickItem(e, itemValue); }, size: size, ref: DropdownContRef, zIndex: currentZIndex + 10 }, children))));
2868
3283
  }
2869
3284
 
2870
3285
  var matchSearchTerm = function (content, term, variant) {
@@ -2888,8 +3303,11 @@ var filterOptions = function (options, searchTerm) {
2888
3303
  });
2889
3304
  };
2890
3305
 
2891
- var processDropdownChildren$1 = function (nodes, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, searchVariant) {
3306
+ var processDropdownChildren$1 = function (nodes, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, searchVariant, highlight) {
2892
3307
  if (searchVariant === void 0) { searchVariant = 'include'; }
3308
+ if (highlight === void 0) { highlight = undefined; }
3309
+ // Counts the enabled top-level items, so arrow keys can skip disabled ones
3310
+ var enabledCount = 0;
2893
3311
  return React.Children.map(nodes, function (child) {
2894
3312
  if (!React.isValidElement(child) || child.type !== DropdownItem) {
2895
3313
  return child;
@@ -2910,12 +3328,20 @@ var processDropdownChildren$1 = function (nodes, currentSearchTerm, includeAllIf
2910
3328
  var clonedChildren = itemProps.children
2911
3329
  ? processDropdownChildren$1(itemProps.children, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, searchVariant)
2912
3330
  : null;
3331
+ var position = isDisabled ? -1 : enabledCount;
3332
+ if (!isDisabled)
3333
+ enabledCount += 1;
3334
+ var highlightProps = highlight && position >= 0 && position === highlight.index
3335
+ ? {
3336
+ className: cn$1(itemProps.className, OPTION_HIGHLIGHT_CLASS),
3337
+ id: getOptionId(highlight.baseId, position),
3338
+ }
3339
+ : {};
2913
3340
  // Clone and Inject Click Handler
2914
3341
  // DropdownItem renders a <button>, but handleDropdownItemClick's event
2915
3342
  // type is HTMLDivElement to match its other callers (the event's
2916
3343
  // specific target type is never used here, only forwarded).
2917
- return React.cloneElement(child, {
2918
- onClick: function (e) {
3344
+ return React.cloneElement(child, __assign({ onClick: function (e) {
2919
3345
  var divEvent = e;
2920
3346
  if (!isDisabled) {
2921
3347
  if (itemValue === undefined &&
@@ -2931,31 +3357,41 @@ var processDropdownChildren$1 = function (nodes, currentSearchTerm, includeAllIf
2931
3357
  if (itemProps.onClickItem) {
2932
3358
  itemProps.onClickItem(e, itemValue !== undefined ? itemValue : itemContent);
2933
3359
  }
2934
- },
2935
- children: clonedChildren,
2936
- });
3360
+ }, children: clonedChildren }, highlightProps));
2937
3361
  });
2938
3362
  };
2939
- var processRenderedChildren$1 = function (children, searchTerm, searchVariant, handleDropdownItemClick) {
3363
+ var processRenderedChildren$1 = function (children, searchTerm, searchVariant, handleDropdownItemClick, highlight) {
3364
+ if (highlight === void 0) { highlight = undefined; }
2940
3365
  var renderedChildren = null;
2941
3366
  var hasFilteredResults = false;
2942
3367
  if (searchTerm) {
2943
- renderedChildren = processDropdownChildren$1(children, searchTerm, false, handleDropdownItemClick, searchVariant);
3368
+ renderedChildren = processDropdownChildren$1(children, searchTerm, false, handleDropdownItemClick, searchVariant, highlight);
2944
3369
  hasFilteredResults =
2945
3370
  React.Children.toArray(renderedChildren).filter(Boolean).length > 0;
2946
3371
  }
2947
3372
  else {
2948
- renderedChildren = processDropdownChildren$1(children, '', true, handleDropdownItemClick, searchVariant);
3373
+ renderedChildren = processDropdownChildren$1(children, '', true, handleDropdownItemClick, searchVariant, highlight);
2949
3374
  hasFilteredResults =
2950
3375
  React.Children.toArray(renderedChildren).filter(Boolean).length > 0;
2951
3376
  }
2952
- return { renderedChildren: renderedChildren, hasFilteredResults: hasFilteredResults };
3377
+ var enabledCount = React.Children.toArray(renderedChildren).filter(function (child) {
3378
+ return React.isValidElement(child) &&
3379
+ child.type === DropdownItem &&
3380
+ !child.props.disabled;
3381
+ }).length;
3382
+ return { renderedChildren: renderedChildren, hasFilteredResults: hasFilteredResults, enabledCount: enabledCount };
2953
3383
  };
2954
3384
 
2955
3385
  var useLiveSearch$1 = function (_a) {
2956
3386
  var value = _a.value, setValue = _a.setValue, onChangeText = _a.onChangeText, dropContOnClickItem = _a.dropContOnClickItem;
2957
3387
  var _b = React.useState(false), isOpen = _b[0], setIsOpen = _b[1];
2958
3388
  var _c = React.useState(getItemLabel(value)), searchTerm = _c[0], setSearchTerm = _c[1];
3389
+ // Option picked by arrow keys (-1 = none)
3390
+ var _d = React.useState(-1), highlightedIndex = _d[0], setHighlightedIndex = _d[1];
3391
+ React.useEffect(function () {
3392
+ if (!isOpen)
3393
+ setHighlightedIndex(-1);
3394
+ }, [isOpen]);
2959
3395
  React.useEffect(function () {
2960
3396
  if (!isOpen && searchTerm !== getItemLabel(value)) {
2961
3397
  setSearchTerm(getItemLabel(value));
@@ -2967,6 +3403,7 @@ var useLiveSearch$1 = function (_a) {
2967
3403
  var handleInputChange = function (e) {
2968
3404
  var newSearchTerm = e.target.value;
2969
3405
  setSearchTerm(newSearchTerm);
3406
+ setHighlightedIndex(-1);
2970
3407
  setIsOpen(true);
2971
3408
  onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(e);
2972
3409
  };
@@ -2996,6 +3433,8 @@ var useLiveSearch$1 = function (_a) {
2996
3433
  isOpen: isOpen,
2997
3434
  setIsOpen: setIsOpen,
2998
3435
  searchTerm: searchTerm,
3436
+ highlightedIndex: highlightedIndex,
3437
+ setHighlightedIndex: setHighlightedIndex,
2999
3438
  handleInputChange: handleInputChange,
3000
3439
  handleCancel: handleCancel,
3001
3440
  handleClear: handleClear,
@@ -3003,16 +3442,22 @@ var useLiveSearch$1 = function (_a) {
3003
3442
  };
3004
3443
  };
3005
3444
 
3445
+ var getOptionKey = function (option) {
3446
+ return isObjectWithLabel(option) && option.id != null
3447
+ ? String(option.id)
3448
+ : getItemLabel(option);
3449
+ };
3006
3450
  function LiveSearch(_a) {
3007
3451
  var _b = _a.autoComplete, autoComplete = _b === void 0 ? 'off' : _b, _c = _a.children, children = _c === void 0 ? undefined : _c, _d = _a.descText, descText = _d === void 0 ? undefined : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.dropContProps, dropContProps = _f === void 0 ? undefined : _f, _g = _a.id, id = _g === void 0 ? undefined : _g, _h = _a.label, label = _h === void 0 ? undefined : _h, _j = _a.noResultsContent, noResultsContent = _j === void 0 ? undefined : _j, _k = _a.onChangeText, onChangeText = _k === void 0 ? function () { } : _k, _l = _a.onChangeButton, onChangeButton = _l === void 0 ? undefined : _l, _m = _a.onClickDropdown, onClickDropdown = _m === void 0 ? function () { } : _m, _o = _a.options, options = _o === void 0 ? undefined : _o, _p = _a.placeholder, placeholder = _p === void 0 ? undefined : _p, _q = _a.readOnly, readOnly = _q === void 0 ? false : _q, _r = _a.required, required = _r === void 0 ? false : _r, _s = _a.searchVariant, searchVariant = _s === void 0 ? 'include' : _s, setValue = _a.setValue, _t = _a.size, size = _t === void 0 ? 'md' : _t, _u = _a.isValid, isValid = _u === void 0 ? null : _u, value = _a.value;
3008
3452
  var inputRef = React.useRef(null);
3009
3453
  var wrapperRef = React.useRef(null);
3454
+ var baseId = React.useId();
3010
3455
  var _v = useLiveSearch$1({
3011
3456
  value: value,
3012
3457
  setValue: setValue,
3013
3458
  onChangeText: onChangeText,
3014
3459
  dropContOnClickItem: dropContProps === null || dropContProps === void 0 ? void 0 : dropContProps.onClickItem,
3015
- }), isOpen = _v.isOpen, setIsOpen = _v.setIsOpen, searchTerm = _v.searchTerm, handleInputChange = _v.handleInputChange, handleCancel = _v.handleCancel, handleClear = _v.handleClear, handleDropdownItemClick = _v.handleDropdownItemClick;
3460
+ }), isOpen = _v.isOpen, setIsOpen = _v.setIsOpen, searchTerm = _v.searchTerm, highlightedIndex = _v.highlightedIndex, setHighlightedIndex = _v.setHighlightedIndex, handleInputChange = _v.handleInputChange, handleCancel = _v.handleCancel, handleClear = _v.handleClear, handleDropdownItemClick = _v.handleDropdownItemClick;
3016
3461
  // The plain `options` list has no overlay, so close it when the user clicks away.
3017
3462
  // The `children` list is closed by its own overlay.
3018
3463
  React.useEffect(function () {
@@ -3036,15 +3481,54 @@ function LiveSearch(_a) {
3036
3481
  if (!disabled && isExistValidation && !isValid)
3037
3482
  descColor = 'text-bia-red';
3038
3483
  var filteredOptions = filterOptions(options || [], getItemLabel(value));
3039
- var _y = processRenderedChildren$1(children, searchTerm, searchVariant, handleDropdownItemClick), renderedChildren = _y.renderedChildren, hasFilteredResults = _y.hasFilteredResults;
3484
+ var _y = processRenderedChildren$1(children, searchTerm, searchVariant, handleDropdownItemClick, { index: highlightedIndex, baseId: baseId }), renderedChildren = _y.renderedChildren, hasFilteredResults = _y.hasFilteredResults, enabledCount = _y.enabledCount;
3485
+ // Number of options the arrow keys can move through
3486
+ var optionCount = hasFilteredResults ? enabledCount : 0;
3487
+ if (children === undefined)
3488
+ optionCount = filteredOptions.length;
3489
+ var activeIndex = isOpen && highlightedIndex >= 0 && highlightedIndex < optionCount
3490
+ ? highlightedIndex
3491
+ : -1;
3492
+ var activeId = activeIndex >= 0 ? getOptionId(baseId, activeIndex) : undefined;
3493
+ React.useEffect(function () {
3494
+ if (activeId)
3495
+ scrollOptionIntoView(activeId);
3496
+ }, [activeId]);
3497
+ var handleKeyDown = function (e) {
3498
+ var _a;
3499
+ if (e.key === 'Escape' && isOpen) {
3500
+ e.preventDefault();
3501
+ handleCancel();
3502
+ return;
3503
+ }
3504
+ if (disabled || readOnly)
3505
+ return;
3506
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
3507
+ e.preventDefault();
3508
+ var delta = e.key === 'ArrowDown' ? 1 : -1;
3509
+ if (!isOpen) {
3510
+ setIsOpen(true);
3511
+ setHighlightedIndex(nextIndex(-1, delta, optionCount));
3512
+ }
3513
+ else {
3514
+ setHighlightedIndex(nextIndex(activeIndex, delta, optionCount));
3515
+ }
3516
+ }
3517
+ else if (e.key === 'Enter') {
3518
+ if (activeId) {
3519
+ e.preventDefault();
3520
+ (_a = document.getElementById(activeId)) === null || _a === void 0 ? void 0 : _a.click();
3521
+ }
3522
+ }
3523
+ else if (e.key === 'Tab' && isOpen) {
3524
+ handleCancel();
3525
+ }
3526
+ };
3040
3527
  var disabledClass = disabled ? 'cursor-not-allowed' : '';
3041
3528
  return (React.createElement("div", { className: "bianic-livesearch bianic-fgc-container bianic-text-input-container field-group group/form flex w-full flex-col gap-y-2" },
3042
3529
  label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
3043
3530
  React.createElement("div", { ref: wrapperRef, className: "group relative w-full ".concat(disabledClass) },
3044
- React.createElement("input", { className: "bianic-livesearch-input bianic-fgc-target field peer w-full rounded border border-bia-grey-dark-10 bg-primary-white text-bia-black read-only:pointer-events-none read-only:border-bia-grey-light-50 focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(inputClass), style: { paddingRight: "".concat(10 + Number(iconSize), "px") }, onClick: function () { return setIsOpen(!isOpen); }, value: searchTerm, required: required, disabled: disabled, id: id, placeholder: placeholder, ref: inputRef, onKeyDown: function (e) {
3045
- if (e.key === 'Escape' && isOpen)
3046
- handleCancel();
3047
- }, onChange: function (e) {
3531
+ React.createElement("input", { className: "bianic-livesearch-input bianic-fgc-target field peer w-full rounded border border-bia-grey-dark-10 bg-primary-white text-bia-black read-only:pointer-events-none read-only:border-bia-grey-light-50 focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(inputClass), style: { paddingRight: "".concat(10 + Number(iconSize), "px") }, onClick: function () { return setIsOpen(!isOpen); }, value: searchTerm, required: required, disabled: disabled, id: id, placeholder: placeholder, ref: inputRef, onKeyDown: handleKeyDown, "aria-activedescendant": activeId, onChange: function (e) {
3048
3532
  onChangeText(e);
3049
3533
  handleInputChange(e);
3050
3534
  }, type: "text", readOnly: readOnly, autoComplete: autoComplete }),
@@ -3060,15 +3544,15 @@ function LiveSearch(_a) {
3060
3544
  children === undefined && isOpen && (
3061
3545
  // Consumer-provided click-catcher; each rendered option below is its own interactive control
3062
3546
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
3063
- React.createElement("div", { className: "border-grey-100 absolute z-10 max-h-60 w-full overflow-y-auto rounded-b-md border bg-primary-white shadow-lg", onClick: onClickDropdown }, filteredOptions.map(function (option) {
3547
+ React.createElement("div", { className: "border-grey-100 absolute z-10 max-h-60 w-full overflow-y-auto rounded-b-md border bg-primary-white shadow-lg", onClick: onClickDropdown }, filteredOptions.map(function (option, index) {
3064
3548
  var isSelected = isObjectWithLabel(value) &&
3065
3549
  isObjectWithLabel(option) &&
3066
3550
  value.id &&
3067
3551
  option.id === value.id;
3068
- return isObjectWithLabel(option) && option.custom ? (React.createElement(CustomDropdownItem, { size: size, isSelected: isSelected, className: dropContClassName, onClick: function () {
3552
+ return isObjectWithLabel(option) && option.custom ? (React.createElement(CustomDropdownItem, { key: getOptionKey(option), size: size, isSelected: isSelected, isHighlighted: index === activeIndex, id: index === activeIndex ? activeId : undefined, className: dropContClassName, onClick: function () {
3069
3553
  setValue(option);
3070
3554
  setIsOpen(false);
3071
- } }, option.custom)) : (React.createElement(DefaultDropdownItem, { label: getItemLabel(option), size: size, isSelected: isSelected, className: dropContClassName, onClick: function () {
3555
+ } }, option.custom)) : (React.createElement(DefaultDropdownItem, { key: getOptionKey(option), label: getItemLabel(option), size: size, isSelected: isSelected, isHighlighted: index === activeIndex, id: index === activeIndex ? activeId : undefined, className: dropContClassName, onClick: function () {
3072
3556
  setValue(option);
3073
3557
  setIsOpen(false);
3074
3558
  } }));
@@ -3109,8 +3593,11 @@ var isMatchValue = function (existingValue, optionValue) {
3109
3593
  }
3110
3594
  return existingValue === null || existingValue === void 0 ? void 0 : existingValue.includes(optionValue);
3111
3595
  };
3112
- var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, existingValues, searchVariant) {
3596
+ var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, existingValues, searchVariant, highlight) {
3113
3597
  if (searchVariant === void 0) { searchVariant = 'include'; }
3598
+ if (highlight === void 0) { highlight = undefined; }
3599
+ // Counts the enabled top-level items, so arrow keys can skip disabled ones
3600
+ var enabledCount = 0;
3114
3601
  return React.Children.map(nodes, function (child) {
3115
3602
  if (!React.isValidElement(child) || child.type !== DropdownItem) {
3116
3603
  return child;
@@ -3138,12 +3625,20 @@ var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNo
3138
3625
  var clonedChildren = itemProps.children
3139
3626
  ? processDropdownChildren(itemProps.children, currentSearchTerm, includeAllIfNoSearch, handleDropdownItemClick, existingValues, searchVariant)
3140
3627
  : null;
3628
+ var position = isDisabled ? -1 : enabledCount;
3629
+ if (!isDisabled)
3630
+ enabledCount += 1;
3631
+ var highlightProps = highlight && position >= 0 && position === highlight.index
3632
+ ? {
3633
+ className: cn$1(itemProps.className, OPTION_HIGHLIGHT_CLASS),
3634
+ id: getOptionId(highlight.baseId, position),
3635
+ }
3636
+ : {};
3141
3637
  // Clone and Inject Click Handler
3142
3638
  // DropdownItem renders a <button>, but handleDropdownItemClick's event
3143
3639
  // type is HTMLDivElement to match its other callers (the event's
3144
3640
  // specific target type is never used here, only forwarded).
3145
- return React.cloneElement(child, {
3146
- onClick: function (e) {
3641
+ return React.cloneElement(child, __assign({ onClick: function (e) {
3147
3642
  var divEvent = e;
3148
3643
  if (!isDisabled) {
3149
3644
  if (itemValue === undefined &&
@@ -3159,32 +3654,43 @@ var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNo
3159
3654
  if (itemProps.onClickItem) {
3160
3655
  itemProps.onClickItem(e, itemValue !== undefined ? itemValue : itemContent);
3161
3656
  }
3162
- },
3163
- children: clonedChildren,
3164
- });
3657
+ }, children: clonedChildren }, highlightProps));
3165
3658
  });
3166
3659
  };
3167
- var processRenderedChildren = function (children, searchTerm, searchVariant, handleDropdownItemClick, existingValues) {
3660
+ var processRenderedChildren = function (children, searchTerm, searchVariant, handleDropdownItemClick, existingValues, highlight) {
3661
+ if (highlight === void 0) { highlight = undefined; }
3168
3662
  var renderedChildren = null;
3169
3663
  var hasFilteredResults = false;
3170
3664
  if (searchTerm || (existingValues === null || existingValues === void 0 ? void 0 : existingValues.length) > 0) {
3171
- renderedChildren = processDropdownChildren(children, searchTerm, false, handleDropdownItemClick, existingValues, searchVariant);
3665
+ renderedChildren = processDropdownChildren(children, searchTerm, false, handleDropdownItemClick, existingValues, searchVariant, highlight);
3172
3666
  }
3173
3667
  else {
3174
- renderedChildren = processDropdownChildren(children, '', true, handleDropdownItemClick, [], searchVariant);
3668
+ renderedChildren = processDropdownChildren(children, '', true, handleDropdownItemClick, [], searchVariant, highlight);
3175
3669
  }
3176
3670
  hasFilteredResults =
3177
3671
  React.Children.toArray(renderedChildren).filter(Boolean).length > 0;
3178
- return { renderedChildren: renderedChildren, hasFilteredResults: hasFilteredResults };
3672
+ var enabledCount = React.Children.toArray(renderedChildren).filter(function (child) {
3673
+ return React.isValidElement(child) &&
3674
+ child.type === DropdownItem &&
3675
+ !child.props.disabled;
3676
+ }).length;
3677
+ return { renderedChildren: renderedChildren, hasFilteredResults: hasFilteredResults, enabledCount: enabledCount };
3179
3678
  };
3180
3679
 
3181
3680
  var useLiveSearch = function (_a) {
3182
3681
  var value = _a.value, setValue = _a.setValue, onChangeText = _a.onChangeText, dropContOnClickItem = _a.dropContOnClickItem;
3183
3682
  var _b = React.useState(false), isOpen = _b[0], setIsOpen = _b[1];
3184
3683
  var _c = React.useState(''), searchTerm = _c[0], setSearchTerm = _c[1];
3684
+ // Option picked by arrow keys (-1 = none)
3685
+ var _d = React.useState(-1), highlightedIndex = _d[0], setHighlightedIndex = _d[1];
3686
+ React.useEffect(function () {
3687
+ if (!isOpen)
3688
+ setHighlightedIndex(-1);
3689
+ }, [isOpen]);
3185
3690
  var handleInputChange = function (e) {
3186
3691
  var newSearchTerm = e.target.value;
3187
3692
  setSearchTerm(newSearchTerm);
3693
+ setHighlightedIndex(-1);
3188
3694
  setIsOpen(true);
3189
3695
  onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(e);
3190
3696
  };
@@ -3200,6 +3706,8 @@ var useLiveSearch = function (_a) {
3200
3706
  isOpen: isOpen,
3201
3707
  setIsOpen: setIsOpen,
3202
3708
  searchTerm: searchTerm,
3709
+ highlightedIndex: highlightedIndex,
3710
+ setHighlightedIndex: setHighlightedIndex,
3203
3711
  handleInputChange: handleInputChange,
3204
3712
  handleDropdownItemClick: handleDropdownItemClick,
3205
3713
  };
@@ -3410,14 +3918,7 @@ function TagLabelInputInner(_a, ref) {
3410
3918
  setValue: onChange,
3411
3919
  onChangeText: onChangeText,
3412
3920
  dropContOnClickItem: dropContProps === null || dropContProps === void 0 ? void 0 : dropContProps.onClickItem,
3413
- }), isOpen = _s.isOpen, setIsOpen = _s.setIsOpen, searchTerm = _s.searchTerm, handleInputChange = _s.handleInputChange, handleDropdownItemClick = _s.handleDropdownItemClick;
3414
- var handleKeyDown = function (e) {
3415
- var _a;
3416
- if (e.key === 'Backspace' && searchTerm === '' && value.length > 0) {
3417
- handleRemoveTag(value.length - 1);
3418
- }
3419
- (_a = restInputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restInputProps, e);
3420
- };
3921
+ }), isOpen = _s.isOpen, setIsOpen = _s.setIsOpen, searchTerm = _s.searchTerm, highlightedIndex = _s.highlightedIndex, setHighlightedIndex = _s.setHighlightedIndex, handleInputChange = _s.handleInputChange, handleDropdownItemClick = _s.handleDropdownItemClick;
3421
3922
  var handleContainerClick = function () {
3422
3923
  var _a;
3423
3924
  if (!disabled && !readOnly) {
@@ -3445,7 +3946,50 @@ function TagLabelInputInner(_a, ref) {
3445
3946
  }
3446
3947
  var _t = sizeConfig$6[size], inputClass = _t.inputClass, paddingClass = _t.paddingClass, resizePosition = _t.resizePosition;
3447
3948
  var _u = dropContProps || {}, dropContClassName = _u.className, restDropContProps = __rest(_u, ["className"]);
3448
- var _v = processRenderedChildren(children, searchTerm, 'include', handleDropdownItemClick, value), renderedChildren = _v.renderedChildren, hasFilteredResults = _v.hasFilteredResults;
3949
+ var _v = processRenderedChildren(children, searchTerm, 'include', handleDropdownItemClick, value, { index: highlightedIndex, baseId: inputId }), renderedChildren = _v.renderedChildren, hasFilteredResults = _v.hasFilteredResults, enabledCount = _v.enabledCount;
3950
+ // Options the arrow keys can move through (chosen and disabled ones are out)
3951
+ var optionCount = hasFilteredResults ? enabledCount : 0;
3952
+ var activeIndex = isOpen && highlightedIndex >= 0 && highlightedIndex < optionCount
3953
+ ? highlightedIndex
3954
+ : -1;
3955
+ var activeId = activeIndex >= 0 ? getOptionId(inputId, activeIndex) : undefined;
3956
+ React.useEffect(function () {
3957
+ if (activeId)
3958
+ scrollOptionIntoView(activeId);
3959
+ }, [activeId]);
3960
+ var handleKeyDown = function (e) {
3961
+ var _a, _b;
3962
+ if (e.key === 'Backspace' && searchTerm === '' && value.length > 0) {
3963
+ handleRemoveTag(value.length - 1);
3964
+ }
3965
+ if (!disabled && !readOnly) {
3966
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
3967
+ e.preventDefault();
3968
+ var delta = e.key === 'ArrowDown' ? 1 : -1;
3969
+ if (!isOpen) {
3970
+ setIsOpen(true);
3971
+ setHighlightedIndex(nextIndex(-1, delta, optionCount));
3972
+ }
3973
+ else {
3974
+ setHighlightedIndex(nextIndex(activeIndex, delta, optionCount));
3975
+ }
3976
+ }
3977
+ else if (e.key === 'Enter') {
3978
+ if (activeId) {
3979
+ e.preventDefault();
3980
+ (_a = document.getElementById(activeId)) === null || _a === void 0 ? void 0 : _a.click();
3981
+ }
3982
+ }
3983
+ else if (e.key === 'Escape' && isOpen) {
3984
+ e.preventDefault();
3985
+ setIsOpen(false);
3986
+ }
3987
+ else if (e.key === 'Tab' && isOpen) {
3988
+ setIsOpen(false);
3989
+ }
3990
+ }
3991
+ (_b = restInputProps.onKeyDown) === null || _b === void 0 ? void 0 : _b.call(restInputProps, e);
3992
+ };
3449
3993
  var showPlaceholder = !disabled && !readOnly && value.length === 0;
3450
3994
  console.log('showPlaceholder', showPlaceholder);
3451
3995
  return (React.createElement("div", { className: cn$1('relative w-full', className) },
@@ -3464,7 +4008,7 @@ function TagLabelInputInner(_a, ref) {
3464
4008
  !readOnly &&
3465
4009
  'focus-within:rounded-b-none hover:rounded-b-none', isFocused && !disabled && !readOnly && 'rounded-b-none', getBottomBorderColor(), paddingClass) },
3466
4010
  value.map(function (tag, index) { return (React.createElement(TagLabel, __assign({ key: typeof tag === 'object' ? tag.id || tag.label : "".concat(tag, "-").concat(index), variant: "closeable", size: size, text: getTagLabel(tag), open: true, closeHandler: function () { return handleRemoveTag(index); } }, getTagStyles(tag)))); }),
3467
- React.createElement("input", __assign({}, restInputProps, { "aria-autocomplete": "list", "aria-expanded": isOpen, "aria-haspopup": "listbox", "aria-controls": "".concat(inputId, "-listbox"), disabled: disabled, id: inputId, onChange: function (e) {
4011
+ React.createElement("input", __assign({}, restInputProps, { "aria-autocomplete": "list", "aria-expanded": isOpen, "aria-haspopup": "listbox", "aria-controls": "".concat(inputId, "-listbox"), "aria-activedescendant": activeId, disabled: disabled, id: inputId, onChange: function (e) {
3468
4012
  if (disabled || readOnly)
3469
4013
  return;
3470
4014
  onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(e);
@@ -3554,7 +4098,7 @@ function SegmentButtonItem(_a) {
3554
4098
  : "".concat(sizeConfig$3[size], " ").concat(minWidthConfig[size], " ").concat(minHeightConfig[size]);
3555
4099
  var radiusStyle = "".concat(roundedConfig[size]);
3556
4100
  var selectedStyle = "".concat(isSelectedConfig[isSelected]);
3557
- return (React.createElement("button", { type: "button", onClick: onClick, disabled: disabled, className: "group:last:border-l-0 flex items-center justify-center border-[1px] border-l-0 border-bia-grey-dark-10 first:border-l-[1px] focus-visible:z-50 focus-visible:outline focus-visible:outline-[3px] focus-visible:-outline-offset-1 focus-visible:outline-bia-blue-light-50 disabled:cursor-not-allowed disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(selectedStyle, " ").concat(radiusStyle, " ").concat(sizingStyle, " ").concat(className) }, children));
4101
+ return (React.createElement("button", { type: "button", onClick: onClick, disabled: disabled, className: "group:last:border-l-0 flex items-center justify-center border-[1px] border-l-0 border-bia-grey-dark-10 first:border-l-[1px] focus-visible:z-50 focus-visible:outline focus-visible:outline-[3px] focus-visible:-outline-offset-1 focus-visible:outline-bia-blue-light-50 disabled:cursor-not-allowed disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-grey-dark-10".concat(selectedStyle, " ").concat(radiusStyle, " ").concat(sizingStyle, " ").concat(className) }, children));
3558
4102
  }
3559
4103
 
3560
4104
  function SegmentButtonGroup(_a) {
@@ -3682,8 +4226,151 @@ var areMonthsAdjacent = function (leftMonth, leftYear, rightMonth, rightYear) {
3682
4226
  return rightMonth === leftMonth + 1 && rightYear === leftYear;
3683
4227
  };
3684
4228
 
4229
+ // Default focus ring (R38). Written as one literal so Tailwind scans it.
4230
+ var FOCUS_RING = 'focus-visible:outline focus-visible:outline-[3px] focus-visible:outline-offset-0 focus-visible:outline-bia-blue-light-50';
4231
+ // Marks a grid cell (day, month or year) inside the popup.
4232
+ var CELL_ATTRIBUTE = 'data-calendar-cell';
4233
+ var ACTIVE_CELL_SELECTOR = "[".concat(CELL_ATTRIBUTE, "][tabindex=\"0\"]");
4234
+ var FOCUSABLE_SELECTOR = 'button, [tabindex]';
4235
+ function getTabbableElements(root) {
4236
+ return Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR)).filter(function (element) {
4237
+ if (element.tabIndex < 0)
4238
+ return false;
4239
+ if (element.disabled)
4240
+ return false;
4241
+ return element.getClientRects().length > 0;
4242
+ });
4243
+ }
4244
+ function focusActiveCell(root) {
4245
+ var cell = root === null || root === void 0 ? void 0 : root.querySelector(ACTIVE_CELL_SELECTOR);
4246
+ cell === null || cell === void 0 ? void 0 : cell.focus();
4247
+ }
4248
+ // Escape closes the popup. Tab and Shift+Tab wrap inside the popup.
4249
+ function handleDialogKeyDown(event, onClose) {
4250
+ if (event.key === 'Escape') {
4251
+ event.preventDefault();
4252
+ event.stopPropagation();
4253
+ onClose === null || onClose === void 0 ? void 0 : onClose();
4254
+ return;
4255
+ }
4256
+ if (event.key !== 'Tab')
4257
+ return;
4258
+ var tabbable = getTabbableElements(event.currentTarget);
4259
+ if (tabbable.length === 0)
4260
+ return;
4261
+ var first = tabbable[0];
4262
+ var last = tabbable[tabbable.length - 1];
4263
+ var activeElement = document.activeElement;
4264
+ if (event.shiftKey && (activeElement === first || !activeElement)) {
4265
+ event.preventDefault();
4266
+ last.focus();
4267
+ }
4268
+ else if (!event.shiftKey && activeElement === last) {
4269
+ event.preventDefault();
4270
+ first.focus();
4271
+ }
4272
+ }
4273
+ function isArrowKey(key) {
4274
+ return (key === 'ArrowLeft' ||
4275
+ key === 'ArrowRight' ||
4276
+ key === 'ArrowUp' ||
4277
+ key === 'ArrowDown');
4278
+ }
4279
+ function getArrowStep(key, columns) {
4280
+ switch (key) {
4281
+ case 'ArrowLeft':
4282
+ return -1;
4283
+ case 'ArrowRight':
4284
+ return 1;
4285
+ case 'ArrowUp':
4286
+ return -columns;
4287
+ default:
4288
+ return columns;
4289
+ }
4290
+ }
4291
+
3685
4292
  function DateDisplay(_a) {
3686
- var displayDays = _a.displayDays, viewMonthValue = _a.viewMonthValue, selectedDate = _a.selectedDate, onDateSelect = _a.onDateSelect, minDateValue = _a.minDateValue, maxDateValue = _a.maxDateValue;
4293
+ var displayDays = _a.displayDays, viewMonthValue = _a.viewMonthValue, selectedDate = _a.selectedDate, onDateSelect = _a.onDateSelect, minDateValue = _a.minDateValue, maxDateValue = _a.maxDateValue, _b = _a.viewYearValue, viewYearValue = _b === void 0 ? undefined : _b, _c = _a.onNavigateMonth, onNavigateMonth = _c === void 0 ? undefined : _c, _d = _a.isOpen, isOpen = _d === void 0 ? true : _d;
4294
+ var gridRef = React.useRef(null);
4295
+ // Day picked with the arrow keys, and the month view it was picked in.
4296
+ var _e = React.useState(null), activeState = _e[0], setActiveState = _e[1];
4297
+ // Day to focus once the panel has moved to another month.
4298
+ var pendingFocusRef = React.useRef(null);
4299
+ var viewKey = "".concat(viewYearValue, "-").concat(viewMonthValue);
4300
+ React.useEffect(function () {
4301
+ if (!isOpen)
4302
+ setActiveState(null);
4303
+ }, [isOpen]);
4304
+ var firstDayTime = displayDays[0] ? displayDays[0].getTime() : 0;
4305
+ React.useEffect(function () {
4306
+ var _a, _b;
4307
+ var key = pendingFocusRef.current;
4308
+ if (!key)
4309
+ return;
4310
+ pendingFocusRef.current = null;
4311
+ (_b = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-date=\"".concat(key, "\"]"))) === null || _b === void 0 ? void 0 : _b.focus();
4312
+ }, [firstDayTime]);
4313
+ var isDisabledDay = function (date) {
4314
+ return !!((minDateValue && date < minDateValue) ||
4315
+ (maxDateValue && date > maxDateValue));
4316
+ };
4317
+ var isShown = function (key) {
4318
+ return displayDays.some(function (day) { return dateToInputString(day) === key; });
4319
+ };
4320
+ // The day in the tab order: the one reached with the arrows, else the
4321
+ // selected day, else today, else the first enabled day of the month.
4322
+ var activeKey = null;
4323
+ if (activeState) {
4324
+ var activeDay = displayDays.find(function (day) { return dateToInputString(day) === activeState.key; });
4325
+ if (activeDay &&
4326
+ !isDisabledDay(activeDay) &&
4327
+ (activeState.view === viewKey || activeDay.getMonth() === viewMonthValue)) {
4328
+ activeKey = activeState.key;
4329
+ }
4330
+ }
4331
+ if (!activeKey) {
4332
+ var rangeDates = Array.isArray(selectedDate)
4333
+ ? selectedDate.filter(Boolean).sort()
4334
+ : [];
4335
+ var firstRangeDay = rangeDates[0];
4336
+ var selectedValue = Array.isArray(selectedDate)
4337
+ ? firstRangeDay
4338
+ : selectedDate;
4339
+ var candidates = [
4340
+ selectedValue ? new Date(selectedValue) : null,
4341
+ new Date(TODAY_VALUE),
4342
+ ];
4343
+ var found = candidates.find(function (candidate) {
4344
+ return candidate &&
4345
+ candidate.getMonth() === viewMonthValue &&
4346
+ isShown(dateToInputString(candidate)) &&
4347
+ !isDisabledDay(candidate);
4348
+ });
4349
+ var fallback = found ||
4350
+ displayDays.find(function (day) { return day.getMonth() === viewMonthValue && !isDisabledDay(day); });
4351
+ activeKey = fallback ? dateToInputString(fallback) : null;
4352
+ }
4353
+ var handleKeyDown = function (event, date) {
4354
+ var _a, _b;
4355
+ if (!isArrowKey(event.key))
4356
+ return;
4357
+ event.preventDefault();
4358
+ var target = new Date(date);
4359
+ target.setDate(target.getDate() + getArrowStep(event.key, 7));
4360
+ // A day outside minDate or maxDate does not take focus.
4361
+ if (isDisabledDay(target))
4362
+ return;
4363
+ var targetKey = dateToInputString(target);
4364
+ setActiveState({ key: targetKey, view: viewKey });
4365
+ if (isShown(targetKey)) {
4366
+ (_b = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-date=\"".concat(targetKey, "\"]"))) === null || _b === void 0 ? void 0 : _b.focus();
4367
+ }
4368
+ else if (onNavigateMonth) {
4369
+ pendingFocusRef.current = targetKey;
4370
+ var isBefore = getDayKey(target) < getDayKey(displayDays[0]);
4371
+ onNavigateMonth(isBefore ? 'prev' : 'next');
4372
+ }
4373
+ };
3687
4374
  var isRangeMode = Array.isArray(selectedDate) && selectedDate.length === 2;
3688
4375
  var firstRangeDate = isRangeMode && (selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate[0]) ? new Date(selectedDate[0]) : null;
3689
4376
  var secondRangeDate = isRangeMode && (selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate[1]) ? new Date(selectedDate[1]) : null;
@@ -3695,9 +4382,9 @@ function DateDisplay(_a) {
3695
4382
  return (React.createElement("div", null,
3696
4383
  React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-header grid grid-cols-7 gap-[3px] pb-1.5" }, DAYS_MAP.map(function (day) { return (React.createElement("div", { key: day, className: "bianic-datepicker-calendar-day flex h-[18px] w-[31px] items-center justify-center" },
3697
4384
  React.createElement(Text, { variant: "small-text", extended: "text-bia-coolgrey" }, day.slice(0, 3)))); })),
3698
- React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-body grid grid-cols-7 gap-y-1.5" }, displayDays.map(function (date) {
3699
- var isOutOfRange = !!((minDateValue && date < minDateValue) ||
3700
- (maxDateValue && date > maxDateValue));
4385
+ React.createElement("div", { ref: gridRef, className: "bianic-datepicker-calendar-days-grid-body grid grid-cols-7 gap-y-1.5" }, displayDays.map(function (date) {
4386
+ var isOutOfRange = isDisabledDay(date);
4387
+ var dateKey = dateToInputString(date);
3701
4388
  var isOutOfMonth = date.getMonth() !== viewMonthValue;
3702
4389
  var isStartRange = isRangeMode && checkDateEquals(date, startRangeDate);
3703
4390
  var isEndRange = isRangeMode && checkDateEquals(date, endRangeDate);
@@ -3749,7 +4436,10 @@ function DateDisplay(_a) {
3749
4436
  else if (isOutOfMonth) {
3750
4437
  textStyle = 'text-bia-coolgrey';
3751
4438
  }
3752
- return (React.createElement("button", { type: "button", key: date.toString(), className: "bianic-datepicker-calendar-day flex h-[31px] items-center justify-center ".concat(customClassname, " ").concat(dayStateClass), disabled: isOutOfRange, onClick: function () { return onDateSelect(date); } },
4439
+ return (React.createElement("button", { type: "button", key: date.toString(), className: "bianic-datepicker-calendar-day flex h-[31px] items-center justify-center ".concat(customClassname, " ").concat(dayStateClass, " ").concat(FOCUS_RING), disabled: isOutOfRange, "data-date": dateKey, "data-calendar-cell": "", tabIndex: dateKey === activeKey ? 0 : -1, onKeyDown: function (event) { return handleKeyDown(event, date); }, onClick: function () {
4440
+ setActiveState({ key: dateKey, view: viewKey });
4441
+ onDateSelect(date);
4442
+ } },
3753
4443
  React.createElement(Text, { variant: "small-text", extended: textStyle }, date.getDate())));
3754
4444
  }))));
3755
4445
  }
@@ -3772,8 +4462,10 @@ function MonthDisplay(_a) {
3772
4462
  return dateYear === viewYearValue && dateMonth === monthIndex;
3773
4463
  });
3774
4464
  };
3775
- return (React.createElement("div", { className: "bianic-datepicker-calendar-month-grid grid grid-cols-3 gap-y-1.5" }, MONTH_MAP.map(function (month, index) {
3776
- var isOutOfRange = !!((minDateValue &&
4465
+ var gridRef = React.useRef(null);
4466
+ var _b = React.useState(null), activeIndexState = _b[0], setActiveIndexState = _b[1];
4467
+ var isMonthOutOfRange = function (index) {
4468
+ return !!((minDateValue &&
3777
4469
  minDateValue.getFullYear() <= viewYearValue &&
3778
4470
  index <
3779
4471
  (minDateValue.getFullYear() === viewYearValue
@@ -3785,6 +4477,42 @@ function MonthDisplay(_a) {
3785
4477
  (maxDateValue.getFullYear() === viewYearValue
3786
4478
  ? maxDateValue.getMonth()
3787
4479
  : 11)));
4480
+ };
4481
+ // The month in the tab order: the one reached with the arrows, else the
4482
+ // selected month, else the current month, else the first enabled month.
4483
+ var todayDate = new Date(TODAY_VALUE);
4484
+ var selectedIndex = MONTH_MAP.findIndex(function (_, index) {
4485
+ return isMonthAlreadySelected(index);
4486
+ });
4487
+ var activeIndex = -1;
4488
+ var candidates = [
4489
+ activeIndexState,
4490
+ selectedIndex,
4491
+ todayDate.getFullYear() === viewYearValue ? todayDate.getMonth() : -1,
4492
+ ];
4493
+ var preferred = candidates.find(function (candidate) {
4494
+ return candidate !== null && candidate >= 0 && !isMonthOutOfRange(candidate);
4495
+ });
4496
+ if (preferred !== undefined && preferred !== null) {
4497
+ activeIndex = preferred;
4498
+ }
4499
+ else {
4500
+ activeIndex = MONTH_MAP.findIndex(function (_, index) { return !isMonthOutOfRange(index); });
4501
+ }
4502
+ var handleKeyDown = function (event, index) {
4503
+ var _a, _b;
4504
+ if (!isArrowKey(event.key))
4505
+ return;
4506
+ event.preventDefault();
4507
+ var target = index + getArrowStep(event.key, 3);
4508
+ // Stop at the edges of the grid and at months that are not allowed.
4509
+ if (target < 0 || target > 11 || isMonthOutOfRange(target))
4510
+ return;
4511
+ setActiveIndexState(target);
4512
+ (_b = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-index=\"".concat(target, "\"]"))) === null || _b === void 0 ? void 0 : _b.focus();
4513
+ };
4514
+ return (React.createElement("div", { ref: gridRef, className: "bianic-datepicker-calendar-month-grid grid grid-cols-3 gap-y-1.5" }, MONTH_MAP.map(function (month, index) {
4515
+ var isOutOfRange = isMonthOutOfRange(index);
3788
4516
  var isAlreadySelected = isMonthAlreadySelected(index);
3789
4517
  var isSelected = selectedDate &&
3790
4518
  (Array.isArray(selectedDate) ? selectedDate[0] : selectedDate) &&
@@ -3806,19 +4534,49 @@ function MonthDisplay(_a) {
3806
4534
  }
3807
4535
  return (React.createElement("button", { type: "button", key: month, onClick: function (e) {
3808
4536
  e.stopPropagation();
4537
+ setActiveIndexState(index);
3809
4538
  onMonthSelect(index);
3810
- }, disabled: isOutOfRange, className: "bianic-datepicker-calendar-month mx-[15px] flex h-[31px] items-center justify-center rounded-full ".concat(isSelected || isAlreadySelected
4539
+ }, onKeyDown: function (e) { return handleKeyDown(e, index); }, disabled: isOutOfRange, "data-index": index, "data-calendar-cell": "", tabIndex: index === activeIndex ? 0 : -1, className: "bianic-datepicker-calendar-month mx-[15px] flex h-[31px] items-center justify-center rounded-full ".concat(isSelected || isAlreadySelected
3811
4540
  ? 'border border-bia-blue-dark-10 bg-bia-blue-dark-10'
3812
- : 'enabled:hover:bg-bia-blue-pastel') },
4541
+ : 'enabled:hover:bg-bia-blue-pastel', " ").concat(FOCUS_RING) },
3813
4542
  React.createElement(Text, { variant: "small-text", extended: textStyle }, month.slice(0, 3))));
3814
4543
  })));
3815
4544
  }
3816
4545
 
3817
4546
  function YearDisplay(_a) {
3818
4547
  var yearDisplayRange = _a.yearDisplayRange, viewYearValue = _a.viewYearValue, minDateValue = _a.minDateValue, maxDateValue = _a.maxDateValue, onYearSelect = _a.onYearSelect;
3819
- return (React.createElement("div", { className: "bianic-datepicker-calendar-year-grid grid grid-cols-4 gap-y-1.5" }, yearDisplayRange.map(function (year, index) {
3820
- var isOutOfRange = !!((minDateValue && year < minDateValue.getFullYear()) ||
4548
+ var gridRef = React.useRef(null);
4549
+ var _b = React.useState(null), activeYearState = _b[0], setActiveYearState = _b[1];
4550
+ var isYearOutOfRange = function (year) {
4551
+ return !!((minDateValue && year < minDateValue.getFullYear()) ||
3821
4552
  (maxDateValue && year > maxDateValue.getFullYear()));
4553
+ };
4554
+ // The year in the tab order: the one reached with the arrows, else the
4555
+ // selected year, else the current year, else the first enabled year.
4556
+ var currentYear = new Date(TODAY_VALUE).getFullYear();
4557
+ var preferredYear = [activeYearState, viewYearValue, currentYear].find(function (candidate) {
4558
+ return candidate !== null &&
4559
+ yearDisplayRange.includes(candidate) &&
4560
+ !isYearOutOfRange(candidate);
4561
+ });
4562
+ var activeYear = preferredYear !== null && preferredYear !== void 0 ? preferredYear : yearDisplayRange.find(function (year) { return !isYearOutOfRange(year); });
4563
+ var handleKeyDown = function (event, index) {
4564
+ var _a, _b;
4565
+ if (!isArrowKey(event.key))
4566
+ return;
4567
+ event.preventDefault();
4568
+ var targetIndex = index + getArrowStep(event.key, 4);
4569
+ // Stop at the edges of the grid and at years that are not allowed.
4570
+ if (targetIndex < 0 || targetIndex >= yearDisplayRange.length)
4571
+ return;
4572
+ var targetYear = yearDisplayRange[targetIndex];
4573
+ if (isYearOutOfRange(targetYear))
4574
+ return;
4575
+ setActiveYearState(targetYear);
4576
+ (_b = (_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("[data-year=\"".concat(targetYear, "\"]"))) === null || _b === void 0 ? void 0 : _b.focus();
4577
+ };
4578
+ return (React.createElement("div", { ref: gridRef, className: "bianic-datepicker-calendar-year-grid grid grid-cols-4 gap-y-1.5" }, yearDisplayRange.map(function (year, index) {
4579
+ var isOutOfRange = isYearOutOfRange(year);
3822
4580
  var isSelected = year === viewYearValue;
3823
4581
  var isEdgeYear = index === 0 || index === 11;
3824
4582
  var textStyle = 'text-bia-black';
@@ -3833,10 +4591,11 @@ function YearDisplay(_a) {
3833
4591
  }
3834
4592
  return (React.createElement("button", { type: "button", key: year, onClick: function (e) {
3835
4593
  e.stopPropagation();
4594
+ setActiveYearState(year);
3836
4595
  onYearSelect(year);
3837
- }, disabled: isOutOfRange, className: "bianic-datepicker-calendar-month mx-[6px] flex h-[31px] items-center justify-center rounded-full ".concat(isSelected
4596
+ }, onKeyDown: function (e) { return handleKeyDown(e, index); }, disabled: isOutOfRange, "data-year": year, "data-calendar-cell": "", tabIndex: year === activeYear ? 0 : -1, className: "bianic-datepicker-calendar-month mx-[6px] flex h-[31px] items-center justify-center rounded-full ".concat(isSelected
3838
4597
  ? 'border border-bia-blue-dark-10 bg-bia-blue-dark-10'
3839
- : 'enabled:hover:bg-bia-blue-pastel', " ").concat(isEdgeYear ? 'text-bia-coolgrey' : '') },
4598
+ : 'enabled:hover:bg-bia-blue-pastel', " ").concat(isEdgeYear ? 'text-bia-coolgrey' : '', " ").concat(FOCUS_RING) },
3840
4599
  React.createElement(Text, { variant: "small-text", extended: textStyle }, year)));
3841
4600
  })));
3842
4601
  }
@@ -3857,26 +4616,36 @@ function PickerHeader(_a) {
3857
4616
  else if (pickerMode === 'month') {
3858
4617
  handleNext = handleNextYear;
3859
4618
  }
4619
+ var prevLabels = {
4620
+ date: 'Previous month',
4621
+ month: 'Previous year',
4622
+ year: 'Previous years',
4623
+ };
4624
+ var nextLabels = {
4625
+ date: 'Next month',
4626
+ month: 'Next year',
4627
+ year: 'Next years',
4628
+ };
3860
4629
  return (React.createElement("div", { className: "bianic-datepicker-calendar-controller flex w-full items-center justify-between" },
3861
- React.createElement("button", { type: "button", className: "bianic-datepicker-calendar-prev-button text-bia-coolgrey disabled:text-bia-coolgrey-light-50", disabled: isPrevDisabled ? isPrevDisabled() : false, onClick: handlePrev },
3862
- React.createElement(TbChevronLeft, { size: 18 })),
4630
+ React.createElement("button", { type: "button", "aria-label": prevLabels[pickerMode], className: "bianic-datepicker-calendar-prev-button rounded text-bia-coolgrey disabled:text-bia-coolgrey-light-50 ".concat(FOCUS_RING), disabled: isPrevDisabled ? isPrevDisabled() : false, onClick: handlePrev },
4631
+ React.createElement(TbChevronLeft, { size: 18, "aria-hidden": "true" })),
3863
4632
  React.createElement("div", { className: "bianic-datepicker-calendar-current-month flex items-center justify-center gap-1" },
3864
- React.createElement("button", { type: "button", className: pickerMode === 'date' ? '' : 'hidden', onClick: function (e) {
4633
+ React.createElement("button", { type: "button", className: "".concat(pickerMode === 'date' ? '' : 'hidden', " rounded ").concat(FOCUS_RING), onClick: function (e) {
3865
4634
  e.stopPropagation();
3866
4635
  handlePickerMode('month');
3867
4636
  } },
3868
4637
  React.createElement(Text, { variant: "normal-text-semibold" },
3869
4638
  MONTH_MAP[viewMonthValue],
3870
4639
  ' ')),
3871
- React.createElement("button", { type: "button", className: pickerMode === 'date' || pickerMode === 'month' ? '' : 'hidden', onClick: function (e) {
4640
+ React.createElement("button", { type: "button", className: "".concat(pickerMode === 'date' || pickerMode === 'month' ? '' : 'hidden', " rounded ").concat(FOCUS_RING), onClick: function (e) {
3872
4641
  e.stopPropagation();
3873
4642
  handlePickerMode('year');
3874
4643
  } },
3875
4644
  React.createElement(Text, { variant: "normal-text" }, viewYearValue)),
3876
- React.createElement("button", { type: "button", className: pickerMode === 'year' ? '' : 'hidden' },
4645
+ React.createElement("button", { type: "button", className: "".concat(pickerMode === 'year' ? '' : 'hidden', " rounded ").concat(FOCUS_RING) },
3877
4646
  React.createElement(Text, { variant: "normal-text" }, "".concat(yearDisplayRange[1], " - ").concat(yearDisplayRange[10])))),
3878
- React.createElement("button", { type: "button", className: "bianic-datepicker-calendar-next-button text-bia-coolgrey disabled:text-bia-coolgrey-light-50", disabled: isNextDisabled ? isNextDisabled() : false, onClick: handleNext },
3879
- React.createElement(TbChevronRight, { size: 18 }))));
4647
+ React.createElement("button", { type: "button", "aria-label": nextLabels[pickerMode], className: "bianic-datepicker-calendar-next-button rounded text-bia-coolgrey disabled:text-bia-coolgrey-light-50 ".concat(FOCUS_RING), disabled: isNextDisabled ? isNextDisabled() : false, onClick: handleNext },
4648
+ React.createElement(TbChevronRight, { size: 18, "aria-hidden": "true" }))));
3880
4649
  }
3881
4650
 
3882
4651
  var useCalendarLogic = function (selectedDate, minDate, maxDate) {
@@ -4020,12 +4789,12 @@ var useCalendarLogic = function (selectedDate, minDate, maxDate) {
4020
4789
  };
4021
4790
 
4022
4791
  function PickerContent(_a) {
4023
- var selectedDate = _a.selectedDate, onDateSelect = _a.onDateSelect, _b = _a.initialViewMonth, initialViewMonth = _b === void 0 ? undefined : _b, _c = _a.initialViewYear, initialViewYear = _c === void 0 ? undefined : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.onPrevMonth, onPrevMonth = _d === void 0 ? undefined : _d, _e = _a.onNextMonth, onNextMonth = _e === void 0 ? undefined : _e, _f = _a.onMonthSelect, onMonthSelect = _f === void 0 ? undefined : _f, _g = _a.onYearSelect, onYearSelect = _g === void 0 ? undefined : _g;
4024
- var _h = useCalendarLogic(
4792
+ var selectedDate = _a.selectedDate, onDateSelect = _a.onDateSelect, _b = _a.initialViewMonth, initialViewMonth = _b === void 0 ? undefined : _b, _c = _a.initialViewYear, initialViewYear = _c === void 0 ? undefined : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.onPrevMonth, onPrevMonth = _d === void 0 ? undefined : _d, _e = _a.onNextMonth, onNextMonth = _e === void 0 ? undefined : _e, _f = _a.onMonthSelect, onMonthSelect = _f === void 0 ? undefined : _f, _g = _a.onYearSelect, onYearSelect = _g === void 0 ? undefined : _g, _h = _a.isOpen, isOpen = _h === void 0 ? true : _h;
4793
+ var _j = useCalendarLogic(
4025
4794
  // use first selectedDate if array
4026
4795
  Array.isArray(selectedDate)
4027
4796
  ? selectedDate[0]
4028
- : selectedDate, minDate, maxDate), pickerMode = _h.pickerMode, viewMonthValue = _h.viewMonthValue, viewYearValue = _h.viewYearValue, yearDisplayRange = _h.yearDisplayRange, isPrevDisabled = _h.isPrevDisabled, isNextDisabled = _h.isNextDisabled, internalHandlePrevMonth = _h.handlePrevMonth, handlePrevYear = _h.handlePrevYear, handlePrevDecade = _h.handlePrevDecade, internalHandleNextMonth = _h.handleNextMonth, handleNextYear = _h.handleNextYear, handleNextDecade = _h.handleNextDecade, handlePickerMode = _h.handlePickerMode, getDisplayDays = _h.getDisplayDays, setViewMonthValue = _h.setViewMonthValue, setViewYearValue = _h.setViewYearValue, maxDateValue = _h.maxDateValue, minDateValue = _h.minDateValue;
4797
+ : selectedDate, minDate, maxDate), pickerMode = _j.pickerMode, viewMonthValue = _j.viewMonthValue, viewYearValue = _j.viewYearValue, yearDisplayRange = _j.yearDisplayRange, isPrevDisabled = _j.isPrevDisabled, isNextDisabled = _j.isNextDisabled, internalHandlePrevMonth = _j.handlePrevMonth, handlePrevYear = _j.handlePrevYear, handlePrevDecade = _j.handlePrevDecade, internalHandleNextMonth = _j.handleNextMonth, handleNextYear = _j.handleNextYear, handleNextDecade = _j.handleNextDecade, handlePickerMode = _j.handlePickerMode, getDisplayDays = _j.getDisplayDays, setViewMonthValue = _j.setViewMonthValue, setViewYearValue = _j.setViewYearValue, maxDateValue = _j.maxDateValue, minDateValue = _j.minDateValue;
4029
4798
  React.useEffect(function () {
4030
4799
  if (typeof initialViewMonth === 'number') {
4031
4800
  setViewMonthValue(initialViewMonth);
@@ -4038,32 +4807,58 @@ function PickerContent(_a) {
4038
4807
  var handlePrevMonth = onPrevMonth || internalHandlePrevMonth;
4039
4808
  var handleNextMonth = onNextMonth || internalHandleNextMonth;
4040
4809
  var days = getDisplayDays(viewMonthValue, viewYearValue);
4041
- return (React.createElement("div", { className: "picker-body flex w-[250px] flex-col gap-[15px]" },
4042
- React.createElement(PickerHeader, { pickerMode: pickerMode, viewMonthValue: viewMonthValue, viewYearValue: viewYearValue, yearDisplayRange: yearDisplayRange, isPrevDisabled: isPrevDisabled, isNextDisabled: isNextDisabled, handlePrevMonth: handlePrevMonth, handlePrevYear: handlePrevYear, handlePrevDecade: handlePrevDecade, handleNextMonth: handleNextMonth, handleNextYear: handleNextYear, handleNextDecade: handleNextDecade, handlePickerMode: handlePickerMode }),
4043
- pickerMode === 'date' && (React.createElement(DateDisplay, { displayDays: days, maxDateValue: maxDateValue, minDateValue: minDateValue, onDateSelect: onDateSelect, selectedDate: selectedDate, viewMonthValue: viewMonthValue })),
4810
+ var rootRef = React.useRef(null);
4811
+ // Set when the view changes, so focus follows to the new grid.
4812
+ var focusGridRef = React.useRef(false);
4813
+ var changePickerMode = function (mode) {
4814
+ focusGridRef.current = true;
4815
+ handlePickerMode(mode);
4816
+ };
4817
+ React.useEffect(function () {
4818
+ if (!focusGridRef.current)
4819
+ return;
4820
+ focusGridRef.current = false;
4821
+ focusActiveCell(rootRef.current);
4822
+ }, [pickerMode]);
4823
+ var prevDisabled = isPrevDisabled();
4824
+ var nextDisabled = isNextDisabled();
4825
+ React.useEffect(function () {
4826
+ var _a;
4827
+ var active = document.activeElement;
4828
+ if (active instanceof HTMLButtonElement &&
4829
+ active.disabled &&
4830
+ ((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.contains(active))) {
4831
+ focusActiveCell(rootRef.current);
4832
+ }
4833
+ }, [prevDisabled, nextDisabled]);
4834
+ return (React.createElement("div", { ref: rootRef, className: "picker-body flex w-[250px] flex-col gap-[15px]" },
4835
+ React.createElement(PickerHeader, { pickerMode: pickerMode, viewMonthValue: viewMonthValue, viewYearValue: viewYearValue, yearDisplayRange: yearDisplayRange, isPrevDisabled: isPrevDisabled, isNextDisabled: isNextDisabled, handlePrevMonth: handlePrevMonth, handlePrevYear: handlePrevYear, handlePrevDecade: handlePrevDecade, handleNextMonth: handleNextMonth, handleNextYear: handleNextYear, handleNextDecade: handleNextDecade, handlePickerMode: changePickerMode }),
4836
+ pickerMode === 'date' && (React.createElement(DateDisplay, { displayDays: days, maxDateValue: maxDateValue, minDateValue: minDateValue, onDateSelect: onDateSelect, selectedDate: selectedDate, viewMonthValue: viewMonthValue, viewYearValue: viewYearValue, isOpen: isOpen, onNavigateMonth: function (direction) {
4837
+ return direction === 'prev' ? handlePrevMonth() : handleNextMonth();
4838
+ } })),
4044
4839
  pickerMode === 'month' && (React.createElement(MonthDisplay, { maxDateValue: maxDateValue, minDateValue: minDateValue, onMonthSelect: function (m) {
4045
4840
  if (onMonthSelect)
4046
4841
  onMonthSelect(m);
4047
4842
  else
4048
4843
  setViewMonthValue(m);
4049
- handlePickerMode('date');
4844
+ changePickerMode('date');
4050
4845
  }, selectedDate: selectedDate, viewMonthValue: viewMonthValue, viewYearValue: viewYearValue })),
4051
4846
  pickerMode === 'year' && (React.createElement(YearDisplay, { maxDateValue: maxDateValue, minDateValue: minDateValue, onYearSelect: function (y) {
4052
4847
  if (onYearSelect)
4053
4848
  onYearSelect(y);
4054
4849
  else
4055
4850
  setViewYearValue(y);
4056
- handlePickerMode('month');
4851
+ changePickerMode('month');
4057
4852
  }, viewYearValue: viewYearValue, yearDisplayRange: yearDisplayRange }))));
4058
4853
  }
4059
4854
 
4060
4855
  function SinglePicker(_a) {
4061
- var selectedDate = _a.selectedDate, onDateChange = _a.onDateChange, minDate = _a.minDate, maxDate = _a.maxDate;
4856
+ var selectedDate = _a.selectedDate, onDateChange = _a.onDateChange, minDate = _a.minDate, maxDate = _a.maxDate, _b = _a.isOpen, isOpen = _b === void 0 ? true : _b;
4062
4857
  var handleDateSelect = function (date) {
4063
4858
  onDateChange(dateToInputString(date));
4064
4859
  };
4065
4860
  return (React.createElement("div", { className: "single-picker picker-body" },
4066
- React.createElement(PickerContent, { selectedDate: selectedDate !== null && selectedDate !== void 0 ? selectedDate : null, onDateSelect: handleDateSelect, minDate: minDate, maxDate: maxDate })));
4861
+ React.createElement(PickerContent, { selectedDate: selectedDate !== null && selectedDate !== void 0 ? selectedDate : null, onDateSelect: handleDateSelect, minDate: minDate, maxDate: maxDate, isOpen: isOpen })));
4067
4862
  }
4068
4863
 
4069
4864
  function RangePicker(_a) {
@@ -4260,8 +5055,8 @@ function RangePicker(_a) {
4260
5055
  };
4261
5056
  return (React.createElement("div", { className: "space-y-[30px]" },
4262
5057
  React.createElement("div", { className: "range-picker picker-body flex gap-x-[22px]" },
4263
- React.createElement(PickerContent, { selectedDate: tempSelectedDate, minDate: minDate, maxDate: maxDate, onDateSelect: handleDateSelect, initialViewMonth: leftMonth, initialViewYear: leftYear, onPrevMonth: handleLeftPrevMonth, onNextMonth: handleLeftNextMonth, onMonthSelect: handleMonthSelect(0, leftYear), onYearSelect: handleYearSelectLeft }),
4264
- React.createElement(PickerContent, { selectedDate: tempSelectedDate, minDate: minDate, maxDate: maxDate, onDateSelect: handleDateSelect, initialViewMonth: rightMonth, initialViewYear: rightYear, onPrevMonth: handleRightPrevMonth, onNextMonth: handleRightNextMonth, onMonthSelect: handleMonthSelect(1, rightYear), onYearSelect: handleYearSelectRight })),
5058
+ React.createElement(PickerContent, { selectedDate: tempSelectedDate, minDate: minDate, maxDate: maxDate, onDateSelect: handleDateSelect, initialViewMonth: leftMonth, initialViewYear: leftYear, onPrevMonth: handleLeftPrevMonth, onNextMonth: handleLeftNextMonth, onMonthSelect: handleMonthSelect(0, leftYear), onYearSelect: handleYearSelectLeft, isOpen: isPickerOpen }),
5059
+ React.createElement(PickerContent, { selectedDate: tempSelectedDate, minDate: minDate, maxDate: maxDate, onDateSelect: handleDateSelect, initialViewMonth: rightMonth, initialViewYear: rightYear, onPrevMonth: handleRightPrevMonth, onNextMonth: handleRightNextMonth, onMonthSelect: handleMonthSelect(1, rightYear), onYearSelect: handleYearSelectRight, isOpen: isPickerOpen })),
4265
5060
  React.createElement("div", { className: "flex justify-between" },
4266
5061
  React.createElement(Button, { label: "Reset", size: "sm", variant: "primary-outlined", iconLeft: React.createElement(TbRefresh, { className: "text-bia-blue", size: 14 }), onClick: function () { return setTempSelectedDate([]); } }),
4267
5062
  React.createElement("div", { className: "flex gap-x-2.5" },
@@ -4281,19 +5076,26 @@ function PickerBody(_a) {
4281
5076
  onCloseRef.current();
4282
5077
  }
4283
5078
  }, [isPickerOpen]);
4284
- return (React.createElement("div", { className: "picker-body flex gap-x-5" }, pickerVariant === 'single' ? (React.createElement(SinglePicker, { selectedDate: selectedDate, onDateChange: onDateChange, minDate: minDate, maxDate: maxDate })) : (React.createElement(RangePicker, { selectedDate: selectedDate, onDateChange: onDateChange, minDate: minDate, maxDate: maxDate, onClose: onClose, isPickerOpen: isOpen }))));
5079
+ return (React.createElement("div", { className: "picker-body flex gap-x-5" }, pickerVariant === 'single' ? (React.createElement(SinglePicker, { selectedDate: selectedDate, onDateChange: onDateChange, minDate: minDate, maxDate: maxDate, isOpen: isOpen })) : (React.createElement(RangePicker, { selectedDate: selectedDate, onDateChange: onDateChange, minDate: minDate, maxDate: maxDate, onClose: onClose, isPickerOpen: isOpen }))));
4285
5080
  }
4286
5081
  var PickerCalendar = function (_a) {
4287
5082
  var _b = _a.zIndex, zIndex = _b === void 0 ? 100 : _b, anchorRef = _a.anchorRef, maxDate = _a.maxDate, minDate = _a.minDate, onDateChange = _a.onDateChange; _a.ref; var _c = _a.selectedDate, selectedDate = _c === void 0 ? null : _c, _d = _a.isOpen, isOpen = _d === void 0 ? false : _d, _e = _a.onClose, onClose = _e === void 0 ? function () { } : _e, _f = _a.pickerVariant, pickerVariant = _f === void 0 ? 'range' : _f, props = __rest(_a, ["zIndex", "anchorRef", "maxDate", "minDate", "onDateChange", "ref", "selectedDate", "isOpen", "onClose", "pickerVariant"]);
4288
5083
  // Hooks & States
4289
5084
  var pickerCalendarRef = React.useRef(null);
4290
5085
  var _g = useDetectOutsideClick(anchorRef, false, pickerCalendarRef), isPickerOpen = _g[0], setIsPickerOpen = _g[1];
4291
- var style = props.style, className = props.className, restProps = __rest(props, ["style", "className"]);
5086
+ var style = props.style, className = props.className, onKeyDown = props.onKeyDown, restProps = __rest(props, ["style", "className", "onKeyDown"]);
4292
5087
  var positionStyle = usePopupPosition(anchorRef, pickerCalendarRef)[0];
4293
5088
  React.useEffect(function () {
4294
5089
  setIsPickerOpen(isOpen);
4295
5090
  }, [isOpen, setIsPickerOpen]);
4296
- return reactDom.createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'flex' : 'none' }, positionStyle), style) }, restProps),
5091
+ return reactDom.createPortal(
5092
+ // Escape and Tab are handled on the dialog root, not on a control.
5093
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
5094
+ React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, role: "dialog", "aria-label": pickerVariant === 'single' ? 'Choose date' : 'Choose date range', style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'flex' : 'none' }, positionStyle), style) }, restProps, { onKeyDown: function (event) {
5095
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
5096
+ if (!event.defaultPrevented)
5097
+ handleDialogKeyDown(event, onClose);
5098
+ } }),
4297
5099
  React.createElement(PickerBody, { selectedDate: selectedDate, minDate: minDate, maxDate: maxDate, onDateChange: onDateChange, isPickerOpen: isPickerOpen, pickerVariant: pickerVariant, onClose: onClose, isOpen: isOpen })), document.body);
4298
5100
  };
4299
5101
 
@@ -4320,7 +5122,7 @@ var displayDateFormatter = function (date) {
4320
5122
  return "".concat(date.getDate(), " ").concat(monthMap[date.getMonth()].slice(0, 3), " '").concat(date.getFullYear().toString().slice(2, 4));
4321
5123
  };
4322
5124
  var DateInputDisplay = React.forwardRef(function (_a, ref) {
4323
- var value = _a.value, _b = _a.setValue, setValue = _b === void 0 ? function () { } : _b, _c = _a.placeholder, placeholder = _c === void 0 ? 'YYYY-MM-DD' : _c, _d = _a.label, label = _d === void 0 ? '' : _d, required = _a.required, readOnly = _a.readOnly, id = _a.id, _e = _a.size, size = _e === void 0 ? 'sm' : _e, className = _a.className, _f = _a.disabled, disabled = _f === void 0 ? false : _f, _g = _a.buttonAction, buttonAction = _g === void 0 ? function () { } : _g, _h = _a.nullDisplay, nullDisplay = _h === void 0 ? '' : _h;
5125
+ var value = _a.value, _b = _a.setValue, setValue = _b === void 0 ? function () { } : _b, _c = _a.placeholder, placeholder = _c === void 0 ? 'YYYY-MM-DD' : _c, _d = _a.label, label = _d === void 0 ? '' : _d, required = _a.required, readOnly = _a.readOnly, id = _a.id, _e = _a.size, size = _e === void 0 ? 'sm' : _e, className = _a.className, _f = _a.disabled, disabled = _f === void 0 ? false : _f, _g = _a.buttonAction, buttonAction = _g === void 0 ? function () { } : _g, _h = _a.nullDisplay, nullDisplay = _h === void 0 ? '' : _h, _j = _a.toggleButtonRef, toggleButtonRef = _j === void 0 ? undefined : _j, _k = _a.toggleLabel, toggleLabel = _k === void 0 ? 'Choose date' : _k, _l = _a.isOpen, isOpen = _l === void 0 ? false : _l;
4324
5126
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
4325
5127
  _a.isActive;
4326
5128
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
@@ -4344,10 +5146,10 @@ var DateInputDisplay = React.forwardRef(function (_a, ref) {
4344
5146
  viewValue = displayDateFormatter(new Date(value));
4345
5147
  }
4346
5148
  }
4347
- var _j = React.useState(false), isEditing = _j[0], setIsEditing = _j[1];
4348
- var _k = React.useState(inputValue), dateString = _k[0], setDateString = _k[1];
5149
+ var _m = React.useState(false), isEditing = _m[0], setIsEditing = _m[1];
5150
+ var _o = React.useState(inputValue), dateString = _o[0], setDateString = _o[1];
4349
5151
  var fieldStyle = styleConfig.text.fieldStyle;
4350
- var _l = sizeConfig$d[size], iconSize = _l.iconSize, fieldSize = _l.fieldSize, iconPosition = _l.iconPosition;
5152
+ var _p = sizeConfig$d[size], iconSize = _p.iconSize, fieldSize = _p.fieldSize, iconPosition = _p.iconPosition;
4351
5153
  var borderStyle = 'border border-bia-grey-dark-10 bg-primary-white';
4352
5154
  var extendedInputClassName = "w-full ".concat(fieldStyle, " ").concat(fieldSize, " ").concat(borderStyle, " ").concat(className);
4353
5155
  var handleTextChange = function (event) {
@@ -4367,14 +5169,19 @@ var DateInputDisplay = React.forwardRef(function (_a, ref) {
4367
5169
  if (setValue)
4368
5170
  setValue('');
4369
5171
  };
4370
- var handleBlur = function () {
5172
+ // Runs when focus leaves the whole field. Moving from the text to the
5173
+ // icon stays inside the field, so editing continues.
5174
+ var handleBlur = function (event) {
5175
+ if (event.currentTarget.contains(event.relatedTarget)) {
5176
+ return;
5177
+ }
4371
5178
  setIsEditing(false);
4372
5179
  setDateString(inputValue);
4373
5180
  };
4374
- var input = isEditing || disabled ? (React.createElement(TextInput, { type: "text", value: dateString !== null && dateString !== void 0 ? dateString : '', onChange: handleTextChange, onBlur: handleBlur, placeholder: placeholder, size: size, inputClassName: extendedInputClassName, autoFocus: true, disabled: disabled, actionElement: React.createElement("button", { type: "button", className: "bianic-datepicker-toggle-button text-bia-coolgrey disabled:cursor-not-allowed", disabled: disabled, onClick: function () {
4375
- buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction();
5181
+ var input = isEditing || disabled ? (React.createElement(TextInput, { type: "text", value: dateString !== null && dateString !== void 0 ? dateString : '', onChange: handleTextChange, placeholder: placeholder, size: size, inputClassName: extendedInputClassName, autoFocus: true, disabled: disabled, actionElement: React.createElement("button", { type: "button", ref: toggleButtonRef, "aria-label": toggleLabel, "aria-haspopup": "dialog", "aria-expanded": isOpen, className: "bianic-datepicker-toggle-button rounded text-bia-coolgrey disabled:cursor-not-allowed ".concat(FOCUS_RING), disabled: disabled, onClick: function (event) {
5182
+ buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction(event);
4376
5183
  } },
4377
- React.createElement(TbCalendar, { size: iconSize })) })) : (React.createElement(React.Fragment, null,
5184
+ React.createElement(TbCalendar, { size: iconSize, "aria-hidden": "true" })) })) : (React.createElement(React.Fragment, null,
4378
5185
  React.createElement("div", { role: "button", tabIndex: 0, onClick: function () { return setIsEditing(true); }, onKeyDown: function (e) {
4379
5186
  if (e.key === 'Enter' || e.key === ' ') {
4380
5187
  e.preventDefault();
@@ -4382,8 +5189,8 @@ var DateInputDisplay = React.forwardRef(function (_a, ref) {
4382
5189
  }
4383
5190
  }, className: "bianic-text-input bianic-fgc-target w-full rounded hover:rounded-b-none hover:border-b-bia-blue focus:rounded-b-none focus-visible:outline-none disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(extendedInputClassName, " ").concat(inputValue || nullDisplay ? 'text-bia-black' : 'text-bia-coolgrey') }, viewValue),
4384
5191
  React.createElement("div", { className: "absolute inset-y-0 flex items-center pl-3 text-bia-coolgrey ".concat(iconPosition) },
4385
- React.createElement("button", { type: "button", className: "bianic-datepicker-toggle-button", disabled: disabled, onClick: function () { return buttonAction && buttonAction(); } },
4386
- React.createElement(TbCalendar, { size: iconSize })))));
5192
+ React.createElement("button", { type: "button", ref: toggleButtonRef, "aria-label": toggleLabel, "aria-haspopup": "dialog", "aria-expanded": isOpen, className: "bianic-datepicker-toggle-button rounded ".concat(FOCUS_RING), disabled: disabled, onClick: function (event) { return buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction(event); } },
5193
+ React.createElement(TbCalendar, { size: iconSize, "aria-hidden": "true" })))));
4387
5194
  React.useEffect(function () {
4388
5195
  // Only update dateString if we are NOT currently editing.
4389
5196
  if (!isEditing)
@@ -4391,7 +5198,7 @@ var DateInputDisplay = React.forwardRef(function (_a, ref) {
4391
5198
  }, [inputValue, isEditing]);
4392
5199
  return (React.createElement("div", { className: "bianic-date-input-container bianic-fgc-container flex w-full flex-col gap-y-2 text-bia-black" },
4393
5200
  label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
4394
- React.createElement("div", { className: "relative w-full", ref: ref }, input)));
5201
+ React.createElement("div", { className: "relative w-full", ref: ref, onBlur: handleBlur }, input)));
4395
5202
  });
4396
5203
  DateInputDisplay.defaultProps = {
4397
5204
  setValue: undefined,
@@ -4401,26 +5208,68 @@ DateInputDisplay.defaultProps = {
4401
5208
  setIsActive: undefined,
4402
5209
  buttonAction: undefined,
4403
5210
  nullDisplay: undefined,
5211
+ toggleButtonRef: undefined,
5212
+ toggleLabel: undefined,
5213
+ isOpen: undefined,
4404
5214
  };
4405
5215
 
4406
5216
  function DatePicker(_a) {
4407
5217
  var _b = _a.zIndexCalendar, zIndexCalendar = _b === void 0 ? 100 : _b, _c = _a.value, value = _c === void 0 ? '' : _c, _d = _a.onChange, onChange = _d === void 0 ? function () { } : _d, _e = _a.variant, variant = _e === void 0 ? 'single' : _e, _f = _a.size, size = _f === void 0 ? 'sm' : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.placeholder, placeholder = _h === void 0 ? '"YYYY-MM-DD"' : _h, _j = _a.label, label = _j === void 0 ? '' : _j, _k = _a.minDate, minDate = _k === void 0 ? '' : _k, _l = _a.maxDate, maxDate = _l === void 0 ? '' : _l, _m = _a.required, required = _m === void 0 ? false : _m, _o = _a.nullDisplay, nullDisplay = _o === void 0 ? '' : _o, _p = _a.inputClassName, inputClassName = _p === void 0 ? '' : _p, _q = _a.containerClassName, containerClassName = _q === void 0 ? '' : _q;
4408
5218
  // State and Ref
4409
5219
  var inputRef = React.useRef(null);
5220
+ var toggleButtonRef = React.useRef(null);
5221
+ var focusOnOpenRef = React.useRef(false);
5222
+ var calendarId = React.useId();
4410
5223
  var _r = React.useState(false), isPickerOpen = _r[0], setIsPickerOpen = _r[1];
5224
+ // Enter or Space on the icon fires a click with detail 0. Only then does
5225
+ // focus move into the popup, so mouse use keeps focus where it is.
5226
+ var handleButtonAction = function (event) {
5227
+ var willOpen = !isPickerOpen;
5228
+ focusOnOpenRef.current = willOpen && (event === null || event === void 0 ? void 0 : event.detail) === 0;
5229
+ setIsPickerOpen(willOpen);
5230
+ };
5231
+ React.useEffect(function () {
5232
+ if (!isPickerOpen || !focusOnOpenRef.current)
5233
+ return undefined;
5234
+ var frame = 0;
5235
+ var attempts = 0;
5236
+ // The popup may not be visible yet, so retry for a few frames.
5237
+ var tryFocus = function () {
5238
+ var popup = document.getElementById(calendarId);
5239
+ focusActiveCell(popup);
5240
+ attempts += 1;
5241
+ if ((popup === null || popup === void 0 ? void 0 : popup.contains(document.activeElement)) || attempts >= 30) {
5242
+ focusOnOpenRef.current = false;
5243
+ return;
5244
+ }
5245
+ frame = requestAnimationFrame(tryFocus);
5246
+ };
5247
+ frame = requestAnimationFrame(tryFocus);
5248
+ return function () { return cancelAnimationFrame(frame); };
5249
+ }, [isPickerOpen, calendarId]);
5250
+ // Closing while focus is inside the popup puts focus back on the icon.
5251
+ var handleClose = function () {
5252
+ var _a;
5253
+ var popup = document.getElementById(calendarId);
5254
+ var wasInside = !!popup && popup.contains(document.activeElement);
5255
+ setIsPickerOpen(false);
5256
+ if (wasInside)
5257
+ (_a = toggleButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
5258
+ };
5259
+ var toggleLabel = variant === 'range' ? 'Choose date range' : 'Choose date';
4411
5260
  return (React.createElement("div", { className: "bianic-datepicker-container relative ".concat(containerClassName) },
4412
5261
  React.createElement("div", { className: "bianic-datepicker-field-container" },
4413
- React.createElement(DateInputDisplay, { className: inputClassName || '', value: value, setValue: onChange, placeholder: placeholder, nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: function () { return setIsPickerOpen(!isPickerOpen); }, ref: inputRef, disabled: disabled })),
4414
- React.createElement(PickerCalendar, { zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, pickerVariant: variant, onDateChange: onChange, minDate: minDate, maxDate: maxDate, isOpen: isPickerOpen, onClose: function () { return setIsPickerOpen(false); } })));
5262
+ React.createElement(DateInputDisplay, { className: inputClassName || '', value: value, setValue: onChange, placeholder: placeholder, nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: handleButtonAction, toggleButtonRef: toggleButtonRef, toggleLabel: toggleLabel, isOpen: isPickerOpen, ref: inputRef, disabled: disabled })),
5263
+ React.createElement(PickerCalendar, { id: calendarId, "aria-label": toggleLabel, zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, pickerVariant: variant, onDateChange: onChange, minDate: minDate, maxDate: maxDate, isOpen: isPickerOpen, onClose: handleClose })));
4415
5264
  }
4416
5265
 
4417
5266
  var YearPickerDisplay = React.forwardRef(function (_a, ref) {
4418
- var value = _a.value, setValue = _a.setValue, _b = _a.placeholder, placeholder = _b === void 0 ? 'YYYY' : _b, label = _a.label, required = _a.required, readOnly = _a.readOnly, id = _a.id, _c = _a.size, size = _c === void 0 ? 'sm' : _c, className = _a.className, _d = _a.disabled, disabled = _d === void 0 ? false : _d, buttonAction = _a.buttonAction, nullDisplay = _a.nullDisplay, minYear = _a.minYear, maxYear = _a.maxYear, customErrorMessage = _a.errorMessage, onErrorChange = _a.onErrorChange, props = __rest(_a, ["value", "setValue", "placeholder", "label", "required", "readOnly", "id", "size", "className", "disabled", "buttonAction", "nullDisplay", "minYear", "maxYear", "errorMessage", "onErrorChange"]);
5267
+ var value = _a.value, setValue = _a.setValue, _b = _a.placeholder, placeholder = _b === void 0 ? 'YYYY' : _b, label = _a.label, required = _a.required, readOnly = _a.readOnly, id = _a.id, _c = _a.size, size = _c === void 0 ? 'sm' : _c, className = _a.className, _d = _a.disabled, disabled = _d === void 0 ? false : _d, buttonAction = _a.buttonAction, nullDisplay = _a.nullDisplay, _e = _a.toggleButtonRef, toggleButtonRef = _e === void 0 ? undefined : _e, _f = _a.toggleLabel, toggleLabel = _f === void 0 ? 'Choose year' : _f, _g = _a.isOpen, isOpen = _g === void 0 ? false : _g, minYear = _a.minYear, maxYear = _a.maxYear, customErrorMessage = _a.errorMessage, onErrorChange = _a.onErrorChange, props = __rest(_a, ["value", "setValue", "placeholder", "label", "required", "readOnly", "id", "size", "className", "disabled", "buttonAction", "nullDisplay", "toggleButtonRef", "toggleLabel", "isOpen", "minYear", "maxYear", "errorMessage", "onErrorChange"]);
4419
5268
  var inputRef = React.useRef(null);
4420
5269
  React.useImperativeHandle(ref, function () { return inputRef.current; });
4421
- var _e = React.useState(false), isEditing = _e[0], setIsEditing = _e[1];
4422
- var _f = React.useState(value ? value.toString() : ''), inputValue = _f[0], setInputValue = _f[1];
4423
- var _g = React.useState(null), internalError = _g[0], setInternalError = _g[1];
5270
+ var _h = React.useState(false), isEditing = _h[0], setIsEditing = _h[1];
5271
+ var _j = React.useState(value ? value.toString() : ''), inputValue = _j[0], setInputValue = _j[1];
5272
+ var _k = React.useState(null), internalError = _k[0], setInternalError = _k[1];
4424
5273
  var setError = function (msg) {
4425
5274
  setInternalError(msg);
4426
5275
  onErrorChange === null || onErrorChange === void 0 ? void 0 : onErrorChange(msg);
@@ -4476,7 +5325,14 @@ var YearPickerDisplay = React.forwardRef(function (_a, ref) {
4476
5325
  }
4477
5326
  }
4478
5327
  };
4479
- var handleBlur = function () {
5328
+ // Runs when focus leaves the whole field. Moving from the text to the
5329
+ // icon stays inside the field, so editing continues.
5330
+ var handleBlur = function (event) {
5331
+ if (!isEditing)
5332
+ return;
5333
+ if (event.currentTarget.contains(event.relatedTarget)) {
5334
+ return;
5335
+ }
4480
5336
  setIsEditing(false);
4481
5337
  // Case A: User left field incomplete (< 4 digits)
4482
5338
  if (inputValue.length > 0 && inputValue.length < 4) {
@@ -4502,17 +5358,17 @@ var YearPickerDisplay = React.forwardRef(function (_a, ref) {
4502
5358
  }
4503
5359
  }
4504
5360
  };
4505
- var _h = sizeConfig$d[size], iconSize = _h.iconSize, fieldSize = _h.fieldSize, iconPosition = _h.iconPosition;
5361
+ var _l = sizeConfig$d[size], iconSize = _l.iconSize, fieldSize = _l.fieldSize, iconPosition = _l.iconPosition;
4506
5362
  var fieldStyle = styleConfig.text.fieldStyle;
4507
5363
  var displayError = customErrorMessage || internalError;
4508
5364
  var borderStyle = displayError
4509
5365
  ? 'border border-bia-red bg-primary-white'
4510
5366
  : 'border border-bia-grey-dark-10 bg-primary-white';
4511
5367
  var extendedInputClassName = "w-full ".concat(fieldStyle, " ").concat(fieldSize, " ").concat(borderStyle, " ").concat(className);
4512
- var input = isEditing || disabled ? (React.createElement(TextInput, __assign({ type: "text", id: id, value: inputValue, placeholder: placeholder, size: size, inputClassName: extendedInputClassName, onChange: handleChange, onBlur: handleBlur, autoFocus: true, required: required, disabled: disabled, actionElement: React.createElement("button", { type: "button", className: "bianic-datepicker-toggle-button text-bia-coolgrey disabled:cursor-not-allowed", disabled: disabled, onClick: function () {
4513
- buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction();
5368
+ var input = isEditing || disabled ? (React.createElement(TextInput, __assign({ type: "text", id: id, value: inputValue, placeholder: placeholder, size: size, inputClassName: extendedInputClassName, onChange: handleChange, autoFocus: true, required: required, disabled: disabled, actionElement: React.createElement("button", { type: "button", ref: toggleButtonRef, "aria-label": toggleLabel, "aria-haspopup": "dialog", "aria-expanded": isOpen, className: "bianic-datepicker-toggle-button rounded text-bia-coolgrey disabled:cursor-not-allowed ".concat(FOCUS_RING), disabled: disabled, onClick: function (event) {
5369
+ buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction(event);
4514
5370
  } },
4515
- React.createElement(TbCalendar, { size: iconSize })) }, props))) : (React.createElement(React.Fragment, null,
5371
+ React.createElement(TbCalendar, { size: iconSize, "aria-hidden": "true" })) }, props))) : (React.createElement(React.Fragment, null,
4516
5372
  React.createElement("div", { role: "button", tabIndex: disabled ? -1 : 0, onClick: function () { return !disabled && setIsEditing(true); }, onKeyDown: function (e) {
4517
5373
  if (e.key === 'Enter' || e.key === ' ') {
4518
5374
  e.preventDefault();
@@ -4521,11 +5377,11 @@ var YearPickerDisplay = React.forwardRef(function (_a, ref) {
4521
5377
  }
4522
5378
  }, className: "bianic-text-input bianic-fgc-target flex w-full items-center rounded hover:rounded-b-none hover:border-b-bia-blue focus:rounded-b-none focus-visible:outline-none disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-coolgrey ".concat(extendedInputClassName, " ").concat(value || nullDisplay ? 'text-bia-black' : 'text-bia-coolgrey', " ").concat(disabled ? 'cursor-not-allowed opacity-60' : 'cursor-text') }, value || nullDisplay || placeholder),
4523
5379
  React.createElement("div", { className: "absolute inset-y-0 right-0 flex items-center pl-3 text-bia-coolgrey ".concat(iconPosition) },
4524
- React.createElement("button", { type: "button", className: "bianic-datepicker-toggle-button", disabled: disabled, onClick: function () { return buttonAction && buttonAction(); } },
4525
- React.createElement(TbCalendar, { size: iconSize })))));
5380
+ React.createElement("button", { type: "button", ref: toggleButtonRef, "aria-label": toggleLabel, "aria-haspopup": "dialog", "aria-expanded": isOpen, className: "bianic-datepicker-toggle-button rounded ".concat(FOCUS_RING), disabled: disabled, onClick: function (event) { return buttonAction === null || buttonAction === void 0 ? void 0 : buttonAction(event); } },
5381
+ React.createElement(TbCalendar, { size: iconSize, "aria-hidden": "true" })))));
4526
5382
  return (React.createElement("div", { className: "bianic-year-input-container bianic-fgc-container flex w-full flex-col gap-y-1 text-bia-black" },
4527
5383
  label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
4528
- React.createElement("div", { className: "relative w-full", ref: inputRef }, input),
5384
+ React.createElement("div", { className: "relative w-full", ref: inputRef, onBlur: handleBlur }, input),
4529
5385
  displayError && (React.createElement("span", { className: "text-xs text-bia-red" }, displayError))));
4530
5386
  });
4531
5387
  YearPickerDisplay.defaultProps = {
@@ -4598,14 +5454,21 @@ var PickerYear = function (_a) {
4598
5454
  var _d = useYearLogic(selectedYear, minYear, maxYear), viewYearValue = _d.viewYearValue, yearDisplayRange = _d.yearDisplayRange, isNextDisabled = _d.isNextDisabled, isPrevDisabled = _d.isPrevDisabled, handleNextDecade = _d.handleNextDecade, handleNextYear = _d.handleNextYear, handlePrevDecade = _d.handlePrevDecade, handlePrevYear = _d.handlePrevYear;
4599
5455
  var pickerCalendarRef = React.useRef(null);
4600
5456
  var _e = useDetectOutsideClick(anchorRef, false, pickerCalendarRef), isPickerOpen = _e[0], setIsPickerOpen = _e[1];
4601
- var style = props.style, className = props.className, restProps = __rest(props, ["style", "className"]);
5457
+ var style = props.style, className = props.className, onKeyDown = props.onKeyDown, restProps = __rest(props, ["style", "className", "onKeyDown"]);
4602
5458
  var positionStyle = usePopupPosition(anchorRef, pickerCalendarRef)[0];
4603
5459
  var substituteMaxDate = maxYear ? new Date(maxYear, 0, 1) : null;
4604
5460
  var substituteMinDate = minYear ? new Date(minYear, 0, 1) : null;
4605
5461
  React.useEffect(function () {
4606
5462
  setIsPickerOpen(isOpen);
4607
5463
  }, [isOpen, setIsPickerOpen]);
4608
- return reactDom.createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'flex' : 'none' }, positionStyle), style) }, restProps),
5464
+ return reactDom.createPortal(
5465
+ // Escape and Tab are handled on the dialog root, not on a control.
5466
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
5467
+ React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, role: "dialog", "aria-label": "Choose year", style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'flex' : 'none' }, positionStyle), style) }, restProps, { onKeyDown: function (event) {
5468
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
5469
+ if (!event.defaultPrevented)
5470
+ handleDialogKeyDown(event, onClose);
5471
+ } }),
4609
5472
  React.createElement("div", { className: "picker-body flex w-[250px] flex-col gap-[15px]" },
4610
5473
  React.createElement(PickerHeader, { pickerMode: "year", handlePickerMode: function () { }, viewYearValue: viewYearValue, yearDisplayRange: yearDisplayRange, isPrevDisabled: isPrevDisabled, isNextDisabled: isNextDisabled, handlePrevYear: handlePrevYear, handlePrevDecade: handlePrevDecade, handleNextYear: handleNextYear, handleNextDecade: handleNextDecade, viewMonthValue: 0 }),
4611
5474
  React.createElement(YearDisplay, { maxDateValue: substituteMaxDate, minDateValue: substituteMinDate, onYearSelect: function (y) {
@@ -4617,11 +5480,49 @@ var PickerYear = function (_a) {
4617
5480
  function YearPicker(_a) {
4618
5481
  var value = _a.value, onChange = _a.onChange, _b = _a.zIndexCalendar, zIndexCalendar = _b === void 0 ? 100 : _b, _c = _a.minYear, minYear = _c === void 0 ? undefined : _c, _d = _a.maxYear, maxYear = _d === void 0 ? undefined : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, disabled = _a.disabled, _f = _a.placeholder, placeholder = _f === void 0 ? '"YYYY-MM-DD"' : _f, label = _a.label, required = _a.required, nullDisplay = _a.nullDisplay, inputClassName = _a.inputClassName, containerClassName = _a.containerClassName;
4619
5482
  var inputRef = React.useRef(null);
5483
+ var toggleButtonRef = React.useRef(null);
5484
+ var focusOnOpenRef = React.useRef(false);
5485
+ var calendarId = React.useId();
4620
5486
  var _g = React.useState(false), isPickerOpen = _g[0], setIsPickerOpen = _g[1];
5487
+ // Enter or Space on the icon fires a click with detail 0. Only then does
5488
+ // focus move into the popup, so mouse use keeps focus where it is.
5489
+ var handleButtonAction = function (event) {
5490
+ var willOpen = !isPickerOpen;
5491
+ focusOnOpenRef.current = willOpen && (event === null || event === void 0 ? void 0 : event.detail) === 0;
5492
+ setIsPickerOpen(willOpen);
5493
+ };
5494
+ React.useEffect(function () {
5495
+ if (!isPickerOpen || !focusOnOpenRef.current)
5496
+ return undefined;
5497
+ var frame = 0;
5498
+ var attempts = 0;
5499
+ // The popup may not be visible yet, so retry for a few frames.
5500
+ var tryFocus = function () {
5501
+ var popup = document.getElementById(calendarId);
5502
+ focusActiveCell(popup);
5503
+ attempts += 1;
5504
+ if ((popup === null || popup === void 0 ? void 0 : popup.contains(document.activeElement)) || attempts >= 30) {
5505
+ focusOnOpenRef.current = false;
5506
+ return;
5507
+ }
5508
+ frame = requestAnimationFrame(tryFocus);
5509
+ };
5510
+ frame = requestAnimationFrame(tryFocus);
5511
+ return function () { return cancelAnimationFrame(frame); };
5512
+ }, [isPickerOpen, calendarId]);
5513
+ // Closing while focus is inside the popup puts focus back on the icon.
5514
+ var handleClose = function () {
5515
+ var _a;
5516
+ var popup = document.getElementById(calendarId);
5517
+ var wasInside = !!popup && popup.contains(document.activeElement);
5518
+ setIsPickerOpen(false);
5519
+ if (wasInside)
5520
+ (_a = toggleButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
5521
+ };
4621
5522
  return (React.createElement("div", { className: "bianic-yearpicker-container relative ".concat(containerClassName) },
4622
5523
  React.createElement("div", { className: "bianic-yearpicker-field-container" },
4623
- React.createElement(YearPickerDisplay, { className: inputClassName || '', value: value, setValue: onChange, placeholder: placeholder, nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: function () { return setIsPickerOpen(!isPickerOpen); }, ref: inputRef, disabled: disabled, minYear: minYear, maxYear: maxYear })),
4624
- React.createElement(PickerYear, { maxYear: maxYear, minYear: minYear, zIndex: zIndexCalendar, anchorRef: inputRef, selectedYear: value, setSelectedYear: onChange, isOpen: isPickerOpen, onClose: function () { return setIsPickerOpen(false); } })));
5524
+ React.createElement(YearPickerDisplay, { className: inputClassName || '', value: value, setValue: onChange, placeholder: placeholder, nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: handleButtonAction, toggleButtonRef: toggleButtonRef, toggleLabel: "Choose year", isOpen: isPickerOpen, ref: inputRef, disabled: disabled, minYear: minYear, maxYear: maxYear })),
5525
+ React.createElement(PickerYear, { id: calendarId, "aria-label": "Choose year", maxYear: maxYear, minYear: minYear, zIndex: zIndexCalendar, anchorRef: inputRef, selectedYear: value, setSelectedYear: onChange, isOpen: isPickerOpen, onClose: handleClose })));
4625
5526
  }
4626
5527
 
4627
5528
  /**
@@ -5405,7 +6306,7 @@ function ProgressBar(_a) {
5405
6306
  iconElement = icon; // Use the provided icon
5406
6307
  }
5407
6308
  }
5408
- return (React.createElement("div", { className: "bianic-progress-bar-container flex w-[320px] flex-col rounded-radius-lg bg-bia-grey-light-80 p-[10px] " },
6309
+ return (React.createElement("div", { className: "bianic-progress-bar-container flex w-full flex-col rounded-radius-lg bg-bia-grey-light-80 p-[10px] " },
5409
6310
  React.createElement("div", { className: "flex items-center justify-between text-primary-black" },
5410
6311
  React.createElement(Text, { variant: "small-text-semibold", extended: "bianic-progress-bar-title" }, title),
5411
6312
  React.createElement("div", { className: "flex gap-1" },
@@ -6080,7 +6981,8 @@ function TableFooterController(_a) {
6080
6981
 
6081
6982
  function TableHeaderController(_a) {
6082
6983
  var _b = _a.size, size = _b === void 0 ? 'sm' : _b, _c = _a.buttonActions, buttonActions = _c === void 0 ? undefined : _c, _d = _a.totalData, totalData = _d === void 0 ? undefined : _d, _e = _a.firstIndex, firstIndex = _e === void 0 ? undefined : _e, _f = _a.lastIndex, lastIndex = _f === void 0 ? undefined : _f;
6083
- var isShowHelperText = totalData || firstIndex || lastIndex;
6984
+ // Boolean(): a bare 0 would be printed by React when there are no results.
6985
+ var isShowHelperText = Boolean(totalData || firstIndex || lastIndex);
6084
6986
  var paddingSize = size === 'md' ? 'py-[13px] pt-[14px] ' : 'py-[7px] pt-2';
6085
6987
  var textSize = size === 'md' ? 'normal-text' : 'small-text';
6086
6988
  return (React.createElement("div", { className: "table-controller-header flex w-full justify-between rounded-t-radius-lg border-b border-bia-grey bg-bia-grey-light-80 px-2.5 ".concat(paddingSize) },
@@ -6543,6 +7445,59 @@ function DataTable(_a) {
6543
7445
  React.createElement(TableFooterController, { size: "md", currentPage: table.page, totalPages: table.totalPages, pageSize: table.pageSize, setCurrentPage: setCurrentPage, setPageSize: setPageSize, isLoading: isLoading })));
6544
7446
  }
6545
7447
 
7448
+ var openStateConfig = {
7449
+ open: 'visible grid-rows-[1fr] opacity-100',
7450
+ closed: 'invisible grid-rows-[0fr] opacity-0',
7451
+ };
7452
+ var columnsConfig = {
7453
+ auto: 'grid-cols-[repeat(3,minmax(0,1fr))_auto]',
7454
+ 2: 'grid-cols-2',
7455
+ 3: 'grid-cols-3',
7456
+ 4: 'grid-cols-4',
7457
+ 5: 'grid-cols-5',
7458
+ 6: 'grid-cols-6',
7459
+ };
7460
+ var panelSizeConfig = {
7461
+ md: 'gap-5 px-5 py-[25px]',
7462
+ sm: 'gap-4 px-5 py-6',
7463
+ };
7464
+ var actionsGapConfig = {
7465
+ md: 'gap-2.5',
7466
+ sm: 'gap-2',
7467
+ };
7468
+ // The buttons sit in the last column. In 'auto' that column is as wide as the
7469
+ // two buttons, so they stay on one line.
7470
+ var actionsColumnConfig = {
7471
+ auto: 'col-start-4 flex-nowrap whitespace-nowrap',
7472
+ 2: 'col-start-2 flex-wrap',
7473
+ 3: 'col-start-3 flex-wrap',
7474
+ 4: 'col-start-4 flex-wrap',
7475
+ 5: 'col-start-5 flex-wrap',
7476
+ 6: 'col-start-6 flex-wrap',
7477
+ };
7478
+
7479
+ var SIZE_UNION = ['md', 'sm'];
7480
+ var COLUMNS_UNION = ['auto', 2, 3, 4, 5, 6];
7481
+ function TableFilterPanel(_a) {
7482
+ var isOpen = _a.isOpen, onApply = _a.onApply, onReset = _a.onReset, children = _a.children, _b = _a.columns, columns = _b === void 0 ? 'auto' : _b, _c = _a.size, size = _c === void 0 ? 'md' : _c, _d = _a.applyLabel, applyLabel = _d === void 0 ? 'Apply Filter' : _d, _e = _a.resetLabel, resetLabel = _e === void 0 ? 'Reset' : _e, _f = _a.className, className = _f === void 0 ? '' : _f, rest = __rest(_a, ["isOpen", "onApply", "onReset", "children", "columns", "size", "applyLabel", "resetLabel", "className"]);
7483
+ var safeSize = validUnion(size, SIZE_UNION);
7484
+ var safeColumns = validUnion(columns, COLUMNS_UNION);
7485
+ return (React.createElement("div", __assign({}, rest, { "data-state": isOpen ? 'open' : 'closed', className: "bianic-table-filter-panel grid transition-all duration-300 ease-in-out motion-reduce:transition-none ".concat(openStateConfig[isOpen ? 'open' : 'closed'], " ").concat(className) }),
7486
+ React.createElement("div", { className: "min-h-0 overflow-hidden" },
7487
+ React.createElement("div", { className: "grid items-end border-b border-bia-grey bg-bia-grey-light-80 ".concat(columnsConfig[safeColumns], " ").concat(panelSizeConfig[safeSize]) },
7488
+ children,
7489
+ React.createElement("div", { className: "flex items-end justify-start ".concat(actionsColumnConfig[safeColumns], " ").concat(actionsGapConfig[safeSize]) },
7490
+ React.createElement(Button, { variant: "default-outlined", size: safeSize, label: applyLabel, iconLeft: React.createElement(TbCheck, { size: 14, "aria-hidden": "true" }), onClick: onApply }),
7491
+ React.createElement(Button, { variant: "default-outlined", size: safeSize, label: resetLabel, iconLeft: React.createElement(TbRefresh, { size: 14, "aria-hidden": "true" }), onClick: onReset }))))));
7492
+ }
7493
+
7494
+ var TableFilterButton = React.forwardRef(function (_a, ref) {
7495
+ var isOpen = _a.isOpen, _b = _a.isActive, isActive = _b === void 0 ? false : _b, _c = _a.label, label = _c === void 0 ? 'Filter' : _c, rest = __rest(_a, ["isOpen", "isActive", "label"]);
7496
+ return (React.createElement(Tooltip, { content: label, direction: "bottom-left" },
7497
+ React.createElement(ContextualButton, __assign({ ref: ref }, rest, { icon: React.createElement(TbFilter, { size: 18, "aria-hidden": "true" }), isSelected: isOpen, isNotified: isActive, "aria-expanded": isOpen, "aria-label": isActive ? "".concat(label, " (active)") : label }))));
7498
+ });
7499
+ TableFilterButton.displayName = 'TableFilterButton';
7500
+
6546
7501
  var colorConfigs = {
6547
7502
  default: 'bg-bia-black',
6548
7503
  info: 'bg-bia-teal',
@@ -10645,6 +11600,8 @@ exports.TabMenu = TabMenu;
10645
11600
  exports.Table = Table;
10646
11601
  exports.TableBody = TableBody;
10647
11602
  exports.TableCell = TableCell;
11603
+ exports.TableFilterButton = TableFilterButton;
11604
+ exports.TableFilterPanel = TableFilterPanel;
10648
11605
  exports.TableFooterController = TableFooterController;
10649
11606
  exports.TableHead = TableHead;
10650
11607
  exports.TableHeaderController = TableHeaderController;