@moneyforward/mfui-components 4.3.1 → 4.6.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 (108) hide show
  1. package/dist/src/Accordion/Accordion.d.ts +21 -1
  2. package/dist/src/Accordion/Accordion.js +28 -4
  3. package/dist/src/Accordion/Accordion.types.d.ts +21 -0
  4. package/dist/src/Badge/Badge.d.ts +1 -1
  5. package/dist/src/Badge/Badge.js +4 -4
  6. package/dist/src/Badge/Badge.types.d.ts +3 -1
  7. package/dist/src/Breadcrumbs/Breadcrumbs.js +1 -1
  8. package/dist/src/Checkbox/Checkbox.js +7 -3
  9. package/dist/src/CheckboxCard/CheckboxCard.js +3 -1
  10. package/dist/src/DataTable/DataTable.js +9 -2
  11. package/dist/src/DataTable/DataTable.types.d.ts +17 -2
  12. package/dist/src/DataTable/DataTableCell/DataTableCell.js +21 -4
  13. package/dist/src/DataTable/DataTableCell/DataTableCell.types.d.ts +1 -1
  14. package/dist/src/DataTable/DataTableHeaderRow/DataTableHeaderRow.js +9 -5
  15. package/dist/src/DataTable/DataTableHeaderRow/DataTableHeaderRow.types.d.ts +19 -1
  16. package/dist/src/DataTable/DataTableRow/DataTableRow.js +106 -31
  17. package/dist/src/DataTable/DataTableRow/DataTableRow.types.d.ts +63 -12
  18. package/dist/src/DataTable/DataTableRowActionContext.d.ts +34 -0
  19. package/dist/src/DataTable/DataTableRowActionContext.js +8 -0
  20. package/dist/src/DateTimeSelection/DatePicker/DatePickerCalendar/DatePickerCalendar.js +7 -3
  21. package/dist/src/DateTimeSelection/DatePicker/DatePickerDateCell/index.d.ts +1 -1
  22. package/dist/src/DateTimeSelection/DatePicker/DatePickerDateCell/index.js +0 -1
  23. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerPopover/DateRangePickerCalendar/DateRangePickerCalendar.js +1 -1
  24. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerPopover/utilities/createDateRangePickerPopoverTestUtility.js +2 -2
  25. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerProvider/DateRangePickerProvider.js +13 -7
  26. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerTrigger/DateRangePickerTrigger.js +1 -1
  27. package/dist/src/DateTimeSelection/FilterDatePicker/FilterDatePicker.js +1 -1
  28. package/dist/src/DateTimeSelection/FilterMonthPicker/FilterMonthPicker.js +1 -1
  29. package/dist/src/DateTimeSelection/FilterMonthRangePicker/FilterMonthRangePicker.js +1 -1
  30. package/dist/src/DateTimeSelection/MonthPicker/MonthPickerPanel/MonthPickerPanel.js +1 -1
  31. package/dist/src/DateTimeSelection/MonthPicker/constants.d.ts +2 -2
  32. package/dist/src/DateTimeSelection/MonthPicker/constants.js +6 -6
  33. package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePickerMonthCell/MonthRangePickerMonthCell.js +1 -1
  34. package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePickerNavigation/MonthRangePickerNavigation.js +2 -2
  35. package/dist/src/DateTimeSelection/TimePicker/TimePicker.js +1 -1
  36. package/dist/src/DateTimeSelection/shared/BasePicker/constants.d.ts +2 -2
  37. package/dist/src/DateTimeSelection/shared/BasePicker/constants.js +10 -10
  38. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerPopover/BaseRangePickerCalendar/BaseRangePickerCalendar.js +1 -1
  39. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerPopover/constants.js +4 -4
  40. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerProvider/BaseRangePickerProvider.js +13 -7
  41. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerTrigger/BaseRangePickerTrigger.js +2 -2
  42. package/dist/src/DateTimeSelection/shared/CalendarGrid/CalendarGrid.js +2 -4
  43. package/dist/src/DateTimeSelection/shared/utilities/japaneseCalendar.js +2 -2
  44. package/dist/src/Dialog/Dialog.d.ts +1 -1
  45. package/dist/src/Dialog/Dialog.types.d.ts +1 -1
  46. package/dist/src/FileDropZone/FileDropZone.js +1 -1
  47. package/dist/src/FileDropZone/utils/fileHelpers.js +1 -1
  48. package/dist/src/MainNavigation/BaseMainNavigation.d.ts +1 -1
  49. package/dist/src/MainNavigation/BaseMainNavigation.js +3 -3
  50. package/dist/src/MainNavigation/MainNavigation.js +2 -1
  51. package/dist/src/MainNavigation/MainNavigation.types.d.ts +9 -0
  52. package/dist/src/MainNavigation/NarrowViewportMainNavigation.js +3 -3
  53. package/dist/src/MultipleSelectBox/MultipleSelectBox.js +27 -18
  54. package/dist/src/MultipleSelectBox/MultipleSelectBoxTrigger/MultipleSelectBoxTrigger.js +1 -1
  55. package/dist/src/MultipleSelectBox/hooks/useCreateOption.js +8 -4
  56. package/dist/src/MultipleSelectBox/hooks/useInitialFocusOnOptionPanelOpen.js +1 -1
  57. package/dist/src/MultipleSelectBox/hooks/useOptionKeyboardNavigation.js +9 -4
  58. package/dist/src/MultipleSelectBox/hooks/useSelectedValues.js +16 -50
  59. package/dist/src/NavigationList/NavigationListItem/NavigationListItem.d.ts +3 -0
  60. package/dist/src/NavigationList/NavigationListItem/NavigationListItem.js +6 -2
  61. package/dist/src/NavigationList/NavigationListItem/NavigationListItem.types.d.ts +2 -1
  62. package/dist/src/NumberBox/NumberBox.d.ts +5 -0
  63. package/dist/src/NumberBox/NumberBox.js +61 -6
  64. package/dist/src/NumberBox/NumberBox.types.d.ts +35 -0
  65. package/dist/src/PageHeader/PageHeader.types.d.ts +2 -0
  66. package/dist/src/Pagination/Pagination.js +4 -1
  67. package/dist/src/Popover/Popover.js +12 -4
  68. package/dist/src/RadioButtonCard/RadioButtonCard.js +3 -1
  69. package/dist/src/SelectBox/SelectBox.js +29 -21
  70. package/dist/src/SelectBox/hooks/useKeyboardNavigation.js +8 -2
  71. package/dist/src/SelectBox/utils/getFlatOptions.js +1 -1
  72. package/dist/src/SidePane/SidePane.js +87 -7
  73. package/dist/src/SidePane/SidePane.types.d.ts +39 -0
  74. package/dist/src/SplitView/hooks/useSplitViewPanelVisibility.js +5 -2
  75. package/dist/src/SubNavigation/SubNavigation.d.ts +10 -1
  76. package/dist/src/SubNavigation/SubNavigation.js +93 -21
  77. package/dist/src/SubNavigation/SubNavigation.types.d.ts +45 -7
  78. package/dist/src/Tabs/Tabs.js +8 -4
  79. package/dist/src/Tabs/hooks/useCalculatedSelectedTabId.js +7 -5
  80. package/dist/src/Tabs/hooks/useTabRegistry.js +5 -5
  81. package/dist/src/Toast/ToastContainer/ToastContainer.js +11 -2
  82. package/dist/src/ToggleSwitch/index.d.ts +1 -1
  83. package/dist/src/ToggleSwitch/index.js +0 -1
  84. package/dist/src/Tooltip/Tooltip.js +8 -3
  85. package/dist/src/Tooltip/hooks/useTooltipDisplayController.js +77 -88
  86. package/dist/src/utilities/dom/containsAcrossShadowRoots.d.ts +21 -0
  87. package/dist/src/utilities/dom/containsAcrossShadowRoots.js +33 -0
  88. package/dist/src/utilities/dom/getFocusableNodes.js +1 -3
  89. package/dist/src/utilities/dom/useFixedColumns.js +6 -8
  90. package/dist/src/utilities/dom/useFocusTrap.js +1 -1
  91. package/dist/src/utilities/dom/useTableEdgeCellMarkers.d.ts +56 -0
  92. package/dist/src/utilities/dom/useTableEdgeCellMarkers.js +223 -0
  93. package/dist/src/utilities/react/flattenChildren.d.ts +15 -0
  94. package/dist/src/utilities/react/flattenChildren.js +28 -0
  95. package/dist/src/utilities/state/useLatest.d.ts +1 -1
  96. package/dist/src/utilities/state/useLatest.js +8 -2
  97. package/dist/styled-system/recipes/badge-slot-recipe.d.ts +1 -1
  98. package/dist/styled-system/recipes/badge-slot-recipe.js +4 -0
  99. package/dist/styled-system/recipes/data-table-cell-slot-recipe.d.ts +1 -1
  100. package/dist/styled-system/recipes/data-table-cell-slot-recipe.js +8 -2
  101. package/dist/styled-system/recipes/data-table-row-slot-recipe.js +13 -6
  102. package/dist/styled-system/recipes/sub-navigation-slot-recipe.d.ts +1 -1
  103. package/dist/styled-system/recipes/sub-navigation-slot-recipe.js +12 -0
  104. package/dist/styles.css +175 -39
  105. package/dist/tsconfig.build.tsbuildinfo +1 -1
  106. package/package.json +12 -12
  107. /package/dist/src/{MultipleSelectBox/utils → utilities/dom}/getDeepActiveElement.d.ts +0 -0
  108. /package/dist/src/{MultipleSelectBox/utils → utilities/dom}/getDeepActiveElement.js +0 -0
