@itwin/itwinui-react 3.15.3 → 3.15.5

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 (81) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +85 -65
  3. package/DEV-cjs/core/ButtonGroup/ButtonGroup.js +32 -27
  4. package/DEV-cjs/core/ComboBox/ComboBox.js +9 -6
  5. package/DEV-cjs/core/DatePicker/DatePicker.js +14 -4
  6. package/DEV-cjs/core/Popover/Popover.js +44 -16
  7. package/DEV-cjs/core/Select/SelectTagContainer.js +27 -13
  8. package/DEV-cjs/core/Table/ColumnHeader.js +21 -28
  9. package/DEV-cjs/core/Table/Table.js +78 -53
  10. package/DEV-cjs/core/Table/TablePaginator.js +111 -88
  11. package/DEV-cjs/core/Table/cells/DefaultCell.js +3 -3
  12. package/DEV-cjs/core/Table/utils.js +3 -3
  13. package/DEV-cjs/styles.js +1 -1
  14. package/DEV-cjs/utils/components/MiddleTextTruncation.js +19 -14
  15. package/DEV-cjs/utils/components/OverflowContainer.js +63 -0
  16. package/DEV-cjs/utils/components/index.js +1 -0
  17. package/DEV-cjs/utils/hooks/useOverflow.js +12 -8
  18. package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +86 -67
  19. package/DEV-esm/core/ButtonGroup/ButtonGroup.js +33 -28
  20. package/DEV-esm/core/ComboBox/ComboBox.js +9 -6
  21. package/DEV-esm/core/DatePicker/DatePicker.js +12 -4
  22. package/DEV-esm/core/Popover/Popover.js +45 -17
  23. package/DEV-esm/core/Select/SelectTagContainer.js +24 -13
  24. package/DEV-esm/core/Table/ColumnHeader.js +28 -29
  25. package/DEV-esm/core/Table/Table.js +79 -54
  26. package/DEV-esm/core/Table/TablePaginator.js +112 -89
  27. package/DEV-esm/core/Table/cells/DefaultCell.js +4 -4
  28. package/DEV-esm/core/Table/utils.js +1 -1
  29. package/DEV-esm/styles.js +1 -1
  30. package/DEV-esm/utils/components/MiddleTextTruncation.js +19 -14
  31. package/DEV-esm/utils/components/OverflowContainer.js +50 -0
  32. package/DEV-esm/utils/components/index.js +1 -0
  33. package/DEV-esm/utils/hooks/useOverflow.js +8 -8
  34. package/cjs/core/Breadcrumbs/Breadcrumbs.js +84 -64
  35. package/cjs/core/ButtonGroup/ButtonGroup.js +32 -27
  36. package/cjs/core/ComboBox/ComboBox.js +9 -6
  37. package/cjs/core/DatePicker/DatePicker.js +14 -4
  38. package/cjs/core/NonIdealState/NonIdealState.d.ts +15 -11
  39. package/cjs/core/Popover/Popover.d.ts +10 -0
  40. package/cjs/core/Popover/Popover.js +44 -16
  41. package/cjs/core/Select/SelectTagContainer.js +27 -13
  42. package/cjs/core/Table/ColumnHeader.d.ts +8 -12
  43. package/cjs/core/Table/ColumnHeader.js +21 -28
  44. package/cjs/core/Table/Table.js +74 -53
  45. package/cjs/core/Table/TablePaginator.js +111 -88
  46. package/cjs/core/Table/cells/DefaultCell.js +3 -3
  47. package/cjs/core/Table/utils.d.ts +2 -2
  48. package/cjs/core/Table/utils.js +3 -3
  49. package/cjs/styles.js +1 -1
  50. package/cjs/utils/components/MiddleTextTruncation.js +19 -14
  51. package/cjs/utils/components/OverflowContainer.d.ts +37 -0
  52. package/cjs/utils/components/OverflowContainer.js +62 -0
  53. package/cjs/utils/components/index.d.ts +1 -0
  54. package/cjs/utils/components/index.js +1 -0
  55. package/cjs/utils/hooks/useOverflow.d.ts +2 -3
  56. package/cjs/utils/hooks/useOverflow.js +12 -8
  57. package/esm/core/Breadcrumbs/Breadcrumbs.js +85 -66
  58. package/esm/core/ButtonGroup/ButtonGroup.js +33 -28
  59. package/esm/core/ComboBox/ComboBox.js +9 -6
  60. package/esm/core/DatePicker/DatePicker.js +12 -4
  61. package/esm/core/NonIdealState/NonIdealState.d.ts +15 -11
  62. package/esm/core/Popover/Popover.d.ts +10 -0
  63. package/esm/core/Popover/Popover.js +45 -17
  64. package/esm/core/Select/SelectTagContainer.js +24 -13
  65. package/esm/core/Table/ColumnHeader.d.ts +8 -12
  66. package/esm/core/Table/ColumnHeader.js +28 -29
  67. package/esm/core/Table/Table.js +75 -54
  68. package/esm/core/Table/TablePaginator.js +112 -89
  69. package/esm/core/Table/cells/DefaultCell.js +4 -4
  70. package/esm/core/Table/utils.d.ts +2 -2
  71. package/esm/core/Table/utils.js +1 -1
  72. package/esm/styles.js +1 -1
  73. package/esm/utils/components/MiddleTextTruncation.js +19 -14
  74. package/esm/utils/components/OverflowContainer.d.ts +37 -0
  75. package/esm/utils/components/OverflowContainer.js +49 -0
  76. package/esm/utils/components/index.d.ts +1 -0
  77. package/esm/utils/components/index.js +1 -0
  78. package/esm/utils/hooks/useOverflow.d.ts +2 -3
  79. package/esm/utils/hooks/useOverflow.js +8 -8
  80. package/package.json +1 -1
  81. package/styles.css +8 -8
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import type { PolymorphicForwardRefComponent } from '../props.js';
3
+ type OverflowContainerProps = {
4
+ /**
5
+ * The orientation of the overflow in container.
6
+ * @default 'horizontal'
7
+ */
8
+ overflowOrientation?: 'horizontal' | 'vertical';
9
+ /**
10
+ * Count of the *original* items (i.e. when sufficient space is available).
11
+ */
12
+ itemsCount: number;
13
+ };
14
+ type OverflowContainerOverflowNodeProps = {
15
+ children: React.ReactNode;
16
+ };
17
+ /**
18
+ * Wrapper over `useOverflow`.
19
+ *
20
+ * - Use `OverflowContainer.useContext()` to get overflow related properties.
21
+ * - Wrap overflow content in `OverflowContainer.OverflowNode` to conditionally render it when overflowing.
22
+ */
23
+ export declare const OverflowContainer: PolymorphicForwardRefComponent<"div", OverflowContainerProps> & {
24
+ /**
25
+ * Wrap overflow content in this component to conditionally render it when overflowing.
26
+ */
27
+ OverflowNode: (props: OverflowContainerOverflowNodeProps) => React.ReactNode;
28
+ /**
29
+ * Get overflow related properties of the nearest `OverflowContainer` ancestor.
30
+ */
31
+ useContext: typeof useOverflowContainerContext;
32
+ };
33
+ declare function useOverflowContainerContext(): {
34
+ visibleCount: number;
35
+ itemsCount: number;
36
+ };
37
+ export {};
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {
3
+ value: true,
4
+ });
5
+ Object.defineProperty(exports, 'OverflowContainer', {
6
+ enumerable: true,
7
+ get: function () {
8
+ return OverflowContainer;
9
+ },
10
+ });
11
+ const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
12
+ const _react = _interop_require_default._(require('react'));
13
+ const _useMergedRefs = require('../hooks/useMergedRefs.js');
14
+ const _Box = require('./Box.js');
15
+ const _useOverflow = require('../hooks/useOverflow.js');
16
+ const _useSafeContext = require('../hooks/useSafeContext.js');
17
+ const OverflowContainerComponent = _react.default.forwardRef((props, ref) => {
18
+ let { itemsCount, children, overflowOrientation, ...rest } = props;
19
+ let [containerRef, visibleCount] = (0, _useOverflow.useOverflow)(
20
+ itemsCount,
21
+ false,
22
+ overflowOrientation,
23
+ );
24
+ let overflowContainerContextValue = _react.default.useMemo(
25
+ () => ({
26
+ visibleCount,
27
+ itemsCount,
28
+ }),
29
+ [itemsCount, visibleCount],
30
+ );
31
+ return _react.default.createElement(
32
+ OverflowContainerContext.Provider,
33
+ {
34
+ value: overflowContainerContextValue,
35
+ },
36
+ _react.default.createElement(
37
+ _Box.Box,
38
+ {
39
+ ref: (0, _useMergedRefs.useMergedRefs)(ref, containerRef),
40
+ ...rest,
41
+ },
42
+ children,
43
+ ),
44
+ );
45
+ });
46
+ const OverflowContainerOverflowNode = (props) => {
47
+ let { children } = props;
48
+ let { visibleCount, itemsCount } = useOverflowContainerContext();
49
+ let isOverflowing = visibleCount < itemsCount;
50
+ return isOverflowing ? children : null;
51
+ };
52
+ const OverflowContainer = Object.assign(OverflowContainerComponent, {
53
+ OverflowNode: OverflowContainerOverflowNode,
54
+ useContext: useOverflowContainerContext,
55
+ });
56
+ const OverflowContainerContext = _react.default.createContext(void 0);
57
+ function useOverflowContainerContext() {
58
+ let overflowContainerContext = (0, _useSafeContext.useSafeContext)(
59
+ OverflowContainerContext,
60
+ );
61
+ return overflowContainerContext;
62
+ }
@@ -12,3 +12,4 @@ export * from './Portal.js';
12
12
  export * from './ShadowRoot.js';
