@moneyforward/mfui-components 3.36.0 → 3.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,15 +30,27 @@ export function MonthPickerPanel({ viewingValue, setViewingValue, value, onChang
30
30
  const { pendingFocusDate, setPendingFocusDate, baseFormat } = useBasePickerContext();
31
31
  const locale = useCalendarLocale();
32
32
  const year = viewingValue.getFullYear();
33
- // Focus the appropriate month cell (with visible focus ring) when the panel first opens.
33
+ // Show a visible focus ring on the appropriate month cell when the panel first opens,
34
+ // without stealing real focus away from the text box (see BasePicker's handlePopoverOpen).
34
35
  // Uses a ref so the initial value is captured at mount time, keeping the dep array empty.
35
36
  const initialFocusMonthRef = useRef(dayjs(value ?? new Date()).format(baseFormat));
36
37
  useLayoutEffect(() => {
37
38
  const targetCell = document.querySelector(`[data-mfui-month="${initialFocusMonthRef.current}"]`);
38
- if (targetCell && !targetCell.disabled) {
39
- targetCell.dataset['focusVisible'] = '';
40
- targetCell.addEventListener('blur', () => delete targetCell.dataset['focusVisible'], { once: true });
41
- }
39
+ if (!targetCell || targetCell.disabled)
40
+ return;
41
+ targetCell.dataset['focusVisible'] = '';
42
+ // Since real focus never moves to targetCell, it can never emit a native 'blur' event.
43
+ // Clear the fake ring the moment real focus lands anywhere else instead.
44
+ const clearFakeFocusVisible = (event) => {
45
+ if (event.target !== targetCell) {
46
+ delete targetCell.dataset['focusVisible'];
47
+ document.removeEventListener('focusin', clearFakeFocusVisible);
48
+ }
49
+ };
50
+ document.addEventListener('focusin', clearFakeFocusVisible);
51
+ return () => {
52
+ document.removeEventListener('focusin', clearFakeFocusVisible);
53
+ };
42
54
  }, []);
43
55
  // Calculate if year navigation should be disabled based on min/max constraints
44
56
  const { isPreviousYearDisabled, isNextYearDisabled } = useMemo(() => {
@@ -122,8 +122,10 @@ function InternalPopover({ value, defaultValue, initialViewingDate, textBoxRef,
122
122
  !isClickOnClearButton;
123
123
  if (isClickOnTextBox || isClickOnWrapper)
124
124
  return;
125
- // Get the date to focus on: selected value → initialViewingDate → today
126
- const dateToFocus = dayjs(value ?? defaultValue ?? initialViewingDate ?? new Date())
125
+ // Get the date to focus on: currently selected value (controlled or uncontrolled) → initialViewingDate → today.
126
+ // `pickerPopoverProps.value` reflects the live selection in both modes; the raw `value`/`defaultValue`
127
+ // props only ever reflect the external controlled value or the original mount-time default.
128
+ const dateToFocus = dayjs(pickerPopoverProps.value ?? value ?? defaultValue ?? initialViewingDate ?? new Date())
127
129
  .startOf('day')
128
130
  .toDate();
129
131
  const formattedDate = dayjs(dateToFocus).format(baseFormat);
@@ -131,7 +133,17 @@ function InternalPopover({ value, defaultValue, initialViewingDate, textBoxRef,
131
133
  setViewingValue(dayjs(dateToFocus).startOf('month').startOf('day').toDate());
132
134
  // Set the pending focus date to ensure proper focus after month change
133
135
  setPendingFocusDate(formattedDate);
134
- }, [textBoxRef, triggerRef, value, defaultValue, initialViewingDate, baseFormat, setViewingValue, setPendingFocusDate]);
136
+ }, [
137
+ textBoxRef,
138
+ triggerRef,
139
+ pickerPopoverProps.value,
140
+ value,
141
+ defaultValue,
142
+ initialViewingDate,
143
+ baseFormat,
144
+ setViewingValue,
145
+ setPendingFocusDate,
146
+ ]);
135
147
  return (_jsx(Popover, { enableAutomaticPortalTargetResolution: true, enableViewportConstraint: enableViewportConstraint ?? false, enableAutoFocusOnPopover: false, ...popoverProps, renderContent: () => (_jsx("div", { ref: basePickerPopoverWrapperRef, className: "mfui-BasePicker__popoverWrapper", onKeyDown: handleOnKeyDown, children: renderPopoverContent({
136
148
  viewingValue,
137
149
  setViewingValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneyforward/mfui-components",
3
- "version": "3.36.0",
3
+ "version": "3.36.1",
4
4
  "description": "React UI Component Library for all Money Forward products",
5
5
  "repository": {
6
6
  "type": "git",