@@ -21,4 +21,39 @@ export type NumberBoxProps = Omit<TextBoxProps, 'onChange' | 'prefixSlot' | 'suf
21
21
  * @default 'right'
22
22
  */
23
23
  textAlign?: 'left' | 'right';
24
+ /**
25
+ * The maximum number of digits (`0-9`) allowed in the integer part of the value, i.e.
26
+ * before the decimal point. The minus sign, the decimal point and the grouping commas
27
+ * are not counted.
28
+ *
29
+ * This limit is independent of `decimalPlaces`, so the two stack: `maxIntegerDigits={13}`
30
+ * combined with `decimalPlaces={2}` allows up to 13 integer digits and 2 decimal digits
31
+ * (15 digits total).
32
+ *
33
+ * An edit that would exceed the limit is silently rejected: the previous value and the
34
+ * cursor position are kept and `onChange` is not called. Because nothing is announced,
35
+ * state the limit up front in an adjacent `HelpMessage` referenced by `aria-describedby`
36
+ * (WCAG 2.2 3.3.2).
37
+ *
38
+ * The limit applies to typing and pasting only. A `value` or `defaultValue` that already
39
+ * exceeds it is displayed as is, and the user can still edit it back into range.
40
+ *
41
+ * @default undefined
42
+ */
43
+ maxIntegerDigits?: number;
44
+ /**
45
+ * The maximum number of digits allowed after the decimal point.
46
+ * `0` also rejects the decimal point itself, making the field integers-only.
47
+ *
48
+ * An edit that would exceed the limit is silently rejected: the previous value and the
49
+ * cursor position are kept and `onChange` is not called. Because nothing is announced,
50
+ * state the limit up front in an adjacent `HelpMessage` referenced by `aria-describedby`
51
+ * (WCAG 2.2 3.3.2).
52
+ *
53
+ * The limit applies to typing and pasting only. A `value` or `defaultValue` that already
54
+ * exceeds it is displayed as is, and the user can still edit it back into range.
55
+ *
56
+ * @default undefined
57
+ */
58
+ decimalPlaces?: number;
24
59
  };
