@xqmsg/ui-core 0.15.2 → 0.15.3
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/hooks/useOnOutsideClick.d.ts +2 -0
- package/dist/ui-core.cjs.development.js +31 -11
- package/dist/ui-core.cjs.development.js.map +1 -1
- package/dist/ui-core.cjs.production.min.js +1 -1
- package/dist/ui-core.cjs.production.min.js.map +1 -1
- package/dist/ui-core.esm.js +32 -12
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/input/StackedMultiSelect/index.tsx +3 -12
- package/src/components/input/StackedSelect/StackedSelect.tsx +2 -2
- package/src/components/input/components/dropdown/index.tsx +1 -1
- package/src/hooks/useOnOutsideClick.tsx +31 -0
|
@@ -531,7 +531,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
531
531
|
fontSize: "13px",
|
|
532
532
|
px: "8px",
|
|
533
533
|
py: "4px",
|
|
534
|
-
width: "
|
|
534
|
+
width: "100%",
|
|
535
535
|
color: colors.label.primary.light,
|
|
536
536
|
_hover: {
|
|
537
537
|
color: colors.label.primary.dark,
|
|
@@ -576,6 +576,32 @@ var useDidMountEffect = function useDidMountEffect(func, deps) {
|
|
|
576
576
|
}, deps);
|
|
577
577
|
};
|
|
578
578
|
|
|
579
|
+
function useOnClickOutside(ref, handler) {
|
|
580
|
+
React.useEffect(function () {
|
|
581
|
+
var listener = function listener(event) {
|
|
582
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
583
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
handler();
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
document.addEventListener('mousedown', listener);
|
|
591
|
+
document.addEventListener('touchstart', listener);
|
|
592
|
+
return function () {
|
|
593
|
+
document.removeEventListener('mousedown', listener);
|
|
594
|
+
document.removeEventListener('touchstart', listener);
|
|
595
|
+
};
|
|
596
|
+
}, // Add ref and handler to effect dependencies
|
|
597
|
+
// It's worth noting that because passed in handler is a new ...
|
|
598
|
+
// ... function on every render that will cause this effect ...
|
|
599
|
+
// ... callback/cleanup to run every render. It's not a big deal ...
|
|
600
|
+
// ... but to optimize you can wrap handler in useCallback before ...
|
|
601
|
+
// ... passing it into this hook.
|
|
602
|
+
[ref, handler]);
|
|
603
|
+
}
|
|
604
|
+
|
|
579
605
|
var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "value"];
|
|
580
606
|
/**
|
|
581
607
|
* A functional React component utilized to render the `StackedSelect` component.
|
|
@@ -628,11 +654,8 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
628
654
|
return option.value === value;
|
|
629
655
|
})) == null ? void 0 : _options$find2.label) != null ? _options$find$label2 : '');
|
|
630
656
|
}, [value]);
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
handler: function handler() {
|
|
634
|
-
return setIsFocussed(false);
|
|
635
|
-
}
|
|
657
|
+
useOnClickOutside(dropdownRef, function () {
|
|
658
|
+
return setIsFocussed(false);
|
|
636
659
|
});
|
|
637
660
|
|
|
638
661
|
var handleOnSelectItem = function handleOnSelectItem(option) {
|
|
@@ -812,11 +835,8 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
812
835
|
setPosition('bottom');
|
|
813
836
|
}
|
|
814
837
|
}, [boundingClientRect]);
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
handler: function handler() {
|
|
818
|
-
return setIsFocussed(false);
|
|
819
|
-
}
|
|
838
|
+
useOnClickOutside(dropdownRef, function () {
|
|
839
|
+
return setIsFocussed(false);
|
|
820
840
|
}); // gets latest watched form value (common delimited) from RHF state and creates a list
|
|
821
841
|
|
|
822
842
|
React.useEffect(function () {
|