13
13
  export * from './LineClamp.js';
14
14
  export * from './FieldsetBase.js';
15
+ export * from './OverflowContainer.js';
@@ -17,3 +17,4 @@ _export_star._(require('./Portal.js'), exports);
17
17
  _export_star._(require('./ShadowRoot.js'), exports);
18
18
  _export_star._(require('./LineClamp.js'), exports);
19
19
  _export_star._(require('./FieldsetBase.js'), exports);
20
+ _export_star._(require('./OverflowContainer.js'), exports);
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  /**
3
2
  * Hook that observes the size of an element and returns the number of items
4
3
  * that should be visible based on the size of the container element.
@@ -6,7 +5,7 @@ import * as React from 'react';
6
5
  * The returned number should be used to render the element with fewer items.
7
6
  *
8
7
  * @private
9
- * @param items Items that this element contains.
8
+ * @param itemsCount Number of items that this element contains.
10
9
  * @param disabled Set to true to disconnect the observer.
11
10
  * @param dimension 'horizontal' (default) or 'vertical'
12
11
  * @returns [callback ref to set on container, stateful count of visible items]
@@ -21,4 +20,4 @@ import * as React from 'react';
21
20
  * </div>
22
21
  * );
23
22
  */
24
- export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: "horizontal" | "vertical") => readonly [(instance: T | null | undefined) => void, number];
23
+ export declare const useOverflow: <T extends HTMLElement>(itemsCount: number, disabled?: boolean, orientation?: "horizontal" | "vertical") => readonly [(instance: T | null | undefined) => void, number];
@@ -14,10 +14,14 @@ const _useMergedRefs = require('./useMergedRefs.js');
14
14
  const _useResizeObserver = require('./useResizeObserver.js');