@@ -44,6 +44,8 @@ export type PageHeaderProps = {
44
44
  showBackButton?: boolean;
45
45
  /**
46
46
  * It's for controlling the back button.
47
+ *
48
+ * The default `aria-label` is `戻る`, but set it to `{destination}へ戻る` (e.g. `請求書一覧へ戻る`) so that users know where the button navigates to.
47
49
  */
48
50
  backButtonProps?: Omit<IconButtonProps, 'outlined' | 'children'>;
49
51
  /**
@@ -8,7 +8,10 @@ import { cx } from '../../styled-system/css';
8
8
  * The general-purpose Pagination component.
9
9
  * This component switches the looks depends on the props: showItemsCount, showPagePicker and showItemsPerPage.
10
10
  */
11
- export function Pagination({ 'aria-label': ariaLabel, currentPageNumber, totalItems, itemsPerPage, unitLabel = '件', prevButtonProps, pageSelectBoxProps, nextButtonProps, itemsPerPageProps = {}, itemsPerPageSelectBoxProps, showItemsCount = false, showPagePicker = false, showItemsPerPage = false, alignment = 'left', pageSuffixLabel = 'ページ', onPageChange, ...props }) {
11
+ export function Pagination({ 'aria-label': ariaLabel, currentPageNumber, totalItems, itemsPerPage, unitLabel = '件', prevButtonProps, pageSelectBoxProps, nextButtonProps, itemsPerPageProps = {}, itemsPerPageSelectBoxProps, showItemsCount = false, showPagePicker = false,
12
+ // No default: `showItemsPerPage` is a required discriminant in both members of the
13
+ // props union, so a default here is unreachable.
14
+ showItemsPerPage, alignment = 'left', pageSuffixLabel = 'ページ', onPageChange, ...props }) {
12
15
  const { label = '1ページの表示数', options, onChange } = itemsPerPageProps;
13
16
  const totalPages = Math.ceil(totalItems / itemsPerPage);
14
17
  const classes = paginationSlotRecipe({ alignment });
@@ -40,6 +40,15 @@ export function Popover({ renderTrigger, renderContent, open, onOpenStateChanged
40
40
  constrainToTriggerWidth: enableConstrainedContentWidth,
41
41
  enableCenteredLayoutOnNarrowViewport,
42
42
  });
43
+ // Mirrors `refs.floating.current` into state so `TargetDomNodeProvider` below can be
44
+ // given it directly, instead of reading a ref's `.current` during render (unsafe: a
45
+ // ref update never triggers the re-render needed to pass a fresh value to context
46
+ // consumers). `refs.setFloating` still runs so floating-ui keeps positioning it.
47
+ const [floatingElement, setFloatingElement] = useState(null);
48
+ const setFloatingRef = useCallback((node) => {
49
+ refs.setFloating(node);
50
+ setFloatingElement(node);
51
+ }, [refs]);
43
52
  // Fire onOpen / onClose *only* when the open state actually changes.
44
53
  // We keep a ref of the previous open state so a new toggleEvent while already
45
54
  // open does not retrigger `onOpen`, which previously caused unexpected focus
@@ -119,8 +128,7 @@ export function Popover({ renderTrigger, renderContent, open, onOpenStateChanged
119
128
  if (isInShadowDOM) {
120
129
  // In Shadow DOM: check both shadow and document active elements
121
130
  isFocusStillWithinComponent =
122
- isElementWithinComponent(shadowActiveElement) ||
123
- isElementWithinComponent(documentActiveElement);
131
+ isElementWithinComponent(shadowActiveElement) || isElementWithinComponent(documentActiveElement);
124
132
  // Special case: If shadow activeElement is null, it means focus has left the shadow DOM.
125
133
  // We should trigger onBlur unless the document activeElement is still within our component
126
134
  // (which would be the case if focus moved to the shadow host or related elements)
@@ -254,8 +262,8 @@ export function Popover({ renderTrigger, renderContent, open, onOpenStateChanged
254
262
  });
255
263
  };
256
264
  }, [isPopoverOpen, refs.reference, refs.floating]);
257
- return (_jsxs(_Fragment, { children: [renderTrigger(options), shouldRenderTheContent ? (_jsx(Portal, { targetDOMNode: targetElement, children: _jsx("div", { ref: refs.setFloating, id: contentProps.id, tabIndex: contentProps.tabIndex ?? 0, "data-mfui-content": "popover-portal-content", "data-mfui-popover-depth": nestingDepth, className: cx(classes.root, 'mfui-Popover__root', contentProps.className), style: {
265
+ return (_jsxs(_Fragment, { children: [renderTrigger(options), shouldRenderTheContent ? (_jsx(Portal, { targetDOMNode: targetElement, children: _jsx("div", { ref: setFloatingRef, id: contentProps.id, tabIndex: contentProps.tabIndex ?? 0, "data-mfui-content": "popover-portal-content", "data-mfui-popover-depth": nestingDepth, className: cx(classes.root, 'mfui-Popover__root', contentProps.className), style: {
258
266
  ...floatingStyles,
259
267
  ...(!enableAutoUnmount && !isPopoverOpen && { display: 'none' }),
260
- }, onKeyDown: handleKeyDownPopover, children: _jsx(TargetDomNodeProvider, { targetDomNode: refs.floating.current, children: _jsx(PopoverContextProvider, { children: renderContent(options) }) }) }) })) : null] }));
268
+ }, onKeyDown: handleKeyDownPopover, children: _jsx(TargetDomNodeProvider, { targetDomNode: floatingElement, children: _jsx(PopoverContextProvider, { children: renderContent(options) }) }) }) })) : null] }));
261
269
  }
@@ -28,5 +28,7 @@ export const RadioButtonCard = forwardRef(({ label, layout = 'vertical', renderD
28
28
  disableResponsive,
29
29
  isResponsive: Boolean(responsiveSlot.narrowViewport),
30
30
  });
31
- return (_jsxs("div", { className: cx(classes.root, 'mfui-RadioButtonCard__root', className), children: [_jsx(FocusIndicator, { disableNestedFocus: true, children: _jsxs(Typography, { variant: "label", className: cx(classes.inputWrapper, 'mfui-RadioButtonCard__inputWrapper'), as: "label", htmlFor: props.id, children: [_jsx(RadioButton, { ref: ref, ...props, className: cx(classes.input, 'mfui-RadioButtonCard__input') }), _jsx("span", { className: cx(classes.label, 'mfui-RadioButtonCard__label'), children: label })] }) }), responsiveSlot.narrowViewport && disableResponsive ? (_jsxs(_Fragment, { children: [_jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsWide, 'mfui-RadioButtonCard__details'), children: responsiveSlot.base(radioButtonState) }), _jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsNarrow, 'mfui-RadioButtonCard__details'), children: responsiveSlot.narrowViewport(radioButtonState) })] })) : responsiveSlot.narrowViewport ? (_jsxs(_Fragment, { children: [_jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsWide, 'mfui-RadioButtonCard__details'), children: responsiveSlot.base(radioButtonState) }), _jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsNarrow, 'mfui-RadioButtonCard__details'), children: responsiveSlot.narrowViewport(radioButtonState) })] })) : responsiveSlot.base ? (_jsx("div", { "data-mfui-content": "details", className: cx(classes.details, 'mfui-RadioButtonCard__details'), children: responsiveSlot.base(radioButtonState) })) : null] }));
31
+ return (_jsxs("div", { className: cx(classes.root, 'mfui-RadioButtonCard__root', className), children: [_jsx(FocusIndicator, { disableNestedFocus: true, children: _jsxs(Typography, { variant: "label", className: cx(classes.inputWrapper, 'mfui-RadioButtonCard__inputWrapper'), as: "label", htmlFor: props.id, children: [_jsx(RadioButton, { ref: ref, ...props, className: cx(classes.input, 'mfui-RadioButtonCard__input') }), _jsx("span", { className: cx(classes.label, 'mfui-RadioButtonCard__label'), children: label })] }) }), responsiveSlot.narrowViewport ? (_jsxs(_Fragment, { children: [_jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsWide, 'mfui-RadioButtonCard__details'), children: responsiveSlot.base(radioButtonState) }), _jsx("div", { "data-mfui-content": "details", className: cx(classes.details, classes.detailsNarrow, 'mfui-RadioButtonCard__details'), children: responsiveSlot.narrowViewport(radioButtonState) })] })) : (
32
+ /* For function-based renderDetailsSlot or ResponsiveSlot with only base, use single details element */
33
+ responsiveSlot.base && (_jsx("div", { "data-mfui-content": "details", className: cx(classes.details, 'mfui-RadioButtonCard__details'), children: responsiveSlot.base(radioButtonState) })))] }));
32
34
  });
