@norges-domstoler/dds-components 0.0.0-dev-20260817100430 → 0.0.0-dev-20260817113506
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.
- package/dist/index.cjs +28 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +28 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -5768,7 +5768,8 @@ const CalendarPopoverContext = createContext({
|
|
|
5768
5768
|
closeButtonRef: null,
|
|
5769
5769
|
isOpen: false,
|
|
5770
5770
|
onClose: () => null,
|
|
5771
|
-
showWeekNumbers: true
|
|
5771
|
+
showWeekNumbers: true,
|
|
5772
|
+
closeOtherCalendars: () => null
|
|
5772
5773
|
});
|
|
5773
5774
|
const CalendarPopover = ({ children, onClose, ...props }) => {
|
|
5774
5775
|
const anchorRef = useRef(null);
|
|
@@ -5785,9 +5786,12 @@ const CalendarPopover = ({ children, onClose, ...props }) => {
|
|
|
5785
5786
|
});
|
|
5786
5787
|
};
|
|
5787
5788
|
const CalendarPopoverAnchor = ({ children }) => {
|
|
5788
|
-
const { anchorRef } = useContext(CalendarPopoverContext);
|
|
5789
|
+
const { anchorRef, closeOtherCalendars } = useContext(CalendarPopoverContext);
|
|
5789
5790
|
return /* @__PURE__ */ jsx("div", {
|
|
5790
5791
|
ref: anchorRef ?? void 0,
|
|
5792
|
+
onFocusCapture: closeOtherCalendars,
|
|
5793
|
+
onMouseDown: closeOtherCalendars,
|
|
5794
|
+
onPointerDown: closeOtherCalendars,
|
|
5791
5795
|
children
|
|
5792
5796
|
});
|
|
5793
5797
|
};
|
|
@@ -6465,10 +6469,30 @@ function createDOMRef(ref) {
|
|
|
6465
6469
|
const refIsFocusable = (ref) => {
|
|
6466
6470
|
return typeof ref === "object" && ref !== null && "focus" in ref;
|
|
6467
6471
|
};
|
|
6472
|
+
const closeRegistry = /* @__PURE__ */ new Map();
|
|
6473
|
+
const closeOtherCalendars = (currentInstanceId) => {
|
|
6474
|
+
for (const [instanceId, close] of closeRegistry.entries()) if (instanceId !== currentInstanceId) close();
|
|
6475
|
+
};
|
|
6468
6476
|
function DatePicker({ errorMessage, componentSize, tip, style, width, smallScreenBreakpoint, showWeekNumbers = true, clearable = false, ref, ...props }) {
|
|
6477
|
+
const instanceIdRef = useRef(Symbol("datePickerInstance"));
|
|
6478
|
+
const closeOthers = () => {
|
|
6479
|
+
closeOtherCalendars(instanceIdRef.current);
|
|
6480
|
+
};
|
|
6469
6481
|
const lang = useLanguage();
|
|
6470
6482
|
if (!lang) throw new Error("DatePicker must be used within a DdsProvider");
|
|
6471
|
-
const state = useDatePickerState(
|
|
6483
|
+
const state = useDatePickerState({
|
|
6484
|
+
...props,
|
|
6485
|
+
onOpenChange: (isOpen) => {
|
|
6486
|
+
if (isOpen) closeOthers();
|
|
6487
|
+
props.onOpenChange?.(isOpen);
|
|
6488
|
+
}
|
|
6489
|
+
});
|
|
6490
|
+
useEffect(() => {
|
|
6491
|
+
closeRegistry.set(instanceIdRef.current, state.close);
|
|
6492
|
+
return () => {
|
|
6493
|
+
closeRegistry.delete(instanceIdRef.current);
|
|
6494
|
+
};
|
|
6495
|
+
}, [state.close]);
|
|
6472
6496
|
const domRef = useFocusManagerRef(ref && refIsFocusable(ref) ? ref : null);
|
|
6473
6497
|
const internalRef = useRef(null);
|
|
6474
6498
|
const combinedRef = useCombinedRef(internalRef, domRef);
|
|
@@ -6487,6 +6511,7 @@ function DatePicker({ errorMessage, componentSize, tip, style, width, smallScree
|
|
|
6487
6511
|
isOpen: state.isOpen,
|
|
6488
6512
|
onClose: state.close,
|
|
6489
6513
|
showWeekNumbers,
|
|
6514
|
+
closeOtherCalendars: closeOthers,
|
|
6490
6515
|
children: [/* @__PURE__ */ jsx(CalendarPopoverAnchor, { children: /* @__PURE__ */ jsx(DateField, {
|
|
6491
6516
|
...fieldProps,
|
|
6492
6517
|
groupProps,
|