15
15
  const _useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect.js');
16
16
  const STARTING_MAX_ITEMS_COUNT = 20;
17
- const useOverflow = (items, disabled = false, orientation = 'horizontal') => {
17
+ const useOverflow = (
18
+ itemsCount,
19
+ disabled = false,
20
+ orientation = 'horizontal',
21
+ ) => {
18
22
  let containerRef = _react.useRef(null);
19
23
  let [visibleCount, setVisibleCount] = _react.useState(() =>
20
- disabled ? items.length : Math.min(items.length, STARTING_MAX_ITEMS_COUNT),
24
+ disabled ? itemsCount : Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT),
21
25
  );
22
26
  let needsFullRerender = _react.useRef(true);
23
27
  let [containerSize, setContainerSize] = _react.useState(0);
@@ -32,12 +36,12 @@ const useOverflow = (items, disabled = false, orientation = 'horizontal') => {
32
36
  );
33
37
  let resizeObserverRef = _react.useRef(observer);
34
38
  (0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
35
- if (disabled) setVisibleCount(items.length);
39
+ if (disabled) setVisibleCount(itemsCount);
36
40
  else {
37
- setVisibleCount(Math.min(items.length, STARTING_MAX_ITEMS_COUNT));
41
+ setVisibleCount(Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT));
38
42
  needsFullRerender.current = true;
39
43
  }
40
- }, [containerSize, disabled, items]);
44
+ }, [containerSize, disabled, itemsCount]);
41
45
  let mergedRefs = (0, _useMergedRefs.useMergedRefs)(containerRef, resizeRef);