@@ -47,7 +47,7 @@ export const SelectBox = forwardRef((props, ref) => {
47
47
  const optionPanelRef = useRef(null);
48
48
  const scrollWrapperRef = useRef(null);
49
49
  const searchInputRef = useRef(null);
50
- const [localSelectedOption, setLocalSelectedOption] = useState(() => defaultValue ?? null);
50
+ const [localSelectedOption, setLocalSelectedOption] = useState(() => value ?? defaultValue ?? null);
51
51
  const { isOpen: isOptionPanelOpen, toggle: toggleOptionPanel, close: closeOptionPanel, } = useDisclosure({
52
52
  value: false,
53
53
  onToggle: onOpenStateChanged,
@@ -63,17 +63,16 @@ export const SelectBox = forwardRef((props, ref) => {
63
63
  resetSearchText();
64
64
  }
65
65
  }, [isOptionPanelOpen, resetSearchText]);
66
- const selectedOption = useMemo(() => {
67
- if (value === undefined)
68
- return null;
69
- return value;
70
- }, [value]);
71
- useEffect(() => {
72
- // Only update when value prop is explicitly provided (controlled mode)
66
+ // Adjusted during render (React's documented pattern for resyncing state to a
67
+ // changed prop) rather than in an effect, so the UI never flashes the stale value
68
+ // for one frame. Only fires when value prop is explicitly provided (controlled mode).
69
+ const [prevValue, setPrevValue] = useState(value);
70
+ if (value !== prevValue) {
71
+ setPrevValue(value);
73
72
  if (value !== undefined) {
74
- setLocalSelectedOption(selectedOption);
73
+ setLocalSelectedOption(value);
75
74
  }
76
- }, [selectedOption, value]);
75
+ }
77
76
  useUpdateEffect(() => {
78
77
  if (value === undefined) {
79
78
  setLocalSelectedOption(null);
@@ -353,22 +352,31 @@ export const SelectBox = forwardRef((props, ref) => {
353
352
  ]);
354
353
  // Render infinite scroll loading indicator
355
354
  const renderInfiniteScrollLoading = useCallback(() => isInfiniteScrollLoading && enableInfiniteScroll ? (_jsx("div", { className: cx(classes.infiniteScrollLoading, 'mfui-SelectBox__infiniteScrollLoading'), children: _jsx(ProgressIndicator, {}) }, "infinite-scroll-loading")) : null, [isInfiniteScrollLoading, enableInfiniteScroll, classes.infiniteScrollLoading]);
355
+ // Early returns rather than a four-level ternary: the branches are mutually exclusive
356
+ // and each returns a different shape (skeletons, virtualized rows, options, or the
357
+ // empty message).
358
+ const renderListContent = () => {
359
+ if (loading) {
360
+ return Array.from({ length: SKELETON_ITEM_COUNT }).map((_, index) => (_jsx("li", { className: cx(classes.skeletonItem, 'mfui-SelectBox__skeletonItem'), children: _jsx(Skeleton, {}) }, index)));
361
+ }
362
+ if (isVirtualized && virtualItems.length > 0) {
363
+ return renderVirtualizedItems();
364
+ }
365
+ if (filteredOptions.length > 0) {
366
+ return [
367
+ ...renderNonVirtualizedItems(),
368
+ !isVirtualized && renderInfiniteScrollLoading(),
369
+ !isVirtualized && renderInfiniteScrollError(),
370
+ ].filter(Boolean);
371
+ }
372
+ return [renderEmptyMessage(), !isVirtualized && renderInfiniteScrollError()].filter(Boolean);
373
+ };
356
374
  const optionsNode = (_jsxs("div", { ref: scrollWrapperRef, className: cx(classes.scrollWrapper, 'mfui-SelectBox__scrollWrapper'), onScroll: enableInfiniteScroll ? handleInfiniteScroll : undefined, children: [_jsx("ul", { role: "listbox", id: listBoxId, className: cx(classes.listBox, 'mfui-SelectBox__listBox'), tabIndex: -1, style: isVirtualized
357
375
  ? {
358
376
  height: `${String(totalSize)}px`,
359
377
  position: 'relative',
360
378
  }
361
- : undefined, children: loading
362
- ? Array.from({ length: SKELETON_ITEM_COUNT }).map((_, index) => (_jsx("li", { className: cx(classes.skeletonItem, 'mfui-SelectBox__skeletonItem'), children: _jsx(Skeleton, {}) }, index)))
363
- : isVirtualized && virtualItems.length > 0
364
- ? renderVirtualizedItems()
365
- : filteredOptions.length > 0
366
- ? [
367
- ...renderNonVirtualizedItems(),
368
- !isVirtualized && renderInfiniteScrollLoading(),
369
- !isVirtualized && renderInfiniteScrollError(),
370
- ].filter(Boolean)
371
- : [renderEmptyMessage(), !isVirtualized && renderInfiniteScrollError()].filter(Boolean) }), isVirtualized ? renderInfiniteScrollLoading() : null, isVirtualized ? renderInfiniteScrollError('div') : null, _jsx(OptionGroupLabelDescriptions, { groups: rendersHiddenGroupLabels ? optionGroupLabels : [] })] }));
379
+ : undefined, children: renderListContent() }), isVirtualized ? renderInfiniteScrollLoading() : null, isVirtualized ? renderInfiniteScrollError('div') : null, _jsx(OptionGroupLabelDescriptions, { groups: rendersHiddenGroupLabels ? optionGroupLabels : [] })] }));
372
380
  const handleClearValue = () => {
373
381
  setLocalSelectedOption(null);
374
382
  onChange?.(null);
@@ -30,9 +30,15 @@ export function useKeyboardNavigation({ isOptionPanelOpen, loading, enableSearch
30
30
  return selectedIndex !== -1 ? selectedIndex : 0;
31
31
  }, [flatOptions, localSelectedOption]);
32
32
  const [tabbableOptionIndex, setTabbableOptionIndex] = useState(getDefaultTabbableIndex());
33
- useEffect(() => {
33
+ // Adjusted during render (React's documented pattern for resyncing state to changed
34
+ // props) rather than in an effect, so the UI never flashes the stale index for one frame.
35
+ const [prevFlatOptions, setPrevFlatOptions] = useState(flatOptions);
36
+ const [prevLocalSelectedOption, setPrevLocalSelectedOption] = useState(localSelectedOption);
37
+ if (flatOptions !== prevFlatOptions || localSelectedOption !== prevLocalSelectedOption) {
38
+ setPrevFlatOptions(flatOptions);
39
+ setPrevLocalSelectedOption(localSelectedOption);
34
40
  setTabbableOptionIndex(getDefaultTabbableIndex());
35
- }, [getDefaultTabbableIndex]);
41
+ }
36
42
  const resetTabbableIndex = useCallback(() => {
37
43
  setTabbableOptionIndex(getDefaultTabbableIndex());
38
44
  }, [getDefaultTabbableIndex]);
@@ -36,7 +36,7 @@ export function getFlatOptions(options) {
36
36
  export function escapeAttributeSelector(value) {
37
37
  const stringValue = String(value);
38
38
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
39
- if (typeof window !== 'undefined' && window.CSS && typeof window.CSS.escape === 'function') {
39
+ if (typeof window !== 'undefined' && typeof window.CSS?.escape === 'function') {
40
40
  return window.CSS.escape(stringValue);
41
41
  }
42
42
  // Polyfill for CSS.escape
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useCallback, useId, useMemo, useState } from 'react';
3
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
4
4
  import { Close, PaneExpansionToRight, PaneExpansionToLeft } from '@moneyforward/mfui-icons-react';
5
5
  import { cx } from '../../styled-system/css';
6
6
  import { Heading } from '../Heading';
@@ -8,6 +8,9 @@ import { IconButton } from '../IconButton';
8
8
  import { sidePaneSlotRecipe } from '../../styled-system/recipes';
9
9
  import { useSidePaneStateController } from './hooks/useSidePaneStateController';
10
10
  import { useFocusTrap } from '../utilities/dom/useFocusTrap';
11
+ import { getFocusableNodes } from '../utilities/dom/getFocusableNodes';
12
+ import { getDeepActiveElement } from '../utilities/dom/getDeepActiveElement';
13
+ import { containsAcrossShadowRoots } from '../utilities/dom/containsAcrossShadowRoots';
11
14
  import { compatibleForwardRef } from '../utilities/react/compatibleForwardRef';
12
15
  import { Portal, TargetDomNodeProvider, useAutomaticTargetDomNode } from '../Portal';
13
16
  import { FormFooter } from '../FormFooter';
@@ -21,7 +24,7 @@ import { FormFooter } from '../FormFooter';
21
24
  *
22
25
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
23
26
  */
24
- export const SidePane = compatibleForwardRef(({ open, title, 'aria-labelledby': ariaLabelledby, 'aria-label': ariaLabel, renderHeading, onClose, className, children, actionSlot, formFooterProps, position = 'right', enableModal = false, enableAutoUnmount = true, disableBackdropClose = false, closeButtonProps, targetDOMNode, insideProps, ...props }, ref) => {
27
+ export const SidePane = compatibleForwardRef(({ open, title, 'aria-labelledby': ariaLabelledby, 'aria-label': ariaLabel, renderHeading, onClose, className, children, actionSlot, formFooterProps, position = 'right', enableModal = false, enableAutoUnmount = true, disableBackdropClose = false, disableClose = false, closeButtonProps, targetDOMNode, insideProps, ...props }, ref) => {
25
28
  const classes = sidePaneSlotRecipe({ position, nonModal: !enableModal });
26
29
  const [insideElement, setInsideElement] = useState(null);
27
30
  const { localOpen, handleCloseSidePane, handleStopCloseSidePane, sidePaneElement, setSidePaneElement } = useSidePaneStateController({
@@ -31,21 +34,98 @@ export const SidePane = compatibleForwardRef(({ open, title, 'aria-labelledby':
31
34
  insideElement,
32
35
  });
33
36
  const handleBackdropClick = useCallback(() => {
34
- if (!disableBackdropClose) {
37
+ if (!disableClose && !disableBackdropClose) {
35
38
  handleCloseSidePane();
36
39
  }
37
- }, [disableBackdropClose, handleCloseSidePane]);
40
+ }, [disableClose, disableBackdropClose, handleCloseSidePane]);
38
41
  const handleKeyDown = useCallback((event) => {
39
42
  if (event.key === 'Escape') {
43
+ // The event is swallowed even while closing is disabled, so that ESC inside a nested
44
+ // side pane never reaches an outer one.
40
45
  event.stopPropagation();
41
46
  event.preventDefault();
42
- handleCloseSidePane();
47
+ if (!disableClose) {
48
+ handleCloseSidePane();
49
+ }
43
50
  }
44
51
  props.onKeyDown?.(event);
45
- }, [handleCloseSidePane, props]);
52
+ }, [disableClose, handleCloseSidePane, props]);
53
+ // Whether the close button currently holds focus, tracked so the recovery effect below can
54
+ // tell focus the browser kicked out from under the user apart from focus that legitimately
55
+ // sits outside a non-modal pane.
56
+ const closeButtonHasFocusRef = useRef(false);
57
+ const handleCloseButtonFocus = useCallback(() => {
58
+ closeButtonHasFocusRef.current = true;
59
+ }, []);
60
+ const handleCloseButtonBlur = useCallback((event) => {
61
+ // `event.currentTarget.disabled`, not the `disableClose` prop: React applies DOM properties
62
+ // before it refreshes the delegated-event props, so the blur the browser dispatches while
63
+ // this button is being disabled is handled with the previous render's closure, where
64
+ // `disableClose` was still false. The DOM property is already up to date at that point, so
65
+ // a blur caused by disabling keeps the flag set for the effect below to consume, while an
66
+ // ordinary blur clears it.
67
+ closeButtonHasFocusRef.current = event.currentTarget.disabled;
68
+ }, []);
69
+ // A focused element that becomes `disabled` is blurred by the browser, moving focus to
70
+ // <body> — outside the `role="dialog"` subtree that `aria-modal` and the focus trap depend
71
+ // on (see useSidePaneStateController). Pull focus back to the pane window.
72
+ // `preventScroll` is required for the same reason as the autofocus effect in that hook.
73
+ useEffect(() => {
74
+ if (!disableClose || !localOpen) {
75
+ // Closing is possible again, or the pane is gone: drop the tracked focus so that a later
76
+ // transition into `disableClose` can never consume a stale `true`. The close button is
77
+ // enabled on these runs, so its own focus/blur handlers keep the flag accurate.
78
+ closeButtonHasFocusRef.current = false;
79
+ return;
80
+ }
81
+ if (!insideElement)
82
+ return;
83
+ if (enableModal) {
84
+ // `document.activeElement` stops at the shadow host when the pane is portalled into a
85
+ // shadow root (via `targetDOMNode`), so resolve from `insideElement`'s own root instead
86
+ // and follow nested shadow roots down to the truly focused element.
87
+ const rootNode = insideElement.getRootNode();
88
+ const activeElement = getDeepActiveElement(rootNode instanceof ShadowRoot ? rootNode : insideElement.ownerDocument);
89
+ // `sidePaneElement` (the overlay root), not `insideElement`: nested overlays portal into
90
+ // the overlay root via the TargetDomNodeProvider below, so focus inside a nested Dialog,
91
+ // listbox or calendar is legitimately outside the pane window and must not be stolen.
92
+ // The containment test has to cross shadow boundaries, which `Node.contains()` does not:
93
+ // the lookup above pierces shadow roots downwards, so focus inside a web component
94
+ // rendered in the pane resolves to a node that no ancestor `contains()`.
95
+ if (containsAcrossShadowRoots(sidePaneElement, activeElement))
96
+ return;
97
+ insideElement.focus({ preventScroll: true });
98
+ return;
99
+ }
100
+ // Non-modal panes (e.g. `EmbeddedSidePane`) trap nothing and have no `aria-modal` boundary
101
+ // to keep focus within, so a blanket restore would steal focus that legitimately sits
102
+ // outside the pane. Only recover when the close button itself held focus as it was
103
+ // disabled. Tracked focus state rather than the blur event itself, because browsers are
104
+ // inconsistent about firing `blur` on the disabled-while-focused fixup (jsdom never does),
105
+ // and React dispatches it with the pre-disable props.
106
+ if (!closeButtonHasFocusRef.current)
107
+ return;
108
+ closeButtonHasFocusRef.current = false;
109
+ insideElement.focus({ preventScroll: true });
110
+ }, [disableClose, enableModal, localOpen, insideElement, sidePaneElement]);
111
+ const handlePressingTabOnNotFocusableElement = useCallback((event) => {
112
+ // When every control is disabled — `disableClose` together with a submitting FormFooter,
113
+ // for instance — the overlay holds no focusable node and the trap has nothing to wrap to.
114
+ // Keep focus on the pane window instead of letting Tab escape the `aria-modal` boundary.
115
+ // Measured over `sidePaneElement` (the overlay root), which is the same subtree the trap
116
+ // itself measures as its `currentTarget`, and the same boundary as the effect above: a
117
+ // nested Dialog, listbox or calendar portalled in there is still keyboard reachable, so
118
+ // Tab must be left alone rather than pulled back to this pane window.
119
+ // (`sidePaneElement` is the node this handler is bound to, so it is never null here.)
120
+ if (!insideElement || !sidePaneElement || getFocusableNodes(sidePaneElement).length > 0)
121
+ return;
122
+ event.preventDefault();
123
+ insideElement.focus({ preventScroll: true });
124
+ }, [insideElement, sidePaneElement]);
46
125
  // Get the focus trap handler
47
126
  const { handleOnKeyDown: focusTrapKeyHandler } = useFocusTrap({
48
127
  onKeyDown: handleKeyDown,
128
+ onPressingTabOnNotFocusableElement: handlePressingTabOnNotFocusableElement,
49
129
  });
50
130
  // Only use focus trap for modal SidePanes
51
131
  const handleOnKeyDown = enableModal ? focusTrapKeyHandler : handleKeyDown;
@@ -67,5 +147,5 @@ export const SidePane = compatibleForwardRef(({ open, title, 'aria-labelledby':
67
147
  return (_jsx(TargetDomNodeProvider, { targetDomNode: sidePaneElement, children: shouldRenderContent ? (_jsx(Portal, { targetDOMNode: targetElement, children: _jsxs("div", { ref: setSidePaneElement, ...props, className: cx(classes.root, 'mfui-SidePane__root', className), style: {
68
148
  ...props.style,
69
149
  ...(!enableAutoUnmount && !localOpen && { display: 'none' }),
70
- }, onKeyDown: handleOnKeyDown, children: [enableModal ? (_jsx("div", { "data-mfui-content": "backdrop", className: cx(classes.backdrop, 'mfui-SidePane__backdrop'), onClick: handleBackdropClick })) : null, _jsxs("div", { ref: setInsideElement, role: "dialog", "aria-modal": enableModal ? 'true' : undefined, "aria-labelledby": ariaLabelledby ?? (title ? titleId : undefined), "aria-label": ariaLabel, tabIndex: -1, "data-mfui-content": "inside", className: cx(classes.inside, 'mfui-SidePane__inside', insideProps?.className), onClick: handleStopCloseSidePane, children: [_jsxs("div", { className: cx(classes.header, 'mfui-SidePane__header'), children: [renderHeading ? (renderHeading({ headingNode })) : (_jsx("div", { className: cx(classes.title, 'mfui-SidePane__title'), children: headingNode })), _jsxs("div", { className: cx(classes.actionSlotWrapper, 'mfui-SidePane__actionSlotWrapper'), children: [!!actionSlot && (_jsx("div", { className: cx(classes.actionSlot, 'mfui-SidePane__actionSlot'), children: actionSlot })), _jsx("div", { className: cx(classes.closeButtonWrapper, 'mfui-SidePane__closeButtonWrapper'), children: _jsx(IconButton, { "aria-label": closeButtonProps?.['aria-label'] ?? '閉じる', onClick: handleCloseSidePane, children: closeButtonIcon }) })] })] }), _jsxs("div", { className: cx(classes.content, 'mfui-SidePane__content'), children: [_jsx("div", { className: cx(classes.contentBody, 'mfui-SidePane__contentBody'), children: children }), resolvedFormFooterPosition === 'stacking' ? (_jsx("div", { className: cx(classes.footer, 'mfui-SidePane__footer'), children: _jsx(FormFooter, { sectionPosition: "fill", ...formFooterProps, position: resolvedFormFooterPosition }) })) : null] }), formFooterProps && resolvedFormFooterPosition !== 'stacking' ? (_jsx("div", { className: cx(classes.footer, 'mfui-SidePane__footer'), children: _jsx(FormFooter, { sectionPosition: "fill", ...formFooterProps, position: resolvedFormFooterPosition }) })) : null] })] }) })) : null }));
150
+ }, onKeyDown: handleOnKeyDown, children: [enableModal ? (_jsx("div", { "data-mfui-content": "backdrop", className: cx(classes.backdrop, 'mfui-SidePane__backdrop'), onClick: handleBackdropClick })) : null, _jsxs("div", { ref: setInsideElement, role: "dialog", "aria-modal": enableModal ? 'true' : undefined, "aria-labelledby": ariaLabelledby ?? (title ? titleId : undefined), "aria-label": ariaLabel, tabIndex: -1, "data-mfui-content": "inside", className: cx(classes.inside, 'mfui-SidePane__inside', insideProps?.className), onClick: handleStopCloseSidePane, children: [_jsxs("div", { className: cx(classes.header, 'mfui-SidePane__header'), children: [renderHeading ? (renderHeading({ headingNode })) : (_jsx("div", { className: cx(classes.title, 'mfui-SidePane__title'), children: headingNode })), _jsxs("div", { className: cx(classes.actionSlotWrapper, 'mfui-SidePane__actionSlotWrapper'), children: [!!actionSlot && (_jsx("div", { className: cx(classes.actionSlot, 'mfui-SidePane__actionSlot'), children: actionSlot })), _jsx("div", { className: cx(classes.closeButtonWrapper, 'mfui-SidePane__closeButtonWrapper'), children: _jsx(IconButton, { "aria-label": closeButtonProps?.['aria-label'] ?? '閉じる', disabled: disableClose, onClick: handleCloseSidePane, onFocus: handleCloseButtonFocus, onBlur: handleCloseButtonBlur, children: closeButtonIcon }) })] })] }), _jsxs("div", { className: cx(classes.content, 'mfui-SidePane__content'), children: [_jsx("div", { className: cx(classes.contentBody, 'mfui-SidePane__contentBody'), children: children }), resolvedFormFooterPosition === 'stacking' ? (_jsx("div", { className: cx(classes.footer, 'mfui-SidePane__footer'), children: _jsx(FormFooter, { sectionPosition: "fill", ...formFooterProps, position: resolvedFormFooterPosition }) })) : null] }), formFooterProps && resolvedFormFooterPosition !== 'stacking' ? (_jsx("div", { className: cx(classes.footer, 'mfui-SidePane__footer'), children: _jsx(FormFooter, { sectionPosition: "fill", ...formFooterProps, position: resolvedFormFooterPosition }) })) : null] })] }) })) : null }));
71
151
  });
