playbook_ui 12.26.0 → 12.26.1.pre.alpha.play716popoverkitcloseonclickissue833

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f05ba004408818dfcba9bd10157c3c88af1dd4d310795c061f333b5945fc4f5a
4
- data.tar.gz: e0634afd89ddd77122ed2a6fedf1a0af05dbc0a07e93dccae55b1e2227303cbc
3
+ metadata.gz: bc05d54c9a3beeca0cdfd89f672b2aa6a3b5ed7cd3eb0ce9fe49aad64c2c5cf4
4
+ data.tar.gz: 40811095a508f62f3b0be30ba0910c8f7bf1e0a058b3c3cef71418c2db782382
5
5
  SHA512:
6
- metadata.gz: d9c746e3c5e9e738c378c47f109c3c7ac8f069da5d04fca517dc58128053d6b02a75b0ba2d244d1f070348f856d8348438721f59708afd9b9be90ba82f66267f
7
- data.tar.gz: '050496ad839d51a4fc1e6440d9356f578cb3613b788770ffbd703b99c1f1f14d1e060e6dd7b7bc1fb878c61f5f1a697b0a8df3ddb55b8f0ee4085d047a6be9a8'
6
+ metadata.gz: 21ae38d7936b12cafb50c6fb7a6bd7a1c250359e0c375eb34e713c9127876c583f22e7b983dea3fb8c54207997ea55e15221af2dc78cc87765b99868bd22b1ba
7
+ data.tar.gz: 1253d8ba46fb06dab662b03797e95f5b82ed240d613e4d8277d1b65c185823933ac54985828fc782c05de3cd72a889902393ffb9d0445d5ca9bbb35ebf011f11
@@ -1,58 +1,16 @@
1
- //function for unchecking items in formattedData
2
- export const unCheckIt = (
3
- formattedData: { [key: string]: any }[],
4
- id: string
5
- ) => {
6
- formattedData.map((item: { [key: string]: any }) => {
7
- if (item.id === id && item.checked) {
8
- item.checked = false;
9
- }
10
- if (item.children && item.children.length > 0) {
11
- unCheckIt(item.children, id);
12
- }
13
- return item;
14
- });
15
- };
16
-
17
1
  //function to retrieve all ancestors of unchecked item and set checked to false
18
2
  export const getAncestorsOfUnchecked = (
19
- formattedData: { [key: string]: any }[],
3
+ data: { [key: string]: any }[],
20
4
  item: { [key: string]: any }
21
5
  ) => {
22
6
  if (item.parent_id) {
23
- const ancestors = filterFormattedDataById(formattedData, item.parent_id);
24
- ancestors[0].checked = false;
25
-
26
- if (ancestors[0].parent_id) {
27
- getAncestorsOfUnchecked(formattedData, ancestors[0]);
28
- }
7
+ const ancestor = filterFormattedDataById(data, item.parent_id);
8
+ ancestor[0].checked = false;
9
+ ancestor[0].parent_id && getAncestorsOfUnchecked(data, ancestor[0])
29
10
  }
11
+ return data;
30
12
  };
31
-
32
- //recursively check all child and grandchild items if parent checked
33
- export const checkedRecursive = (item: { [key: string]: any }) => {
34
- if (!item.checked) {
35
- item.checked = true;
36
- }
37
- if (item.children && item.children.length > 0) {
38
- item.children.forEach((childItem: { [key: string]: any }) => {
39
- checkedRecursive(childItem);
40
- });
41
- }
42
- };
43
-
44
- //recursively uncheck all child and grandchild items if parent unchecked
45
- export const unCheckedRecursive = (item: { [key: string]: any }) => {
46
- if (item.checked) {
47
- item.checked = false;
48
- }
49
- if (item.children && item.children.length > 0) {
50
- item.children.forEach((childItem: { [key: string]: any }) => {
51
- unCheckedRecursive(childItem);
52
- });
53
- }
54
- };
55
-
13
+
56
14
  //function is going over formattedData and returning all objects that match the
