@moneyforward/mfui-components 4.5.0 → 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 (71) hide show
  1. package/dist/src/Badge/Badge.d.ts +1 -1
  2. package/dist/src/Badge/Badge.js +4 -4
  3. package/dist/src/Badge/Badge.types.d.ts +3 -1
  4. package/dist/src/Checkbox/Checkbox.js +7 -3
  5. package/dist/src/DataTable/DataTable.types.d.ts +2 -2
  6. package/dist/src/DataTable/DataTableCell/DataTableCell.js +21 -4
  7. package/dist/src/DataTable/DataTableCell/DataTableCell.types.d.ts +1 -1
  8. package/dist/src/DataTable/DataTableHeaderRow/DataTableHeaderRow.js +7 -5
  9. package/dist/src/DataTable/DataTableRow/DataTableRow.js +104 -32
  10. package/dist/src/DataTable/DataTableRow/DataTableRow.types.d.ts +44 -15
  11. package/dist/src/DataTable/DataTableRowActionContext.d.ts +34 -0
  12. package/dist/src/DataTable/DataTableRowActionContext.js +8 -0
  13. package/dist/src/DateTimeSelection/DatePicker/DatePickerCalendar/DatePickerCalendar.js +7 -3
  14. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerPopover/DateRangePickerCalendar/DateRangePickerCalendar.js +1 -1
  15. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerPopover/utilities/createDateRangePickerPopoverTestUtility.js +2 -2
  16. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerProvider/DateRangePickerProvider.js +13 -7
  17. package/dist/src/DateTimeSelection/DateRangePicker/DateRangePickerTrigger/DateRangePickerTrigger.js +1 -1
  18. package/dist/src/DateTimeSelection/FilterDatePicker/FilterDatePicker.js +1 -1
  19. package/dist/src/DateTimeSelection/FilterMonthPicker/FilterMonthPicker.js +1 -1
  20. package/dist/src/DateTimeSelection/FilterMonthRangePicker/FilterMonthRangePicker.js +1 -1
  21. package/dist/src/DateTimeSelection/MonthPicker/MonthPickerPanel/MonthPickerPanel.js +1 -1
  22. package/dist/src/DateTimeSelection/MonthPicker/constants.d.ts +2 -2
  23. package/dist/src/DateTimeSelection/MonthPicker/constants.js +6 -6
  24. package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePickerMonthCell/MonthRangePickerMonthCell.js +1 -1
  25. package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePickerNavigation/MonthRangePickerNavigation.js +2 -2
  26. package/dist/src/DateTimeSelection/TimePicker/TimePicker.js +1 -1
  27. package/dist/src/DateTimeSelection/shared/BasePicker/constants.d.ts +2 -2
  28. package/dist/src/DateTimeSelection/shared/BasePicker/constants.js +10 -10
  29. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerPopover/BaseRangePickerCalendar/BaseRangePickerCalendar.js +1 -1
  30. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerPopover/constants.js +4 -4
  31. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerProvider/BaseRangePickerProvider.js +13 -7
  32. package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerTrigger/BaseRangePickerTrigger.js +2 -2
  33. package/dist/src/DateTimeSelection/shared/CalendarGrid/CalendarGrid.js +1 -1
  34. package/dist/src/DateTimeSelection/shared/utilities/japaneseCalendar.js +2 -2
  35. package/dist/src/FileDropZone/FileDropZone.js +1 -1
  36. package/dist/src/FileDropZone/utils/fileHelpers.js +1 -1
  37. package/dist/src/MainNavigation/BaseMainNavigation.js +1 -1
  38. package/dist/src/MainNavigation/NarrowViewportMainNavigation.js +1 -1
  39. package/dist/src/MultipleSelectBox/MultipleSelectBoxTrigger/MultipleSelectBoxTrigger.js +1 -1
  40. package/dist/src/MultipleSelectBox/hooks/useCreateOption.js +8 -4
  41. package/dist/src/MultipleSelectBox/hooks/useOptionKeyboardNavigation.js +9 -4
  42. package/dist/src/MultipleSelectBox/hooks/useSelectedValues.js +16 -50
  43. package/dist/src/NumberBox/NumberBox.js +8 -4
  44. package/dist/src/PageHeader/PageHeader.types.d.ts +2 -0
  45. package/dist/src/Popover/Popover.js +11 -2
  46. package/dist/src/SelectBox/SelectBox.js +9 -10
  47. package/dist/src/SelectBox/hooks/useKeyboardNavigation.js +8 -2
  48. package/dist/src/SplitView/hooks/useSplitViewPanelVisibility.js +5 -2
  49. package/dist/src/SubNavigation/SubNavigation.js +80 -19
  50. package/dist/src/SubNavigation/SubNavigation.types.d.ts +18 -6
  51. package/dist/src/Tabs/Tabs.js +8 -4
  52. package/dist/src/Tabs/hooks/useCalculatedSelectedTabId.js +7 -5
  53. package/dist/src/Toast/ToastContainer/ToastContainer.js +11 -2
  54. package/dist/src/Tooltip/Tooltip.js +8 -3
  55. package/dist/src/Tooltip/hooks/useTooltipDisplayController.js +77 -88
  56. package/dist/src/utilities/dom/getFocusableNodes.js +1 -3
  57. package/dist/src/utilities/dom/useFixedColumns.js +6 -8
  58. package/dist/src/utilities/react/flattenChildren.d.ts +15 -0
  59. package/dist/src/utilities/react/flattenChildren.js +28 -0
  60. package/dist/src/utilities/state/useLatest.d.ts +1 -1
  61. package/dist/src/utilities/state/useLatest.js +8 -2
  62. package/dist/styled-system/recipes/badge-slot-recipe.d.ts +1 -1
  63. package/dist/styled-system/recipes/badge-slot-recipe.js +4 -0
  64. package/dist/styled-system/recipes/data-table-cell-slot-recipe.d.ts +1 -1
  65. package/dist/styled-system/recipes/data-table-cell-slot-recipe.js +4 -0
  66. package/dist/styled-system/recipes/data-table-row-slot-recipe.js +13 -6
  67. package/dist/styled-system/recipes/sub-navigation-slot-recipe.d.ts +1 -1
  68. package/dist/styled-system/recipes/sub-navigation-slot-recipe.js +12 -0
  69. package/dist/styles.css +155 -35
  70. package/dist/tsconfig.build.tsbuildinfo +1 -1
  71. package/package.json +12 -12