42
46
  (0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
43
47
  if (!containerRef.current || disabled) {
@@ -57,14 +61,14 @@ const useOverflow = (items, disabled = false, orientation = 'horizontal') => {
57
61
  0,
58
62
  );
59
63
  let currentVisibleCount =
60
- visibleCount || Math.min(items.length, STARTING_MAX_ITEMS_COUNT);
64
+ visibleCount || Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT);
61
65
  let avgItemSize = childrenSize / currentVisibleCount;
62
66
  let visibleItems = Math.floor(availableSize / avgItemSize);
63
67
  if (!isNaN(visibleItems))
64
- setVisibleCount(Math.min(items.length, 2 * visibleItems));
68
+ setVisibleCount(Math.min(itemsCount, 2 * visibleItems));
65
69
  }
66
70
  needsFullRerender.current = false;
67
- }, [containerSize, visibleCount, disabled, items.length, orientation]);
71
+ }, [containerSize, visibleCount, disabled, itemsCount, orientation]);
68
72
  (0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
69
73
  previousContainerSize.current = containerSize;
70
74
  }, [containerSize]);
@@ -1,104 +1,123 @@
1
1
  import * as React from 'react';
2
2
  import cx from 'classnames';
3
3
  import {
4
- useMergedRefs,
5
- useOverflow,
6
4
  SvgChevronRight,
7
5
  Box,
6
+ OverflowContainer,
8
7
  useWarningLogger,
9
8
  } from '../../utils/index.js';
10
9
  import { Button } from '../Buttons/Button.js';
11
10
  import { Anchor } from '../Typography/Anchor.js';