57
15
  //id of the clicked item from the dropdown
58
16
  export const filterFormattedDataById = (
@@ -64,6 +22,7 @@ export const filterFormattedDataById = (
64
22
  for (const item of data) {
65
23
  if (item.id.toLowerCase() === (term.toLowerCase())) {
66
24
  matched.push(item);
25
+ return
67
26
  }
68
27
 
69
28
  if (item.children && item.children.length > 0) {
@@ -116,97 +75,60 @@ export const getCheckedItems = (
116
75
  });
117
76
  return checkedItems;
118
77
  };
78
+
79
+ export const getDefaultCheckedItems = (treeData:{ [key: string]: any }[]) => {
80
+ const checkedDefault: { [key: string]: any }[] = [];
119
81
 
120
- export const getChildIds = (
121
- item: { [key: string]: any },
122
- defaultArray: { [key: string]: any }[]
123
- ) => {
124
- let childIds: string[] = [];
125
- item.children.forEach((child: { [key: string]: any }) => {
126
- childIds.push(child.id);
127
- if (child.children && child.children.length > 0) {
128
- const childChildIds = getChildIds(child, defaultArray);
129
- childIds.push(...childChildIds);
82
+ const traverseTree = (items:{ [key: string]: any }[]) => {
83
+ if (!Array.isArray(items)) {
84
+ return;
130
85
  }
131
- });
132
- return childIds;
133
- };
86
+ items.forEach((item:{ [key: string]: any }) => {
87
+ if (item.checked) {
88
+ if (item.children && item.children.length > 0) {
89
+ const uncheckedChildren = item.children.filter((child:{ [key: string]: any }) => !child.checked);
90
+ if (uncheckedChildren.length === 0) {
91
+ checkedDefault.push(item);
92
+ return;
93
+ }
94
+ } else {
95
+ const parent = items.find((parentItem:{ [key: string]: any }) => parentItem.id === item.parentId);
96
+ if (!parent || !parent.checked) {
97
+ checkedDefault.push(item);
98
+ }
99
+ }
100
+ }
134
101
 
135
- export const updateReturnItems = (newChecked: { [key: string]: any }[]) => {
136
- const updatedCheckedItems: { [key: string]: any }[] = [];
137
- for (const item of newChecked) {
138
- if (item.children && item.children.length > 0) {
139
- const allChildrenChecked = item.children.every(
140
- (child: { [key: string]: any }) => child.checked
141
- );
142
- if (allChildrenChecked) {
143
- updatedCheckedItems.push(item);
102
+ if (item.children && item.children.length > 0) {
103
+ traverseTree(item.children);
144
104
  }
145
- }
146
- const childItem = updatedCheckedItems.some((x) => x.id === item?.parent_id);
147
- if (!childItem) {
148
- updatedCheckedItems.push(item);
149
- }
150
- }
151
- const filteredReturn = updatedCheckedItems.filter((item) => {
152
- return !updatedCheckedItems.find(
153
- (otherItem) => otherItem.id === item.parent_id
154
- );
155
- });
156
- return filteredReturn;
105
+ });
106
+ };
107
+
108
+ traverseTree(treeData);
109
+
110
+ return checkedDefault;
157
111
  };
158
112
 
159
- export const recursiveReturnOnlyParent = (
160
- items: { [key: string]: any },
161
- formattedData: { [key: string]: any }[],
162
- defaultReturn: { [key: string]: any }[],
163
- setDefaultReturn: any
113
+ export const recursiveCheckParent = (
114
+ item: { [key: string]: any },
115
+ data:any
164
116
  ) => {
165
- const parent = filterFormattedDataById(formattedData, items.parent_id);
117
+ if (item.parent_id !== null) {
118
+ const parent = filterFormattedDataById(data, item.parent_id);
166
119
  const allChildrenChecked = parent[0].children.every(
167
120
  (child: { [key: string]: any }) => child.checked
168
121
  );
169
122
  if (allChildrenChecked) {
170
- // Only return the parent and remove its children from defaultReturn
171
123
  parent[0].checked = true;
172
- const filteredDefaultReturn = defaultReturn.filter((item) => {
173
- // Remove children of the specific parent
174
- if (
175
- parent[0].children.find(
176
- (child: { [key: string]: any }) => child.id === item.id
177
- )
178
- ) {
179
- return false;
180
- }
181
- });
182
- setDefaultReturn([...filteredDefaultReturn, parent[0]]);
183
- // Check if the parent has a parent and its children are all checked
184
124
  const parentHasParent = parent[0].parent_id !== null;
185
125
  if (parentHasParent) {
186
- recursiveReturnOnlyParent(
126
+ recursiveCheckParent(
187
127
  parent[0],
188
- formattedData,
189
- filteredDefaultReturn,
190
- setDefaultReturn
128
+ data
191
129
  );
192
130
  }
193
- } else {
194
- const checkedChildren = parent[0].children.filter(
195
- (child: { [key: string]: any }) => child.checked
196
- );
197
- const updatedDefaultReturn = [...defaultReturn, ...checkedChildren];
198
- setDefaultReturn(updatedDefaultReturn);
199
- }
200
- };
201
-
202
- export const removeChildrenIfParentChecked = (
203
- items: { [key: string]: any },
204
- defaultReturn: { [key: string]: any }[],
205
- setDefaultReturn: any
206
- ) => {
207
- const childIds = getChildIds(items, defaultReturn);
208
- const filteredDefaultArray = defaultReturn.filter(
209
- (item: { [key: string]: any }) => childIds !== item.id
210
- );
211
- setDefaultReturn([...filteredDefaultArray, items]);
212
- };
131
+ }
132
+ }
133
+ return data;
134
+ }
@@ -6,18 +6,15 @@ import Icon from "../pb_icon/_icon";
6
6
  import Checkbox from "../pb_checkbox/_checkbox";
7
7
  import FormPill from "../pb_form_pill/_form_pill";
8
8
  import CircleIconButton from "../pb_circle_icon_button/_circle_icon_button";
9
+ import { cloneDeep } from "lodash";
10
+
9
11
  import {
10
- unCheckIt,
11
12
  getAncestorsOfUnchecked,
12
- unCheckedRecursive,
13
- checkedRecursive,
14
13
  filterFormattedDataById,
15
14
  findByFilter,
16
15
  getCheckedItems,
17
- updateReturnItems,
18
- recursiveReturnOnlyParent,
19
- removeChildrenIfParentChecked,
20
- getChildIds,
16
+ getDefaultCheckedItems,
17
+ recursiveCheckParent,
21
18
  } from "./_helper_functions";
22
19
 
23
20
  type MultiLevelSelectProps = {
@@ -51,6 +48,8 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
51
48
 
52
49
  const dropdownRef = useRef(null);
53
50
 
51
+ //state for expanded property
52
+ const [expanded, setExpanded] = useState([]);
54
53
  //state for whether dropdown is open or closed
55
54
  const [isClosed, setIsClosed] = useState(true);
56
55
  //state from onchange for textinput, to use for filtering to create typeahead
@@ -58,45 +57,29 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
58
57
  //this is essentially the return that the user will get when they use the kit
59
58
  const [returnedArray, setReturnedArray] = useState([]);
60
59
  //formattedData with checked and parent_id added
61
- const [formattedData, setFormattedData] = useState(treeData);
62
- //toggle chevron in dropdown
63
- //@ts-ignore
64
- const [isToggled, setIsToggled] = useState<{ [id: number]: boolean }>({});
60
+ const [formattedData, setFormattedData] = useState([]);
65
61
  //state for return for default
66
62
  const [defaultReturn, setDefaultReturn] = useState([]);
67
63
 
68
64
  useEffect(() => {
69
- let el = document.getElementById(`pb_data_wrapper_${id}`);
70
- if (el) {
71
- el.setAttribute(
72
- "data-tree",
73
- JSON.stringify(returnAllSelected ? returnedArray : defaultReturn)
74
- );
65
+ setFormattedData(addCheckedAndParentProperty(treeData));
66
+ }, [treeData]);
67
+
68
+ useEffect(() => {
69
+ if (returnAllSelected) {
70
+ setReturnedArray(getCheckedItems(formattedData));
71
+ } else {
72
+ setDefaultReturn(getDefaultCheckedItems(formattedData));
75
73
  }
76
- returnAllSelected
77
- ? onSelect(returnedArray)
78
- : onSelect(
79
- defaultReturn.filter(
80
- (item, index, self) =>
81
- index === self.findIndex((obj) => obj.id === item.id)
82
- )
83
- );
84
- }, [returnedArray, defaultReturn]);
74
+ }, [formattedData]);
85
75
 
86
76
  useEffect(() => {
87
- //Create new formattedData array for use
88
- setFormattedData(addCheckedAndParentProperty(treeData));
89
77
  // Function to handle clicks outside the dropdown
90
78
  const handleClickOutside = (event: any) => {
91
79
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
92
80
  setIsClosed(true);
93
81
  }
94
82
  };
95
- //if any items already checked in first render, set return accordingly
96
- const initialChecked = getCheckedItems(treeData)
97
- initialChecked && returnAllSelected && setReturnedArray(initialChecked)
98
- initialChecked && !returnAllSelected && setDefaultReturn(initialChecked)
99
-
100
83
  // Attach the event listener
101
84
  window.addEventListener("click", handleClickOutside);
102
85
  // Clean up the event listener on unmount
@@ -105,11 +88,72 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
105
88
  };
106
89
  }, []);
107
90
 
91
+ const modifyRecursive = (tree: { [key: string]: any }[], check: boolean) => {
92
+ if (!Array.isArray(tree)) {
93
+ return;
94
+ }
95
+ return tree.map((item: { [key: string]: any }) => {
96
+ item.checked = check;
97
+ item.children = modifyRecursive(item.children, check);
98
+ return item;
99
+ });
100
+ };
101
+
102
+ //iterate over tree, find item and set checked or unchecked
103
+ const modifyValue = (
104
+ id: string,
105
+ tree: { [key: string]: any }[],
106
+ check: boolean
107
+ ) => {
108
+ if (!Array.isArray(tree)) {
109
+ return;
110
+ }
111
+ return tree.map((item: any) => {
112
+ if (item.id != id) item.children = modifyValue(id, item.children, check);
113
+ else {
114
+ item.checked = check;
115
+ item.children = modifyRecursive(item.children, check);
116
+ }
117
+
118
+ return item;
119
+ });
120
+ };
121
+
122
+ //clone tree, check items + children
123
+ const checkItem = (item: { [key: string]: any }) => {
124
+ const tree = cloneDeep(formattedData);
125
+ if (returnAllSelected) {
126
+ return modifyValue(item.id, tree, true);
127
+ } else {
128
+ const checkedTree = modifyValue(item.id, tree, true);
129
+ return recursiveCheckParent(item, checkedTree);
130
+ }
131
+ };
132
+
133
+ //clone tree, uncheck items + children
134
+ const unCheckItem = (item: { [key: string]: any }) => {
135
+ const tree = cloneDeep(formattedData);
136
+ if (returnAllSelected) {
137
+ return modifyValue(item.id, tree, false);
138
+ } else {
139
+ const uncheckedTree = modifyValue(item.id, tree, false);
140
+ return getAncestorsOfUnchecked(uncheckedTree, item);
141
+ }
142
+ };
143
+
144
+ //setformattedData with proper properties
145
+ const changeItem = (item: { [key: string]: any }, check: boolean) => {
146
+ const tree = check ? checkItem(item) : unCheckItem(item);
147
+ setFormattedData(tree);
148
+
149
+ return tree;
150
+ };
151
+
108
152
  //function to map over data and add parent_id + depth property to each item
109
153
  const addCheckedAndParentProperty = (
110
154
  treeData: { [key: string]: any }[],
111
155
  parent_id: string = null,
112
- depth: number = 0,
156
+ depth: number = 0
113
157
  ) => {
114
158
  if (!Array.isArray(treeData)) {
115
159
  return;
@@ -121,10 +165,14 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
121
165
  depth,
122
166
  };
123
167
  if (newItem.children && newItem.children.length > 0) {
168
+ const children =
169
+ item.checked && !returnAllSelected
170
+ ? modifyRecursive(item.children, true)
171
+ : item.children;
124
172
  newItem.children = addCheckedAndParentProperty(
125
- newItem.children,
173
+ children,
126
174
  newItem.id,
127
- depth + 1,
175
+ depth + 1
128
176
  );
129
177
  }
130
178
  return newItem;
@@ -135,37 +183,13 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
135
183
  const handlePillClose = (event: any, clickedItem: { [key: string]: any }) => {
136
184
  // prevents the dropdown from closing when clicking on the pill
137
185
  event.stopPropagation();
186
+ const updatedTree = changeItem(clickedItem, false);
138
187
  //logic for removing items from returnArray or defaultReturn when pills clicked
139
188
  if (returnAllSelected) {
140
- if (returnedArray.includes(clickedItem)) {
141
- if (clickedItem.children && clickedItem.children.length > 0) {
142
- const childrenOfChecked = getChildIds(clickedItem, returnedArray);
143
- const updatedFiltered = returnedArray
144
- .filter((item) => item !== clickedItem)
145
- .filter((item) => !childrenOfChecked.includes(item.id));
146
- setReturnedArray(updatedFiltered);
147
- } else {
148
- const updatedFiltered = returnedArray.filter(
149
- (item) => item !== clickedItem
150
- );
151
- setReturnedArray(updatedFiltered);
152
- }
153
- }
189
+ onSelect(getCheckedItems(updatedTree));
154
190
  } else {
155
- if (defaultReturn.includes(clickedItem)) {
156
- getAncestorsOfUnchecked(formattedData, clickedItem);
157
- const newChecked = getCheckedItems(formattedData);
158
- const filteredReturn = updateReturnItems(newChecked).filter(
159
- (item) => item.id !== clickedItem.id
160
- );
161
- setDefaultReturn(filteredReturn);
162
- }
163
- }
164
- if (clickedItem.children && clickedItem.children.length > 0) {
165
- unCheckedRecursive(clickedItem);
191
+ onSelect(getDefaultCheckedItems(updatedTree));
166
192
  }
167
- //logic to uncheck clickedItem in formattedData
168
- unCheckIt(formattedData, clickedItem.id);
169
193
  };
170
194
 
171
195
  //handle click on input wrapper(entire div with pills, typeahead, etc) so it doesn't close when input or form pill is clicked
@@ -181,95 +205,36 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
181
205
  };
182
206
 
183
207
  //Main function to handle any click inside dropdown
184
- const handledropdownItemClick = (e: any) => {
208
+ const handledropdownItemClick = (e: any, check: boolean) => {
185
209
  const clickedItem = e.target.parentNode.id;
186
210
  //setting filterItem to "" will clear textinput and clear typeahead
187
211
  setFilterItem("");
188
212
 
189
213
  const filtered = filterFormattedDataById(formattedData, clickedItem);
190
- //check and uncheck all children of checked/unchecked parent item
191
- if (filtered[0].children && filtered[0].children.length > 0) {
192
- if (filtered[0].checked) {
193
- filtered[0].children.forEach((item: { [key: string]: any }) => {
194
- checkedRecursive(item);
195
- });
196
- } else if (!filtered[0].checked) {
197
- filtered[0].children.forEach((item: { [key: string]: any }) => {
198
- unCheckedRecursive(item);
199
- });
200
- }
201
- }
202
-
203
- const checkedItems = getCheckedItems(formattedData);
204
-
205
- //checking and unchecking items for returnAllSelected variant
206
- if (returnedArray.includes(filtered[0])) {
207
- if (!filtered[0].checked) {
208
- if (filtered[0].children && filtered[0].children.length > 0) {
209
- const childrenOfChecked = getChildIds(filtered[0], returnedArray);
210
- const updatedFiltered = returnedArray
211
- .filter((item) => item !== filtered[0])
212
- .filter((item) => !childrenOfChecked.includes(item.id));
213
-
214
- setReturnedArray(updatedFiltered);
215
- } else {
216
- const updatedFiltered = returnedArray.filter(
217
- (item) => item !== filtered[0]
218
- );
219
- setReturnedArray(updatedFiltered);
220
- }
221
- }
214
+ const updatedTree = changeItem(filtered[0], check);
215
+ console.log(updatedTree);
216
+ if (returnAllSelected) {
217
+ onSelect(getCheckedItems(updatedTree));
222
218
  } else {
223
- setReturnedArray(checkedItems);
224
- }
225
-
226
- //when item is unchecked for default variant
227
- if (!filtered[0].checked && !returnAllSelected) {
228
- //uncheck parent and grandparent if any child unchecked
229
- getAncestorsOfUnchecked(formattedData, filtered[0]);
230
-
231
- const newChecked = getCheckedItems(formattedData);
232
- //get all checked items, and filter to check if all children checked, if yes return only parent
233
- const filteredReturn = updateReturnItems(newChecked);
234
- setDefaultReturn(filteredReturn);
235
- }
236
-
237
- //when item is checked for default variant
238
- if (!returnAllSelected && filtered[0].checked) {
239
- //if checked item has children
240
- if (filtered[0].children && filtered[0].children.length > 0) {
241
- removeChildrenIfParentChecked(
242
- filtered[0],
243
- defaultReturn,
244
- setDefaultReturn
245
- );
246
- }
247
-
248
- //if clicked item has parent_id, find parent and check if all children checked or not
249
- if (filtered[0].parent_id !== null) {
250
- recursiveReturnOnlyParent(
251
- filtered[0],
252
- formattedData,
253
- defaultReturn,
254
- setDefaultReturn
255
- );
256
- } else {
257
- setDefaultReturn([filtered[0]]);
258
- }
219
+ onSelect(getDefaultCheckedItems(updatedTree));
259
220
  }
260
221
  };
261
222
 
223
+ const isExpanded = (item: any) => expanded.indexOf(item.id) > -1;
224
+
262
225
  //handle click on chevron toggles in dropdown
263
226
  const handleToggleClick = (id: string, event: React.MouseEvent) => {
264
227
  event.stopPropagation();
265
- setIsToggled((prevState: { [id: string]: boolean }) => ({
266
- ...prevState,
267
- [id]: !prevState[id],
268
- }));
269
228
  const clickedItem = filterFormattedDataById(formattedData, id);
270
-
271
229
  if (clickedItem) {
272
- clickedItem[0].expanded = !clickedItem[0].expanded;
230
+ let expandedArray = [...expanded];
231
+ const itemExpanded = isExpanded(clickedItem[0]);
232
+
233
+ if (itemExpanded)
234
+ expandedArray = expandedArray.filter((i) => i != clickedItem[0].id);
235
+ else expandedArray.push(clickedItem[0].id);
236
+
237
+ setExpanded(expandedArray);
273
238
  }
274
239
  };
275
240
 
@@ -281,23 +246,23 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
281
246
  items.map((item: { [key: string]: any }) => {
282
247
  return (
283
248
  <>
284
- <li
285
- key={item.id}
286
- className="dropdown_item"
287
- data-name={item.id}
288
- >
249
+ <li key={item.id} className="dropdown_item" data-name={item.id}>
289
250
  <div className="dropdown_item_checkbox_row">
290
251
  <div
291
- key={
292
- item.expanded ? "chevron-down" : "chevron-right"
293
- }
252
+ key={isExpanded(item) ? "chevron-down" : "chevron-right"}
294
253
  >
295
254
  <CircleIconButton
296
255
  icon={
297
- item.expanded ? "chevron-down" : "chevron-right"
256
+ isExpanded(item) ? "chevron-down" : "chevron-right"
257
+ }
258
+ className={
259
+ item.children && item.children.length > 0
260
+ ? ""
261
+ : "toggle_icon"
262
+ }
263
+ onClick={(event: any) =>
264
+ handleToggleClick(item.id, event)
298
265
  }
299
- className={item.children && item.children.length > 0 ? "" : "toggle_icon"}
300
- onClick={(event) => handleToggleClick(item.id, event)}
301
266
  variant="link"
302
267
  />
303
268
  </div>
@@ -308,13 +273,12 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
308
273
  name={item.label}
309
274
  value={item.label}
310
275
  onChange={(e) => {
311
- item.checked = !item.checked;
312
- handledropdownItemClick(e);
276
+ handledropdownItemClick(e, !item.checked);
313
277
  }}
314
278
  />
315
279
  </Checkbox>
316
280
  </div>
317
- {item.expanded &&
281
+ {isExpanded(item) &&
318
282
  item.children &&
319
283
  item.children.length > 0 &&
320
284
  !filterItem && ( // Show children if expanded is true
@@ -339,25 +303,20 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
339
303
  key={index}
340
304
  text={item.label}
341
305
  size="small"
342
- onClick={(event) => handlePillClose(event, item)}
306
+ onClick={(event: any) => handlePillClose(event, item)}
343
307
  />
344
308
  ))
345
309
  : null}
346
310
  {!returnAllSelected &&
347
311
  defaultReturn.length !== 0 &&
348
- defaultReturn
349
- .filter(
350
- (item, index, self) =>
351
- index === self.findIndex((obj) => obj.id === item.id)
352
- )
353
- .map((item, index) => (
354
- <FormPill
355
- key={index}
356
- text={item.label}
357
- size="small"
358
- onClick={(event) => handlePillClose(event, item)}
359
- />
360
- ))}
312
+ defaultReturn.map((item, index) => (
313
+ <FormPill
314
+ key={index}
315
+ text={item.label}
316
+ size="small"
317
+ onClick={(event: any) => handlePillClose(event, item)}
318
+ />
319
+ ))}
361
320
  {returnedArray.length !== 0 && returnAllSelected && <br />}
362
321
  {defaultReturn.length !== 0 && !returnAllSelected && <br />}
363
322
  <input
@@ -171,17 +171,19 @@ const PbReactPopover = (props: PbPopoverProps) => {
171
171
 
172
172
  switch (closeOnClick) {
173
173
  case "outside":
174
- if (!targetIsPopover || targetIsReference) {
174
+ if (!targetIsPopover && !targetIsReference) {
175
175
  shouldClosePopover(true);
176
176
  }
177
177
  break;
178
178
  case "inside":
179
- if (targetIsPopover || targetIsReference) {
179
+ if (targetIsPopover) {
180
180
  shouldClosePopover(true);
181
181
  }
182
182
  break;
183
183
  case "any":
184
- shouldClosePopover(true);
184
+ if (targetIsPopover || !targetIsPopover && !targetIsReference) {
185
+ shouldClosePopover(true);
186
+ }
185
187
  break;
186
188
  }
187
189
  },
@@ -49,13 +49,16 @@ export default class PbPopover extends PbEnhancedElement {
49
49
  checkCloseTooltip() {
50
50
  document.querySelector('body').addEventListener('click', ({ target } ) => {
51
51
  const isTooltipElement = (target as HTMLElement).closest(`#${this.tooltipId}`) !== null
52
+ const isTriggerElement = (target as HTMLElement).closest(`#${this.triggerElementId}`) !== null
52
53
 
53
54
  switch (this.closeOnClick) {
54
55
  case 'any':
55
- this.hideTooltip()
56
+ if (isTooltipElement || !isTooltipElement && !isTriggerElement) {
57
+ this.hideTooltip()
58
+ }
56
59
  break
57
60
  case 'outside':
58
- if (!isTooltipElement) {
61
+ if (!isTooltipElement && !isTriggerElement) {
59
62
  this.hideTooltip()
60
63
  }
61
64
  break