@bikiran/utils 2.1.1 → 2.1.2

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.
@@ -4,9 +4,10 @@ type TProps = {
4
4
  onSearch: (search: string) => void;
5
5
  resetClick?: () => void;
6
6
  children: React.ReactNode;
7
- placeholder?: string;
7
+ placeholder: string;
8
8
  disabled?: boolean;
9
9
  className?: string;
10
+ outsideClick: boolean;
10
11
  };
11
12
  declare const FilterBarWrapper: FC<TProps>;
12
13
  export default FilterBarWrapper;
@@ -29,7 +29,7 @@ const getStrValue = (filter) => {
29
29
  }
30
30
  return (_c = JSON === null || JSON === void 0 ? void 0 : JSON.stringify(filter)) === null || _c === void 0 ? void 0 : _c.replace(/[{},"]/g, " ");
31
31
  };
32
- const FilterBarWrapper = ({ children, formData, disabled, placeholder = "Search anything...", onSearch, resetClick, className, }) => {
32
+ const FilterBarWrapper = ({ children, formData, disabled, placeholder = "Search anything...", onSearch, resetClick, className, outsideClick = true, }) => {
33
33
  const [isFilterOpen, setIsFilterOpen] = useState(false);
34
34
  // get queries
35
35
  const urlParams = new URLSearchParams(typeof window !== "undefined" ? window.location.search : "");
@@ -47,21 +47,23 @@ const FilterBarWrapper = ({ children, formData, disabled, placeholder = "Search
47
47
  }, [window.location.search]);
48
48
  // outside click
49
49
  useEffect(() => {
50
- const handleClickOutside = (e) => {
51
- var _a, _b;
52
- const isSelectClick = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.closest('[role="combobox"]')) ||
53
- ((_b = e.target) === null || _b === void 0 ? void 0 : _b.closest('[role="listbox"]'));
54
- if (ref.current &&
55
- !ref.current.contains(e.target) &&
56
- !isSelectClick) {
57
- setIsFilterOpen(false);
58
- setIsFocus(false);
59
- }
60
- };
61
- document.addEventListener("mousedown", handleClickOutside);
62
- return () => {
63
- document.removeEventListener("mousedown", handleClickOutside);
64
- };
50
+ if (outsideClick) {
51
+ const handleClickOutside = (e) => {
52
+ var _a, _b;
53
+ const isSelectClick = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.closest('[role="combobox"]')) ||
54
+ ((_b = e.target) === null || _b === void 0 ? void 0 : _b.closest('[role="listbox"]'));
55
+ if (ref.current &&
56
+ !ref.current.contains(e.target) &&
57
+ !isSelectClick) {
58
+ setIsFilterOpen(false);
59
+ setIsFocus(false);
60
+ }
61
+ };
62
+ document.addEventListener("mousedown", handleClickOutside);
63
+ return () => {
64
+ document.removeEventListener("mousedown", handleClickOutside);
65
+ };
66
+ }
65
67
  }, [ref]);
66
68
  const isOpen = isFilterOpen || isFocus;
67
69
  const handleSearch = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikiran/utils",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [