@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
|
-
//
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
}, [
|
|
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,
|