@@ -5,7 +5,7 @@ import { type BadgeProps } from './Badge.types';
5
5
  * - If `dot` is `true`, the badge will be displayed as a dot.
6
6
  * - If `count` is not `undefined`, the badge will be displayed as a number calculated by `digit` prop.
7
7
  * - If `children` is not `undefined`, the badge will be displayed in the top-right corner of the children.
8
- * - In addition, the `aria-describedby` attribute will be added to the children to link the aria-label of the badge.
8
+ * - In addition, the `aria-describedby` attribute will be added to the children to link the visually hidden label of the badge.
9
9
  *
10
10
  * Also extends the props of `<span>` element.
11
11
  *
@@ -9,13 +9,13 @@ import { Typography } from '../Typography';
9
9
  * - If `dot` is `true`, the badge will be displayed as a dot.
10
10
  * - If `count` is not `undefined`, the badge will be displayed as a number calculated by `digit` prop.
11
11
  * - If `children` is not `undefined`, the badge will be displayed in the top-right corner of the children.
12
- * - In addition, the `aria-describedby` attribute will be added to the children to link the aria-label of the badge.
12
+ * - In addition, the `aria-describedby` attribute will be added to the children to link the visually hidden label of the badge.
13
13
  *
14
14
  * Also extends the props of `<span>` element.
15
15
  *
16
16
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
17
17
  */
