@norges-domstoler/dds-components 0.0.0-dev-20260817111025 → 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 +3 -3
package/dist/index.cjs
CHANGED
|
@@ -5801,7 +5801,8 @@ const CalendarPopoverContext = (0, react.createContext)({
|
|
|
5801
5801
|
closeButtonRef: null,
|
|
5802
5802
|
isOpen: false,
|
|
5803
5803
|
onClose: () => null,
|
|
5804
|
-
showWeekNumbers: true
|
|
5804
|
+
showWeekNumbers: true,
|
|
5805
|
+
closeOtherCalendars: () => null
|
|
5805
5806
|
});
|
|
5806
5807
|
const CalendarPopover = ({ children, onClose, ...props }) => {
|
|
5807
5808
|
const anchorRef = (0, react.useRef)(null);
|
|
@@ -5818,9 +5819,12 @@ const CalendarPopover = ({ children, onClose, ...props }) => {
|
|
|
5818
5819
|
});
|
|
5819
5820
|
};
|
|
5820
5821
|
const CalendarPopoverAnchor = ({ children }) => {
|
|
5821
|
-
const { anchorRef } = (0, react.useContext)(CalendarPopoverContext);
|
|
5822
|
+
const { anchorRef, closeOtherCalendars } = (0, react.useContext)(CalendarPopoverContext);
|
|
5822
5823
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5823
5824
|
ref: anchorRef ?? void 0,
|
|
5825
|
+
onFocusCapture: closeOtherCalendars,
|
|
5826
|
+
onMouseDown: closeOtherCalendars,
|
|
5827
|
+
onPointerDown: closeOtherCalendars,
|
|
5824
5828
|
children
|
|
5825
5829
|
});
|
|
5826
5830
|
};
|
|
@@ -6498,10 +6502,30 @@ function createDOMRef(ref) {
|
|
|
6498
6502
|
const refIsFocusable = (ref) => {
|
|
6499
6503
|
return typeof ref === "object" && ref !== null && "focus" in ref;
|
|
6500
6504
|
};
|
|
6505
|
+
const closeRegistry = /* @__PURE__ */ new Map();
|
|
6506
|
+
const closeOtherCalendars = (currentInstanceId) => {
|
|
6507
|
+
for (const [instanceId, close] of closeRegistry.entries()) if (instanceId !== currentInstanceId) close();
|
|
6508
|
+
};
|
|
6501
6509
|
function DatePicker({ errorMessage, componentSize, tip, style, width, smallScreenBreakpoint, showWeekNumbers = true, clearable = false, ref, ...props }) {
|
|
6510
|
+
const instanceIdRef = (0, react.useRef)(Symbol("datePickerInstance"));
|
|
6511
|
+
const closeOthers = () => {
|
|
6512
|
+
closeOtherCalendars(instanceIdRef.current);
|
|
6513
|
+
};
|
|
6502
6514
|
const lang = useLanguage();
|
|
6503
6515
|
if (!lang) throw new Error("DatePicker must be used within a DdsProvider");
|
|
6504
|
-
const state = (0, _react_stately_datepicker.useDatePickerState)(
|
|
6516
|
+
const state = (0, _react_stately_datepicker.useDatePickerState)({
|
|
6517
|
+
...props,
|
|
6518
|
+
onOpenChange: (isOpen) => {
|
|
6519
|
+
if (isOpen) closeOthers();
|
|
6520
|
+
props.onOpenChange?.(isOpen);
|
|
6521
|
+
}
|
|
6522
|
+
});
|
|
6523
|
+
(0, react.useEffect)(() => {
|
|
6524
|
+
closeRegistry.set(instanceIdRef.current, state.close);
|
|
6525
|
+
return () => {
|
|
6526
|
+
closeRegistry.delete(instanceIdRef.current);
|
|
6527
|
+
};
|
|
6528
|
+
}, [state.close]);
|
|
6505
6529
|
const domRef = useFocusManagerRef(ref && refIsFocusable(ref) ? ref : null);
|
|
6506
6530
|
const internalRef = (0, react.useRef)(null);
|
|
6507
6531
|
const combinedRef = useCombinedRef(internalRef, domRef);
|
|
@@ -6520,6 +6544,7 @@ function DatePicker({ errorMessage, componentSize, tip, style, width, smallScree
|
|
|
6520
6544
|
isOpen: state.isOpen,
|
|
6521
6545
|
onClose: state.close,
|
|
6522
6546
|
showWeekNumbers,
|
|
6547
|
+
closeOtherCalendars: closeOthers,
|
|
6523
6548
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarPopoverAnchor, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateField, {
|
|
6524
6549
|
...fieldProps,
|
|
6525
6550
|
groupProps,
|