12
11
  let BreadcrumbsComponent = React.forwardRef((props, ref) => {
13
12
  let {
14
- children: items,
15
- currentIndex = items.length - 1,
13
+ children: childrenProp,
14
+ currentIndex = React.Children.count(childrenProp) - 1,
16
15
  separator,
17
16
  overflowButton,
18
17
  className,
19
18
  ...rest
20
19
  } = props;
21
- let [overflowRef, visibleCount] = useOverflow(items);
22
- let refs = useMergedRefs(overflowRef, ref);
20
+ let items = React.useMemo(
21
+ () => React.Children.toArray(childrenProp),
22
+ [childrenProp],
23
+ );
23
24
  return React.createElement(
24
25
  Box,
25
26
  {
26
27
  as: 'nav',
27
28
  className: cx('iui-breadcrumbs', className),
28
- ref: refs,
29
+ ref: ref,
29
30
  'aria-label': 'Breadcrumb',
30
31
  ...rest,
31
32
  },
32
33
  React.createElement(
33
- Box,
34
+ OverflowContainer,
34
35
  {
35
36
  as: 'ol',
37
+ itemsCount: items.length,
36
38
  className: 'iui-breadcrumbs-list',
37
39
  },
38
- visibleCount > 1 &&
40
+ React.createElement(
41
+ BreadcrumbContent,
42
+ {
43
+ currentIndex: currentIndex,
44
+ overflowButton: overflowButton,
45
+ separator: separator,
46
+ },
47
+ items,
48
+ ),
49
+ ),
50
+ );
51
+ });
52
+ let BreadcrumbContent = (props) => {
53
+ let { children: items, currentIndex, overflowButton, separator } = props;
54
+ let { visibleCount } = OverflowContainer.useContext();
55
+ return React.createElement(
56
+ React.Fragment,
57
+ null,
58
+ visibleCount > 1 &&
59
+ React.createElement(
60
+ React.Fragment,
61
+ null,
62
+ React.createElement(ListItem, {
63
+ item: items[0],
64
+ isActive: 0 === currentIndex,
65
+ }),
66
+ React.createElement(Separator, {
67
+ separator: separator,
68
+ }),
69
+ ),
70
+ items.length - visibleCount > 0 &&
71
+ React.createElement(
72
+ React.Fragment,
73
+ null,
39
74
  React.createElement(
40
- React.Fragment,
41
- null,
42
- React.createElement(ListItem, {
43
- item: items[0],
44
- isActive: 0 === currentIndex,
45
- }),
46
- React.createElement(Separator, {
47
- separator: separator,
48
- }),
75
+ Box,
76
+ {
77
+ as: 'li',
78
+ className: 'iui-breadcrumbs-item',
79
+ },
80
+ overflowButton
81
+ ? overflowButton(visibleCount)
82
+ : React.createElement(
83
+ Box,
84
+ {
85
+ as: 'span',
86
+ className: 'iui-breadcrumbs-content',
87
+ },
88
+ '…',
89
+ ),
49
90
  ),
50
- items.length - visibleCount > 0 &&
51
- React.createElement(
91
+ React.createElement(Separator, {
92
+ separator: separator,
93
+ }),
94
+ ),
95
+ items
96
+ .slice(
97
+ visibleCount > 1 ? items.length - visibleCount + 1 : items.length - 1,
98
+ )
99
+ .map((_, _index) => {
100
+ let index =
101
+ visibleCount > 1
102
+ ? 1 + (items.length - visibleCount) + _index
103
+ : items.length - 1;
104
+ return React.createElement(
52
105
  React.Fragment,
53
- null,
54
- React.createElement(
55
- Box,
56
- {
57
- as: 'li',
58
- className: 'iui-breadcrumbs-item',
59
- },
60
- overflowButton
61
- ? overflowButton(visibleCount)
62
- : React.createElement(
63
- Box,
64
- {
65
- as: 'span',
66
- className: 'iui-breadcrumbs-content',
67
- },
68
- '…',
69
- ),
70
- ),
71
- React.createElement(Separator, {
72
- separator: separator,
106
+ {
107
+ key: index,
108
+ },
109
+ React.createElement(ListItem, {
110
+ item: items[index],
111
+ isActive: currentIndex === index,
73
112
  }),
74
- ),
75
- items
76
- .slice(
77
- visibleCount > 1 ? items.length - visibleCount + 1 : items.length - 1,
78
- )
79
- .map((_, _index) => {
80
- let index =
81
- visibleCount > 1
82
- ? 1 + (items.length - visibleCount) + _index
83
- : items.length - 1;
84
- return React.createElement(
85
- React.Fragment,
86
- {
87
- key: index,
88
- },
89
- React.createElement(ListItem, {
90
- item: items[index],
91
- isActive: currentIndex === index,
113
+ index < items.length - 1 &&
114
+ React.createElement(Separator, {
115
+ separator: separator,
92
116
  }),
93
- index < items.length - 1 &&
94
- React.createElement(Separator, {
95
- separator: separator,
96
- }),
97
- );
98
- }),
99
- ),
117
+ );
118
+ }),
100
119
  );
101
- });
120
+ };
102
121
  let ListItem = ({ item, isActive }) => {
103
122
  let children = item;
104
123
  let logWarning = useWarningLogger();
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import cx from 'classnames';
3
- import { useOverflow, useMergedRefs, Box } from '../../utils/index.js';
3
+ import { Box, OverflowContainer } from '../../utils/index.js';
4
4
  import {
5
5
  Composite,
6
6
  CompositeItem,
@@ -91,14 +91,12 @@ let OverflowGroup = React.forwardRef((props, forwardedRef) => {
91
91
  () => React.Children.toArray(childrenProp).filter(Boolean),
92
92
  [childrenProp],
93
93
  );
94
- let [overflowRef, visibleCount] = useOverflow(
95
- items,
96
- !overflowButton,
97
- orientation,
98
- );
99
94
  return React.createElement(
100
- BaseGroup,
95
+ OverflowContainer,
101
96
  {
97
+ as: BaseGroup,
98
+ itemsCount: items.length,
99
+ overflowOrientation: orientation,
102
100
  orientation: orientation,
103
101
  ...rest,
104
102
  className: cx(
@@ -108,27 +106,34 @@ let OverflowGroup = React.forwardRef((props, forwardedRef) => {
108
106
  },
109
107
  props.className,
110
108
  ),
111
- ref: useMergedRefs(forwardedRef, overflowRef),
109
+ ref: forwardedRef,
112
110
  },
113
- (() => {
114
- if (!(visibleCount < items.length)) return items;
115
- let overflowStart =
116
- 'start' === overflowPlacement
117
- ? items.length - visibleCount
118
- : visibleCount - 1;
119
- return React.createElement(
120
- React.Fragment,
121
- null,
122
- overflowButton &&
123
- 'start' === overflowPlacement &&
124
- overflowButton(overflowStart),
125
- 'start' === overflowPlacement
126
- ? items.slice(overflowStart + 1)
127
- : items.slice(0, Math.max(0, overflowStart)),
128
- overflowButton &&
129
- 'end' === overflowPlacement &&
130
- overflowButton(overflowStart),
131
- );
132
- })(),
111
+ React.createElement(OverflowGroupContent, {
112
+ overflowButton: overflowButton,
113
+ overflowPlacement: overflowPlacement,
114
+ items: items,
115
+ }),
133
116
  );
134
117
  });
118
+ let OverflowGroupContent = (props) => {
119
+ let { overflowButton, overflowPlacement, items } = props;
120
+ let { visibleCount } = OverflowContainer.useContext();
121
+ let overflowStart =
122
+ 'start' === overflowPlacement
123
+ ? items.length - visibleCount
124
+ : visibleCount - 1;
125
+ if (!(visibleCount < items.length)) return items;
126
+ return React.createElement(
127
+ React.Fragment,
128
+ null,
129
+ overflowButton &&
130
+ 'start' === overflowPlacement &&
131
+ overflowButton(overflowStart),
132
+ 'start' === overflowPlacement
133
+ ? items.slice(overflowStart + 1)
134
+ : items.slice(0, Math.max(0, overflowStart)),
135
+ overflowButton &&
136
+ 'end' === overflowPlacement &&
137
+ overflowButton(overflowStart),
138
+ );
139
+ };
@@ -113,12 +113,14 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
113
113
  setFocusedIndex(selectedIndexes ?? -1);
114
114
  } else {
115
115
  setFocusedIndex(-1);
116
- if (!isMultipleEnabled(selectedIndexes, multiple))
117
- setInputValue(
118
- selectedIndexes >= 0
119
- ? optionsRef.current[selectedIndexes]?.label ?? ''
120
- : '',
121
- );
116
+ isMultipleEnabled(selectedIndexes, multiple)
117
+ ? setInputValue('')
118
+ : setInputValue(
119
+ selectedIndexes >= 0
120
+ ? optionsRef.current[selectedIndexes]?.label ?? ''
121
+ : '',
122
+ );
123
+ setIsInputDirty(false);
122
124
  }
123
125
  }, [isOpen, multiple, optionsRef, selectedIndexes]);