18
- export const Badge = forwardRef(({ dot, count: number, digit, className, children, ...props }, ref) => {
18
+ export const Badge = forwardRef(({ dot, count: number, digit, className, children, 'aria-label': ariaLabel, ...props }, ref) => {
19
19
  const classes = badgeSlotRecipe({ hasChildren: children !== undefined });
20
20
  const displayContent = (() => {
21
21
  if (number === undefined)
@@ -25,10 +25,10 @@ export const Badge = forwardRef(({ dot, count: number, digit, className, childre
25
25
  const maxValue = 10 ** digit - 1;
26
26
  return number > maxValue ? `${String(maxValue)}+` : String(number);
27
27
  })();
28
- const badgeId = useId();
28
+ const labelId = useId();
29
29
  const displayBadge = dot !== undefined || number !== undefined;
30
30
  // If the badge is not displayed, just return the children.
31
31
  if (!displayBadge)
32
32
  return children;
33
- return (_jsxs("span", { ref: ref, className: cx(classes.root, 'mfui-Badge__root', className), id: badgeId, ...props, children: [children ? cloneElement(children, { 'aria-describedby': badgeId }) : null, _jsx("span", { className: cx(classes.indicator, 'mfui-Badge__indicator'), children: number !== undefined ? _jsx(Typography, { variant: "condensedBody", children: displayContent }) : null })] }));
33
+ return (_jsxs("span", { ref: ref, className: cx(classes.root, 'mfui-Badge__root', className), ...props, children: [children ? cloneElement(children, { 'aria-describedby': labelId }) : null, _jsx("span", { className: cx(classes.indicator, 'mfui-Badge__indicator'), children: number !== undefined ? (_jsx(Typography, { "aria-hidden": true, variant: "condensedBody", children: displayContent })) : null }), _jsx("span", { id: labelId, className: cx(classes.srOnlyLabel, 'mfui-Badge__srOnlyLabel'), children: ariaLabel })] }));
34
34
  });
@@ -50,7 +50,9 @@ export type BadgeProps = {
50
50
  * The invisible label to specify how you want the badge to be recognized and read by screen readers.
51
51
  * This prop is required.
52
52
  *
53
- * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label
53
+ * The value is not set as an `aria-label` attribute, because it is prohibited on role-less elements.
54
+ * Instead, it is rendered as visually hidden text inside the badge.
55
+ * When `children` is specified, that text is also referenced by the `aria-describedby` attribute of the children.
54
56
  *
55
57
  * @example
56
58
  * ```jsx
@@ -21,6 +21,13 @@ export const Checkbox = forwardRef(({ className, label, indeterminate = false, n
21
21
  const checkboxGroupContext = useContext(CheckboxGroupContext);
22
22
  const [localChecked, setLocalChecked] = useState(!!defaultChecked);
23
23
  const [localIndeterminate, setLocalIndeterminate] = useState(indeterminate);
24
+ // Adjusted during render (React's documented pattern for resyncing state to a changed
25
+ // prop) rather than in an effect, so the UI never flashes the stale value for one frame.
26
+ const [prevIndeterminateProp, setPrevIndeterminateProp] = useState(indeterminate);
27
+ if (indeterminate !== prevIndeterminateProp) {
28
+ setPrevIndeterminateProp(indeterminate);
29
+ setLocalIndeterminate(indeterminate);
30
+ }
24
31
  const classes = checkboxSlotRecipe();
25
32
  const WrapperTag = label ? 'label' : 'span';
26
33
  const wrapperProps = {
@@ -36,9 +43,6 @@ export const Checkbox = forwardRef(({ className, label, indeterminate = false, n
36
43
  checkboxInputRef.current.indeterminate = checkboxGroupContext.values === undefined ? localIndeterminate : false;
37
44
  }
38
45
  }, [checkboxInputRef, localIndeterminate, checkboxGroupContext.values]);
39
- useEffect(() => {
40
- setLocalIndeterminate(indeterminate);
41
- }, [indeterminate]);
42
46
  const icon = (() => {
43
47
  if (isIndeterminate) {
44
48
  return _jsx(CheckboxIndeterminate, {});
@@ -49,8 +49,8 @@ export type DataTableProps = {
49
49
  * - Clicking the row, including its checkbox cell, calls the `checkboxProps.onChange` of the `DataTable.Row` component once.
50
50
  * The checkbox stops responding to clicks on its own, so a single click never toggles the selection twice.
51
51
  * The checkbox cell does not have independent hover, focus, or active styles; the checkbox icon follows the row state.
52
- * - The row is focusable, and pressing Enter or Space while the row itself is focused toggles the selection.
53
- * The checkbox is removed from the tab order, so keyboard selection is handled through the row.
52
+ * - The checkbox stays in the tab order and is the keyboard control: pressing Enter or Space while it is focused toggles the selection.
53
+ * While the checkbox is focused, the focus indicator is displayed on the whole row.
54
54
  * - The row selection is not toggled when the click originates from another interactive element inside the row,
55
55
  * such as a button or a link, or when the row or its checkbox is disabled.
56
56
  *
@@ -1,5 +1,5 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
2
+ import { forwardRef, useState } from 'react';
3
3
  import { DisclosureBasicCollapsed, DisclosureBasicExpanded, DisclosureNestedCollapsed, DisclosureNestedExpanded, } from '@moneyforward/mfui-icons-react';
4
4
  import { dataTableCellSlotRecipe } from '../../../styled-system/recipes';
5
5
  import { FocusIndicator } from '../../FocusIndicator';
@@ -10,6 +10,8 @@ import { cx } from '../../../styled-system/css';
10
10
  import { useFixedColumns } from '../../utilities/dom/useFixedColumns';
11
11
  import { handleCheckboxCellClick } from '../utils/handleCheckbox';
12
12
  import { mergeRefs } from '../../utilities/dom/mergeRefs';
13
+ import { useIsomorphicLayoutEffect } from '../../utilities/react/useIsomorphicLayoutEffect';
14
+ import { useDataTableRowActionContext } from '../DataTableRowActionContext';
13
15
  export const DataTableCell = forwardRef(({ onClickCell, children, type = 'text', className, isRowHighlighted, isRowHeader = false, disabled = false, depth = 0, columnIndex, disclosureIconProps: nestingIconProps, style, ...props }, ref) => {
14
16
  const { size, leftFixedColumnIndex, rightFixedColumnIndex, loading, enableRowSelection, enableRowClickSelection, showVerticalBorder, layout, } = useDataTableContext();
15
17
  const { cellRef, isFixedColumn, isEdgeFixedColumn, fixedPositionStyles } = useFixedColumns({
@@ -20,6 +22,21 @@ export const DataTableCell = forwardRef(({ onClickCell, children, type = 'text',
20
22
  });
21
23
  const isCheckboxCell = enableRowSelection && columnIndex === 0;
22
24
  const isCheckboxCellInteractive = isCheckboxCell && !enableRowClickSelection;
25
+ // Take part in hosting the row action button of a clickable row. The row picks the host among
26
+ // the registered cells, so the button reaches a cell however the consumer composes the row.
27
+ const rowAction = useDataTableRowActionContext();
28
+ const registerRowActionCell = rowAction?.registerCell;
29
+ const [isRowActionHost, setIsRowActionHost] = useState(false);
30
+ useIsomorphicLayoutEffect(() => {
31
+ const element = cellRef.current;
32
+ if (!registerRowActionCell || !element) {
33
+ return;
34
+ }
35
+ return registerRowActionCell({ element, isRowHeader, setIsHost: setIsRowActionHost });
36
+ // `columnIndex` changes when the consumer reorders keyed cells, and the re-registration lets
37
+ // the row pick the host again by the new cell positions.
38
+ }, [registerRowActionCell, isRowHeader, cellRef, columnIndex]);
39
+ const rowActionButtonProps = isRowActionHost ? rowAction?.buttonProps : undefined;
23
40
  const classes = dataTableCellSlotRecipe({
24
41
  size,
25
42
  type,
@@ -27,7 +44,7 @@ export const DataTableCell = forwardRef(({ onClickCell, children, type = 'text',
27
44
  fixedColumn: isFixedColumn,
28
45
  edgeFixedColumn: isEdgeFixedColumn,
29
46
  isCheckboxCell,
30
- isCheckboxCellInteractive: isCheckboxCellInteractive || undefined,
47
+ isCheckboxCellInteractive: isCheckboxCellInteractive ? true : undefined,
31
48
  verticalBorder: showVerticalBorder,
32
49
  layout,
33
50
  // Passing `false` would emit a class for the unused `false` variant value, changing the
@@ -59,8 +76,8 @@ export const DataTableCell = forwardRef(({ onClickCell, children, type = 'text',
59
76
  // A row header identifies its row, so it must be a `th` for assistive technology.
60
77
  // `scope` is only interpreted on `th`, which is why it cannot be passed to a plain cell.
61
78
  const Tag = isRowHeader ? 'th' : 'td';
62
- return (_jsx(Tag, { ref: mergeRefs(ref, cellRef), scope: isRowHeader ? 'row' : undefined, className: cx(classes.root, 'mfui-DataTableCell__root',
63
- /* TODO: Remove in v5.0.0 */ 'mfui-DataGridCell__root', className), style: { ...style, ...fixedPositionStyles, zIndex: isFixedColumn ? 1 : undefined }, ...props, children: cellContent }));
79
+ return (_jsxs(Tag, { ref: mergeRefs(ref, cellRef), scope: isRowHeader ? 'row' : undefined, className: cx(classes.root, 'mfui-DataTableCell__root',
80
+ /* TODO: Remove in v5.0.0 */ 'mfui-DataGridCell__root', className), style: { ...style, ...fixedPositionStyles, zIndex: isFixedColumn ? 1 : undefined }, ...props, children: [rowActionButtonProps ? (_jsx("button", { type: "button", className: cx(classes.rowActionButton, 'mfui-DataTableCell__rowActionButton'), "data-mfui-content": "data-table-row-action-button", ...rowActionButtonProps })) : null, cellContent] }));
64
81
  });
65
82
  DataTableCell.displayName = 'DataTableCell';
66
83
  function CellContent({ children, depth, disclosureIconProps, classes, }) {
@@ -109,7 +109,7 @@ export type DataTableCellProps = {
109
109
  *
110
110
  * `aria-expanded` is set automatically based on `isOpen`:
111
111
  * on the cell button when the cell is interactive (`onClickCell`),
112
- * or on the row when the row is interactive (`onClickRow`).
112
+ * or on the visually hidden row action button when the row is interactive (`onClickRow`).
113
113
  *
114
114
  * Note: the attribute on the cell button is fully derived from `isOpen`
115
115
  * and cannot be overridden, while an `aria-expanded` passed to
@@ -1,23 +1,25 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Children, cloneElement, forwardRef, isValidElement, useEffect } from 'react';
2
+ import { cloneElement, forwardRef, isValidElement, useEffect } from 'react';
3
3
  import { dataTableHeaderRowSlotRecipe } from '../../../styled-system/recipes';
4
4
  import { useDataTableContext } from '../DataTableProvider';
5
5
  import { DataTableHeaderCell } from '../DataTableHeaderCell';
6
6
  import { Checkbox } from '../../Checkbox';
7
7
  import { cx } from '../../../styled-system/css';
8
8
  import { isComponentOrWrapped } from '../../utilities/react/isComponentOrWrapped';
9
+ import { flattenChildren } from '../../utilities/react/flattenChildren';
9
10
  export const DataTableHeaderRow = forwardRef(({ children, checkboxProps, className, ...props }, ref) => {
10
11
  const { enableRowSelection, setNumberColumns } = useDataTableContext();
11
12
  const classes = dataTableHeaderRowSlotRecipe();
12
13
  // Building the element before wrapping keeps everything the header row owns on the Checkbox itself.
13
14
  const selectionCheckbox = (_jsx(Checkbox, { checked: checkboxProps?.checked, indeterminate: checkboxProps?.indeterminate, "aria-label": checkboxProps?.['aria-label'] ?? 'すべての行を選択', disabled: checkboxProps?.disabled, onChange: checkboxProps?.onChange, onClick: checkboxProps?.onClick }));
14
- // Count the number of header cells
15
+ // Count the number of header cells, plus the selection checkbox column rendered
16
+ // below when `enableRowSelection` is on (it isn't part of `children`).
15
17
  useEffect(() => {
16
- const headerCells = Children.toArray(children).filter((child) => isValidElement(child) && isComponentOrWrapped(child, DataTableHeaderCell));
17
- setNumberColumns(headerCells.length);
18
+ const headerCells = flattenChildren(children).filter((child) => isValidElement(child) && isComponentOrWrapped(child, DataTableHeaderCell));
19
+ setNumberColumns(headerCells.length + (enableRowSelection ? 1 : 0));
18
20
  }, [children, enableRowSelection, setNumberColumns]);
19
21
  return (_jsxs("tr", { className: cx(classes.root, 'mfui-DataTableHeaderRow__root',
20
- /* TODO: Remove in v5.0.0 */ 'mfui-DataGridHeaderRow__root', className), ...props, ref: ref, children: [enableRowSelection ? (_jsx(DataTableHeaderCell, { columnIndex: 0, disabled: checkboxProps?.disabled, children: checkboxProps?.wrapper ? checkboxProps.wrapper(selectionCheckbox) : selectionCheckbox })) : null, Children.map(children, (child, index) => {
22
+ /* TODO: Remove in v5.0.0 */ 'mfui-DataGridHeaderRow__root', className), ...props, ref: ref, children: [enableRowSelection ? (_jsx(DataTableHeaderCell, { columnIndex: 0, disabled: checkboxProps?.disabled, children: checkboxProps?.wrapper ? checkboxProps.wrapper(selectionCheckbox) : selectionCheckbox })) : null, flattenChildren(children).map((child, index) => {
21
23
  if (!isValidElement(child)) {
22
24
  return child;
23
25
  }
@@ -1,11 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Children, cloneElement, forwardRef, isValidElement, useRef } from 'react';
2
+ import { cloneElement, forwardRef, isValidElement, useCallback, useMemo, useRef, useState } from 'react';
3
+ import { DataTableRowActionContext, } from '../DataTableRowActionContext';
3
4
  import { dataTableRowSlotRecipe } from '../../../styled-system/recipes';
4
5
  import { DataTableCell } from '../DataTableCell';
5
6
  import { Checkbox } from '../../Checkbox';
6
7
  import { useDataTableContext } from '../DataTableProvider';
7
8
  import { cx } from '../../../styled-system/css';
8
9
  import { isComponentOrWrapped } from '../../utilities/react/isComponentOrWrapped';
10
+ import { flattenChildren } from '../../utilities/react/flattenChildren';
11
+ import { useIsomorphicLayoutEffect } from '../../utilities/react/useIsomorphicLayoutEffect';
12
+ const ROW_ACTION_BUTTON_SELECTOR = '[data-mfui-content="data-table-row-action-button"]';
9
13
  const INTERACTIVE_ELEMENT_SELECTOR = [
10
14
  'a[href]',
11
15
  'button',
@@ -33,17 +37,32 @@ function isClickFromNestedInteractiveElement(event) {
33
37
  if (!(event.target instanceof Element)) {
34
38
  return false;
35
39
  }
40
+ // A click inside a nested table (e.g. a DataTable rendered in a cell) belongs to the inner row.
41
+ if (event.target.closest('tr') !== event.currentTarget) {
42
+ return true;
43
+ }
36
44
  const interactiveElement = event.target.closest(INTERACTIVE_ELEMENT_SELECTOR);
37
- return interactiveElement !== null && interactiveElement !== event.currentTarget;
45
+ if (interactiveElement === null || interactiveElement === event.currentTarget) {
46
+ return false;
47
+ }
48
+ // The visually hidden row action button exists to trigger the row click itself,
49
+ // so its click must not be treated as a nested interactive element's click.
50
+ return !interactiveElement.matches(ROW_ACTION_BUTTON_SELECTOR);
38
51
  }
39
- export const DataTableRow = forwardRef(({ children, disabled = false, highlighted, checkboxProps, className, onClickRow, selectable, ...props }, ref) => {
52
+ export const DataTableRow = forwardRef(({ children, disabled = false, highlighted, checkboxProps, className, onClickRow, rowActionButtonProps, selectable, 'aria-expanded': ariaExpandedProp, ...props }, ref) => {
40
53
  const { enableRowSelection: contextEnableRowSelection, enableRowClickSelection, layout } = useDataTableContext();
41
54
  const selectionCheckboxRef = useRef(null);
42
55
  const isSelectable = selectable ?? contextEnableRowSelection;
43
- const isRowHighlighted = isSelectable ? (checkboxProps?.checked ?? highlighted) : highlighted;
56
+ // A selected row is always highlighted, and `highlighted` stays an independent signal on top of it,
57
+ // so that a row can be marked (e.g. as the one opened in a detail panel) while it is not selected.
58
+ const isRowHighlighted = isSelectable ? highlighted === true || checkboxProps?.checked === true : highlighted;
44
59
  // Only a row whose selection can actually be toggled becomes the trigger of the row selection.
45
60
  const isRowClickSelectable = !!enableRowClickSelection && isSelectable && !disabled && !checkboxProps?.disabled;
46
61
  const isInteractive = (onClickRow !== undefined || isRowClickSelectable) && !disabled;
62
+ // The row click itself is exposed to keyboard and screen reader users through the row action
63
+ // button. The row click selection is exposed through the selection checkbox instead.
64
+ // A disabled row keeps the button as a disabled one so that the row action stays discoverable.
65
+ const hasRowActionButton = onClickRow !== undefined;
47
66
  const classes = dataTableRowSlotRecipe({
48
67
  layout,
49
68
  highlighted: isRowHighlighted,
@@ -51,20 +70,85 @@ export const DataTableRow = forwardRef(({ children, disabled = false, highlighte
51
70
  rowClickSelectable: isRowClickSelectable,
52
71
  disabled,
53
72
  });
73
+ // Fragments are expanded so that cells wrapped in a Fragment (e.g. `<>{items.map(...)}</>`)
74
+ // are recognized by the cell inspection below.
75
+ const flatChildren = useMemo(() => flattenChildren(children), [children]);
76
+ const isCellElement = (child) => isValidElement(child) && isComponentOrWrapped(child, DataTableCell);
54
77
  // When the interactive row itself toggles a disclosure (a child cell shows the disclosure icon
55
- // but does not handle the click by itself), expose the expanded state on the row.
56
- const disclosureIconProps = Children.toArray(children)
57
- .filter((child) => isValidElement(child) && isComponentOrWrapped(child, DataTableCell))
78
+ // but does not handle the click by itself), expose the expanded state on the row action button.
79
+ const disclosureIconProps = flatChildren
80
+ .filter(isCellElement)
58
81
  .find((cell) => cell.props.disclosureIconProps && !cell.props.onClickCell)?.props.disclosureIconProps;
59
- const ariaExpanded = onClickRow !== undefined && !disabled && disclosureIconProps ? (disclosureIconProps.isOpen ?? false) : undefined;
82
+ const derivedAriaExpanded = hasRowActionButton && disclosureIconProps ? (disclosureIconProps.isOpen ?? false) : undefined;
83
+ const rowActionAriaExpanded = ariaExpandedProp ?? derivedAriaExpanded;
84
+ // The default name is given by `aria-label`, so a consumer `aria-label` replaces it and a consumer
85
+ // `aria-labelledby` takes precedence over it by the accessible name computation.
86
+ // A row that toggles a disclosure says so, since its expanded state is exposed on the button.
87
+ const defaultRowActionLabel = disclosureIconProps ? '行を開閉' : '行の操作';
88
+ const resolvedRowActionButtonProps = useMemo(() => hasRowActionButton
89
+ ? {
90
+ ...rowActionButtonProps,
91
+ // An explicitly undefined consumer label must not leave the button without a name.
92
+ 'aria-label': rowActionButtonProps?.['aria-label'] ?? defaultRowActionLabel,
93
+ ...(rowActionAriaExpanded !== undefined && { 'aria-expanded': rowActionAriaExpanded }),
94
+ ...(disabled && { disabled }),
95
+ }
96
+ : undefined, [hasRowActionButton, rowActionButtonProps, defaultRowActionLabel, rowActionAriaExpanded, disabled]);
97
+ // The cells register themselves through the context, so the button reaches a cell wherever the
98
+ // consumer renders it (intermediate components, wrappers, Fragments). The version state makes the
99
+ // host selection below run again whenever a cell mounts or unmounts.
100
+ const rowActionCellEntries = useRef(new Set());
101
+ const [rowActionCellsVersion, setRowActionCellsVersion] = useState(0);
102
+ const registerRowActionCell = useCallback((entry) => {
103
+ rowActionCellEntries.current.add(entry);
104
+ setRowActionCellsVersion((version) => version + 1);
105
+ return () => {
106
+ rowActionCellEntries.current.delete(entry);
107
+ setRowActionCellsVersion((version) => version + 1);
108
+ };
109
+ }, []);
110
+ // The first cell in the row hosts the button, skipping a row header cell so that the button label
111
+ // does not become part of the row header name. The selection cell, rendered by the row itself,
112
+ // therefore hosts it whenever the row is selectable.
113
+ const hasWarnedMissingRowActionHost = useRef(false);
114
+ useIsomorphicLayoutEffect(() => {
115
+ // The registration order follows the mount order, which differs from the visual order when a
116
+ // cell mounts later, so sort by the position of the cell element in the row.
117
+ const entries = [...rowActionCellEntries.current].toSorted((a, b) => a.element.cellIndex - b.element.cellIndex);
118
+ const host = hasRowActionButton ? (entries.find((entry) => !entry.isRowHeader) ?? entries[0]) : undefined;
119
+ entries.forEach((entry) => {
120
+ entry.setIsHost(entry === host);
121
+ });
122
+ if (hasRowActionButton && host === undefined && !hasWarnedMissingRowActionHost.current) {
123
+ hasWarnedMissingRowActionHost.current = true;
124
+ console.warn('[MFUI] DataTable.Row received onClickRow, but the row action button was not rendered because ' +
125
+ 'the row contains no DataTable.Cell, so the row cannot be operated with a keyboard or screen reader. ' +
126
+ 'Render the cells of the row with DataTable.Cell.');
127
+ }
128
+ }, [hasRowActionButton, rowActionCellsVersion]);
129
+ // The cells of a row without the button do not register, so such a row does not pay for the host selection.
130
+ const rowActionContextValue = useMemo(() => ({
131
+ buttonProps: resolvedRowActionButtonProps,
132
+ registerCell: hasRowActionButton ? registerRowActionCell : undefined,
133
+ }), [hasRowActionButton, resolvedRowActionButtonProps, registerRowActionCell]);
60
134
  // Forwarding the interaction to the checkbox lets the consumer keep handling the row selection in
61
135
  // `checkboxProps.onChange` only, and the change event carries the real next checked state.
62
136
  const toggleSelectionByRowInteraction = () => {
63
137
  selectionCheckboxRef.current?.click();
64
138
  };
139
+ // The focus indicator is displayed on the whole row while the selection checkbox is focused, so the
140
+ // selection also toggles with Enter, which a native checkbox ignores, in addition to Space.
141
+ const handleKeyDownSelectionCheckbox = (event) => {
142
+ if (isRowClickSelectable && event.key === 'Enter') {
143
+ // Prevents the implicit form submission.
144
+ event.preventDefault();
145
+ toggleSelectionByRowInteraction();
146
+ }
147
+ };
65
148
  // Building the element before wrapping keeps everything the row owns on the Checkbox itself, so that the
66
149
  // ref-based toggle and the recipe selectors keep working with a consumer-supplied wrapper in between.
67
- const selectionCheckbox = (_jsx(Checkbox, { ref: selectionCheckboxRef, className: cx(classes.selectionCheckbox, 'mfui-DataTableRow__selectionCheckbox'), checked: checkboxProps?.checked, "aria-label": checkboxProps?.['aria-label'] ?? '行を選択', disabled: disabled || checkboxProps?.disabled, tabIndex: isRowClickSelectable ? -1 : undefined, onChange: checkboxProps?.onChange, onClick: checkboxProps?.onClick }));
150
+ const selectionCheckbox = (_jsx(Checkbox, { ref: selectionCheckboxRef, className: cx(classes.selectionCheckbox, 'mfui-DataTableRow__selectionCheckbox'), checked: checkboxProps?.checked, "aria-label": checkboxProps?.['aria-label'] ?? '行を選択', disabled: disabled || checkboxProps?.disabled, onChange: checkboxProps?.onChange, onClick: checkboxProps?.onClick, onKeyDown: handleKeyDownSelectionCheckbox }));
151
+ // Handles pointer clicks anywhere in the row and the bubbled click of the row action button.
68
152
  const handleClickRow = (event) => {
69
153
  if (disabled || isClickFromNestedInteractiveElement(event)) {
70
154
  return;
@@ -74,29 +158,17 @@ export const DataTableRow = forwardRef(({ children, disabled = false, highlighte
74
158
  }
75
159
  onClickRow?.(event);
76
160
  };
77
- const handleKeyDownRow = (event) => {
78
- if (!disabled && event.target === event.currentTarget && (event.key === 'Enter' || event.key === ' ')) {
79
- if (isRowClickSelectable) {
80
- // Not to scroll the page when the Space key is pressed on the focused row.
81
- event.preventDefault();
82
- toggleSelectionByRowInteraction();
83
- }
84
- onClickRow?.(event);
85
- }
86
- };
87
- return (_jsxs("tr", { ref: ref, className: cx(classes.root, 'mfui-DataTableRow__root',
88
- /* TODO: Remove in v5.0.0 */ 'mfui-DataGridRow__root', className), ...(ariaExpanded !== undefined && { 'aria-expanded': ariaExpanded }), ...props,
89
- // When the row is clickable, the role should be 'button' in order to allow screen readers to understand the row is clickable.
90
- role: isInteractive ? 'button' : 'row', tabIndex: isInteractive ? 0 : undefined, ...(disabled && { 'aria-disabled': disabled }), onClick: handleClickRow, onKeyDown: handleKeyDownRow, children: [isSelectable ? (_jsx(DataTableCell, { columnIndex: 0, isRowHighlighted: isRowHighlighted, disabled: disabled, children: checkboxProps?.wrapper ? checkboxProps.wrapper(selectionCheckbox) : selectionCheckbox })) : null, Children.map(children, (child, index) => {
91
- if (!isValidElement(child)) {
161
+ return (_jsx(DataTableRowActionContext.Provider, { value: rowActionContextValue, children: _jsxs("tr", { ref: ref, className: cx(classes.root, 'mfui-DataTableRow__root',
162
+ /* TODO: Remove in v5.0.0 */ 'mfui-DataGridRow__root', className), ...(!hasRowActionButton && ariaExpandedProp !== undefined && { 'aria-expanded': ariaExpandedProp }), ...props, ...(disabled && { 'aria-disabled': disabled }), onClick: handleClickRow, children: [isSelectable ? (_jsx(DataTableCell, { columnIndex: 0, isRowHighlighted: isRowHighlighted, disabled: disabled, children: checkboxProps?.wrapper ? checkboxProps.wrapper(selectionCheckbox) : selectionCheckbox })) : null, flatChildren.map((child, index) => {
163
+ if (!isValidElement(child)) {
164
+ return child;
165
+ }
166
+ if (isComponentOrWrapped(child, DataTableCell)) {
167
+ // Add selectable offset to columnIndex if selectable is true
168
+ const columnIndex = isSelectable ? index + 1 : index;
169
+ return cloneElement(child, { isRowHighlighted, columnIndex, disabled });
170
+ }
92
171
  return child;
93
- }
94
- if (isComponentOrWrapped(child, DataTableCell)) {
95
- // Add selectable offset to columnIndex if selectable is true
96
- const columnIndex = isSelectable ? index + 1 : index;
97
- return cloneElement(child, { isRowHighlighted, columnIndex, disabled });
98
- }
99
- return child;
100
- })] }));
172
+ })] }) }));
101
173
  });
102
174
  DataTableRow.displayName = 'DataTableRow';
@@ -1,4 +1,4 @@
1
- import { type ComponentPropsWithRef } from 'react';
1
+ import { type ComponentPropsWithRef, type ComponentPropsWithoutRef } from 'react';
2
2
  import { type CheckboxProps } from '../../Checkbox';
3
3
  import { type DataTableSelectionCheckboxWrapper } from '../DataTable.types';
4
4
  /**
@@ -11,7 +11,7 @@ import { type DataTableSelectionCheckboxWrapper } from '../DataTable.types';
11
11
  export type DataTableRowProps = {
12
12
  /**
13
13
  * Whether the row is disabled.
14
- * When true, interaction when the row is clicked and the checkbox for selectable feature will be disabled.
14
+ * When true, interaction when the row is clicked, the row action button and the checkbox for selectable feature will be disabled.
15
15
  * The row content remains visible with appropriate styling for readability.
16
16
  * Interactive elements passed as a children for DataTable.Cell won't be disabled automatically.
17
17
  *
@@ -19,8 +19,13 @@ export type DataTableRowProps = {
19
19
  */
20
20
  disabled?: boolean;
21
21
  /**
22
- * The state of the row whether it is highlighted without a selected.
23
- * This prop displays a highlighted background color regardless of the `enableRowSelection` prop of the DataTable component.
22
+ * Whether the row displays the highlighted background color.
23
+ * This prop works regardless of the `enableRowSelection` prop of the `DataTable` component: on a selectable table
24
+ * the row is highlighted when this prop is `true` OR when `checkboxProps.checked` is `true`, so a row can be
25
+ * highlighted while it is not selected.
26
+ *
27
+ * Note that the highlighted background is the same color as the selected one, so on a selectable table the
28
+ * selection checkbox, not the background, is what tells a selected row from a merely highlighted one.
24
29
  *
25
30
  * @default false
26
31
  */
@@ -47,10 +52,6 @@ export type DataTableRowProps = {
47
52
  * When the content restates the accessible name of the checkbox, pass `hideFromScreenReader` to the `Tooltip`
48
53
  * component to avoid announcing the same information twice.
49
54
  *
50
- * Note that when the `enableRowClickSelection` prop of the `DataTable` component is `true`, the checkbox is removed
51
- * from the tab order and the focusable element is the row, which is outside the wrapper. A tooltip in the wrapper is
52
- * then opened by hover only, so do not put information that keyboard users need in it in that case.
53
- *
54
55
  * ```tsx
55
56
  * <DataTable.Row
56
57
  * checkboxProps={{
@@ -64,25 +65,53 @@ export type DataTableRowProps = {
64
65
  };
65
66
  /**
66
67
  * The callback function that is called when the row is clicked.
67
- * If provided, the row can be focused and the focus indicator is displayed.
68
68
  *
69
- * This prop will be passed to the `onClick` and `onKeyDown` of the `tr` element.
70
- * When the element is clicked, the event is passed to the `onClickRow` prop, but event isn't passed when the Enter or Space key is pressed.
69
+ * If provided, a visually hidden button is rendered inside the row so that keyboard and
70
+ * screen reader users can perform the row action without making the `tr` element itself
71
+ * interactive. The `tr` element keeps the `row` role and is not focusable, so the controls
72
+ * inside the cells stay reachable. Activating the button (Enter or Space) triggers this
73
+ * callback via the bubbled click event, and the focus indicator is displayed on the row
74
+ * while the button is focused. The accessible name of the button can be customized with
75
+ * the `rowActionButtonProps` prop.
76
+ *
77
+ * The button is hosted by the first `DataTableCell` of the row that is not a row header (the
78
+ * selection checkbox cell when the row is selectable), wherever the cell is rendered in the
79
+ * React tree: intermediate components, wrapper components and Fragments are all fine. If the
80
+ * row renders no `DataTableCell` at all, the button is not rendered, the row becomes unusable
81
+ * with a keyboard or screen reader, and a warning is logged.
71
82
  *
72
83
  * Note that this callback is NOT called when the click originates from an interactive
73
84
  * descendant inside the row — e.g. a button, link, input (including `Checkbox`), select,
74
85
  * label, or an element with an interactive ARIA role such as `checkbox` or `menuitem`.
75
86
  * Handle those interactions on the descendant itself (e.g. the `Checkbox`'s `onChange`).
76
- * Likewise, Enter or Space triggers this callback only while the row itself is focused,
77
- * not while a focusable descendant is focused.
78
87
  *
79
88
  * When the `enableRowClickSelection` prop of the `DataTable` component is `true`, the selection checkbox stops
80
- * responding to clicks on its own, so this callback is called for the clicks on the checkbox cell as well.
89
+ * responding to pointer clicks on its own, so this callback is called for the clicks on the checkbox cell as well.
81
90
  * Do not toggle the row selection here in that case, otherwise the selection is toggled twice.
91
+ * Toggling the checkbox with the keyboard does not call this callback.
82
92
  *
83
93
  * @default undefined
84
94
  */
85
- onClickRow?: (event: React.MouseEvent<HTMLTableRowElement> | React.KeyboardEvent<HTMLTableRowElement>) => void;
95
+ onClickRow?: (event: React.MouseEvent<HTMLTableRowElement>) => void;
96
+ /**
97
+ * The properties for the visually hidden button that makes the clickable row accessible
98
+ * to keyboard and screen reader users.
99
+ * This prop is available when the `onClickRow` prop is provided.
100
+ * If this prop is not passed, the default values for each property will be applied.
101
+ *
102
+ * @property aria-label - The alternative text for the button. default is '行の操作', or '行を開閉' when the
103
+ * row toggles a disclosure (a cell has `disclosureIconProps` without `onClickCell`).
104
+ *
105
+ * @property aria-labelledby - The id of the element that names the button, e.g. the row header cell.
106
+ * It takes precedence over `aria-label`.
107
+ *
108
+ * @property aria-describedby - The id of the element that describes the button.
109
+ *
110
+ * @property aria-controls - The id of the element that the row action expands or collapses.
111
+ *
112
+ * @property id - The id of the button, e.g. to move the focus back to the row action after closing a dialog.
113
+ */
114
+ rowActionButtonProps?: Pick<ComponentPropsWithoutRef<'button'>, 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-controls' | 'id'>;
86
115
  /**
87
116
  * Whether the table rows are selectable.
88
117
  * If `true`, the checkbox cell will be added to the first column of header and each row.
@@ -0,0 +1,34 @@
1
+ import { type ComponentPropsWithoutRef } from 'react';
2
+ /**
3
+ * The attributes of the visually hidden row action button, resolved by `DataTableRow`.
4
+ */
5
+ export type RowActionButtonProps = Pick<ComponentPropsWithoutRef<'button'>, 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-controls' | 'aria-expanded' | 'id' | 'disabled'>;
6
+ /**
7
+ * A cell that registered itself as a candidate host of the row action button.
8
+ */
9
+ export type RowActionCellEntry = {
10
+ /** The rendered cell element, used to order the candidates by their position in the row. */
11
+ element: HTMLTableCellElement;
12
+ /** Row header cells host the button only when the row has no other cell. */
13
+ isRowHeader: boolean;
14
+ /** Called by the row when the cell becomes, or stops being, the host. */
15
+ setIsHost: (isHost: boolean) => void;
16
+ };
17
+ export type DataTableRowActionContextValue = {
18
+ /** The attributes of the row action button, or `undefined` when the row has no row action. */
19
+ buttonProps: RowActionButtonProps | undefined;
20
+ /**
21
+ * Registers a cell as a candidate host of the row action button, or `undefined` when the row has
22
+ * no row action so that the cells skip the registration.
23
+ *
24
+ * @returns The function that unregisters the cell.
25
+ */
26
+ registerCell: ((entry: RowActionCellEntry) => () => void) | undefined;
27
+ };
28
+ /**
29
+ * Lets any `DataTableCell` rendered inside a `DataTableRow` take part in hosting the row action
30
+ * button, regardless of how the consumer composes the cells (intermediate components, wrappers,
31
+ * Fragments). The row decides which registered cell hosts the button.
32
+ */
33
+ export declare const DataTableRowActionContext: import("react").Context<DataTableRowActionContextValue | null>;
34
+ export declare const useDataTableRowActionContext: () => DataTableRowActionContextValue | null;
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from 'react';
2
+ /**
3
+ * Lets any `DataTableCell` rendered inside a `DataTableRow` take part in hosting the row action
4
+ * button, regardless of how the consumer composes the cells (intermediate components, wrappers,
5
+ * Fragments). The row decides which registered cell hosts the button.
6
+ */
7
+ export const DataTableRowActionContext = createContext(null);
8
+ export const useDataTableRowActionContext = () => useContext(DataTableRowActionContext);
@@ -22,9 +22,13 @@ export function DatePickerCalendar({ value, onChange, minDate, maxDate, checkDis
22
22
  const { viewingValue, setViewingValue, pendingFocusDate, setPendingFocusDate } = useBasePickerContext();
23
23
  const [internalValue, setInternalValue] = useState(value);
24
24
  const calendarLocale = useCalendarLocale();
25
- useEffect(() => {
25
+ // Adjusted during render (React's documented pattern for resyncing state to a changed
26
+ // prop) rather than in an effect, so the UI never flashes the stale value for one frame.
27
+ const [prevValueProp, setPrevValueProp] = useState(value);
28
+ if (value !== prevValueProp) {
29
+ setPrevValueProp(value);
26
30
  setInternalValue(value);
27
- }, [value]);
31
+ }
28
32
  const setValue = useCallback((date, event) => {
29
33
  setInternalValue(date);
30
34
  onChange?.(date, event);
@@ -81,7 +85,7 @@ export function DatePickerCalendar({ value, onChange, minDate, maxDate, checkDis
81
85
  newDate.setFullYear(year);
82
86
  setViewingValue(newDate);
83
87
  }, [setViewingValue, viewingValue]);
84
- const shouldFilterYears = !!(minDate || maxDate);
88
+ const shouldFilterYears = !!(minDate ?? maxDate);
85
89
  const filterYear = useCallback((y) => {
86
90
  const normalizedMinDate = minDate ? new Date(minDate) : undefined;
87
91
  const normalizedMaxDate = maxDate ? new Date(maxDate) : undefined;
@@ -39,5 +39,5 @@ export function DateRangePickerCalendar({ viewingMonth, handleKeyboardNavigation
39
39
  };
40
40
  return (_jsx(DateRangePickerDateCell, { ...rest, date: date, selected: selected, inRange: inRange, disabled: disabled, isRangeStart: isStart, isRangeEnd: isEnd, onClick: handleClick, onMouseEnter: handleMouseEnter, onFocus: handleFocus, onMouseLeave: clearPreview, onBlur: clearPreview }, date.toISOString()));
41
41
  }, [isDateDisabled, isRangeStart, isRangeEnd, isInRange, handleDateClick, handlePreview, clearPreview]);
42
- return (_jsx("div", { className: cx(classNames.root, 'mfui-DateRangePickerCalendar__root'), children: _jsx(CalendarGrid, { viewingValue: viewingMonth, renderDateCell: renderDateCell, pendingFocusDate: pendingFocusDate ?? undefined, value: temporaryStart || temporaryEnd, onDateClick: undefined, onPendingFocusDateChange: setPendingFocusDate, onKeyboardNavigation: handleKeyboardNavigation }) }));
42
+ return (_jsx("div", { className: cx(classNames.root, 'mfui-DateRangePickerCalendar__root'), children: _jsx(CalendarGrid, { viewingValue: viewingMonth, renderDateCell: renderDateCell, pendingFocusDate: pendingFocusDate ?? undefined, value: temporaryStart ?? temporaryEnd, onDateClick: undefined, onPendingFocusDateChange: setPendingFocusDate, onKeyboardNavigation: handleKeyboardNavigation }) }));
43
43
  }
@@ -5,7 +5,7 @@ export function createDateRangePickerPopoverTestUtility({ user }) {
5
5
  // Look for the previous month button by finding buttons that might contain previous month indicators
6
6
  const allButtons = screen.getAllByRole('button');
7
7
  // The previous month button is typically the first IconButton in the navigation
8
- return (allButtons.find((button) => button.getAttribute('aria-label')?.includes('月') || button.getAttribute('aria-label')?.includes('month')) ??
8
+ return (allButtons.find((button) => !!button.getAttribute('aria-label')?.includes('月') || !!button.getAttribute('aria-label')?.includes('month')) ??
9
9
  allButtons.find((button) => button.querySelector('svg')) ??
10
10
  allButtons[0]);
11
11
  }
@@ -15,7 +15,7 @@ export function createDateRangePickerPopoverTestUtility({ user }) {
15
15
  // Find the button with next month aria-label
16
16
  const nextButton = allButtons.find((button) => {
17
17
  const label = button.getAttribute('aria-label');
18
- return label?.includes('次の') || label?.includes('Next');
18
+ return !!label?.includes('次の') || !!label?.includes('Next');
19
19
  });
20
20
  return nextButton ?? allButtons[1]; // fallback to second button
21
21
  }