@@ -134,10 +134,49 @@ export type SidePaneBaseProps = {
134
134
  /**
135
135
  * Disables closing the side pane when clicking on the backdrop (modal mode only).
136
136
  * When true, the side pane can only be closed via buttons or the close button.
137
+ * The ESC key still closes the side pane. Use `disableClose` to suppress every
138
+ * closing trigger at once.
137
139
  *
138
140
  * @default false
139
141
  */
140
142
  disableBackdropClose?: boolean;
143
+ /**
144
+ * Disables every trigger that closes the side pane: the close button (rendered in the
145
+ * disabled style), the ESC key, and the backdrop click. Use it while an operation the
146
+ * user cannot cancel is in flight, such as a form submission.
147
+ *
148
+ * This does not block the `open` prop, so the side pane can always be closed programmatically.
149
+ *
150
+ * A modal side pane cannot be dismissed at all while this is true, so use it only for short,
151
+ * bounded operations, clear it on both success and failure, and show visible progress inside
152
+ * the pane so the user understands why closing is unavailable.
153
+ *
154
+ * @default false
155
+ *
156
+ * @example
157
+ * ```tsx
158
+ * <SidePane
159
+ * open={isOpen}
160
+ * enableModal
161
+ * title="Edit profile"
162
+ * disableClose={isSubmitting}
163
+ * onClose={handleClose}
164
+ * formFooterProps={{
165
+ * actionsSlot: (
166
+ * <>
167
+ * <Button disabled={isSubmitting} onClick={handleClose}>
168
+ * キャンセル
169
+ * </Button>
170
+ * <Button priority="primary" loading={isSubmitting} onClick={handleSubmit}>
171
+ * 保存
172
+ * </Button>
173
+ * </>
174
+ * ),
175
+ * }}
176
+ * />
177
+ * ```
178
+ */
179
+ disableClose?: boolean;
141
180
  /**
142
181
  * Enable auto unmounting of the side pane content when it's not displayed.
143
182
  * When true, the side pane content will return null instead of hiding via CSS.
@@ -19,8 +19,11 @@ export function useSplitViewPanelVisibility(isOpen, controlledPanelSlot) {
19
19
  if (wasRightPanelVisibleOnMountRef.current === null) {
20
20
  wasRightPanelVisibleOnMountRef.current = isRightPanelVisible;
21
21
  }
22
- // Initialize hasRightPanelBeenVisible based on initial render state
23
- const [hasRightPanelBeenVisible, setHasRightPanelBeenVisible] = useState(() => wasRightPanelVisibleOnMountRef.current ?? false);
22
+ // Initialize hasRightPanelBeenVisible based on initial render state. Reads
23
+ // `isRightPanelVisible` directly rather than the ref just written above — on first
24
+ // render (the only render this initial value matters for) they're the same value, and
25
+ // this avoids passing a ref's `.current` into a function call during render.
26
+ const [hasRightPanelBeenVisible, setHasRightPanelBeenVisible] = useState(isRightPanelVisible);
24
27
  // Track previous visibility state
25
28
  // Note: This ref is updated in useSplitViewAnimation hook to ensure correct timing
26
29
  const previousIsRightPanelVisibleRef = useRef(isRightPanelVisible);
@@ -1,5 +1,14 @@
1
1
  import { type SubNavigationProps } from './SubNavigation.types';
2
2
  /**
3
3
  * This component is for the navigation links under the main navigation.
4
+ *
5
+ * The root element is a `<nav>` landmark. Name it with `aria-label` or `aria-labelledby` when the
6
+ * page has other navigation landmarks. No name is applied by default because the right name
7
+ * depends on what the navigation is for on each page.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <SubNavigation navigationItems={items} aria-label="設定" />
12
+ * ```
4
13
  */
5
- export declare function SubNavigation({ orientation, navigationItems, customLinkComponent, renderNavigationLabel, headerSlot, className, }: SubNavigationProps): import("react/jsx-runtime").JSX.Element;
14
+ export declare const SubNavigation: import("react").ForwardRefExoticComponent<SubNavigationProps & import("react").RefAttributes<HTMLElement>>;