124
126
  let previousOptions = React.useRef(options);
@@ -216,6 +218,7 @@ export const ComboBox = React.forwardRef((props, forwardedRef) => {
216
218
  .filter(Boolean)
217
219
  .join(', '),
218
220
  );
221
+ setInputValue('');
219
222
  } else {
220
223
  setSelectedIndexes(__originalIndex);
221
224
  hide();
@@ -11,6 +11,7 @@ import {
11
11
  } from '../../utils/index.js';
12
12
  import { IconButton } from '../Buttons/IconButton.js';
13
13
  import { TimePicker } from '../TimePicker/TimePicker.js';
14
+ import { PopoverInitialFocusContext } from '../Popover/Popover.js';
14
15
  let isSameDay = (a, b) =>
15
16
  a &&
16
17
  b &&
@@ -175,6 +176,11 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
175
176
  currentDate.getFullYear(),
176
177
  );
177
178
  }, [date, setMonthAndYear, startDate, endDate, enableRangeSelect]);
179
+ let popoverInitialFocusContext = React.useContext(PopoverInitialFocusContext);
180
+ React.useLayoutEffect(() => {
181
+ if (setFocus && popoverInitialFocusContext)
182
+ popoverInitialFocusContext.setInitialFocus(-1);
183
+ }, [popoverInitialFocusContext, setFocus]);
178
184
  let days = React.useMemo(() => {
179
185
  let offsetToFirst = new Date(
180
186
  displayedYear,
@@ -499,10 +505,12 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
499
505
  role: 'option',
500
506
  tabIndex: isSameDay(weekDay, focusedDay) ? 0 : -1,
501
507
  'aria-disabled': isDisabled ? 'true' : void 0,
502
- ref: (element) =>
503
- isSameDay(weekDay, focusedDay) &&
504
- needFocus.current &&
505
- element?.focus(),
508
+ ref: (element) => {
509
+ if (isSameDay(weekDay, focusedDay) && needFocus.current)
510
+ setTimeout(() => {
511
+ element?.focus();
512
+ });
513
+ },
506
514
  ...dayProps,
507
515
  className: cx(getDayClass(weekDay), dayProps?.className),
508
516
  },
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
3
3
  type NonIdealStateProps = {
4
4
  /**
5
- * An svg component, preferably from @itwin/itwinui-illustrations-react.
5
+ * An svg component, preferably from `@itwin/itwinui-illustrations-react`.
6
6
  *
7
7
  * @example
8
8
  * import { Svg404 } from '@itwin/itwinui-illustrations-react';
@@ -10,13 +10,17 @@ type NonIdealStateProps = {
10
10
  */
11
11
  svg: React.ReactNode;
12
12
  /**
13
- * Primary heading for the error page
13
+ * Primary heading for the `NonIdealState`
14
14
  */
15
15
  heading?: React.ReactNode;
16
16
  /**
17
17
  * Secondary text to explain the error
18
18
  * Can include html in order to provide a hyperlink
19
- * E.g. `Please visit <a href="https://www.bentley.com/help">our support page</a> for help.`
19
+ *
20
+ * @example
21
+ * <>
22
+ * Please visit <Anchor href="https://www.bentley.com/help">our support page</Anchor> for help.
23
+ * </>
20
24
  */
21
25
  description?: React.ReactNode;
22
26
  /**
@@ -24,13 +28,13 @@ type NonIdealStateProps = {
24
28
  * Typically should be a primary and secondary button.
25
29
  *
26
30
  * @example
27
- * <ErrorPage
28
- * actions={
29
- * <>
30
- * <Button styleType={'high-visibility'}>Retry</Button>
31
- * <Button>Contact us</Button>
32
- * </>
33
- * }
31
+ * <NonIdealState
32
+ * actions={
33
+ * <>
34
+ * <Button styleType={'high-visibility'}>Retry</Button>
35
+ * <Button>Contact us</Button>
36
+ * </>
37
+ * }
34
38
  * />
35
39
  */
36
40
  actions?: React.ReactNode;
@@ -53,7 +57,7 @@ type NonIdealStateProps = {
53
57
  };
54
58
  /**
55
59
  * A stylized display to communicate common http errors and other non-ideal states.
56
- * Works well with svgs from @itwin/itwinui-illustrations-react.
60
+ * Works well with svgs from `@itwin/itwinui-illustrations-react`.
57
61
  *
58
62
  * @example
59
63
  * <NonIdealState svg={<Svg404 />} heading='Not found' />
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { FloatingFocusManager } from '@floating-ui/react';
2
3
  import type { Placement, UseFloatingOptions, UseHoverProps, UseClickProps, UseFocusProps, UseDismissProps } from '@floating-ui/react';
3
4
  import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
4
5
  import type { PortalProps } from '../../utils/components/Portal.js';
@@ -97,8 +98,17 @@ type PopoverInternalProps = {
97
98
  */
98
99
  matchWidth?: boolean;
99
100
  } & Omit<UseFloatingOptions, 'middleware' | 'placement'>;
101
+ type InitialFocus = React.ComponentPropsWithoutRef<typeof FloatingFocusManager>['initialFocus'];
100
102
  /** Stores the current open/closed state of the popover. */
101
103
  export declare const PopoverOpenContext: React.Context<boolean | undefined>;
104
+ /**
105
+ * Stores the initialFocus of the popover.
106
+ *
107
+ * E.g. Popover's descendants can disable the popover's initialFocus to prevent conflicts with its own focus management.
108
+ */
109
+ export declare const PopoverInitialFocusContext: React.Context<{
110
+ setInitialFocus: React.Dispatch<React.SetStateAction<InitialFocus>>;
111
+ } | undefined>;
102
112
  export declare const usePopover: (options: PopoverOptions & PopoverInternalProps) => {
103
113
  placement: Placement;
104
114
  strategy: import("@floating-ui/utils").Strategy;