vrembem 1.39.0 → 1.40.0

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.
@@ -1112,7 +1112,12 @@ function hide$2(popover, obj) {
1112
1112
  const index = obj.collection.findIndex(item => {
1113
1113
  return item.target === popover.target;
1114
1114
  });
1115
- obj.collection[index].state = 'hide'; // Return the popover
1115
+ obj.collection[index].state = 'hide'; // Clear the memory if popover trigger matches the ones saved in memory
1116
+
1117
+ if (popover.trigger === obj.memory.trigger) {
1118
+ obj.memory.trigger = null;
1119
+ } // Return the popover
1120
+
1116
1121
 
1117
1122
  return popover;
1118
1123
  }
@@ -1126,7 +1131,9 @@ function hideAll(obj) {
1126
1131
  return obj.collection;
1127
1132
  }
1128
1133
  function hideCheck(popover, obj) {
1129
- // Needed to correctly check which element is currently being focused
1134
+ // Only run hideCheck if provided popover is currently open
1135
+ if (popover.state != 'show') return; // Needed to correctly check which element is currently being focused
1136
+
1130
1137
  setTimeout(() => {
1131
1138
  // Check if trigger or target are being hovered
1132
1139
  const isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
@@ -1292,13 +1299,29 @@ function handlerClick(popover) {
1292
1299
  if (popover.target.classList.contains(this.settings.stateActive)) {
1293
1300
  hide$2(popover, this);
1294
1301
  } else {
1302
+ this.memory.trigger = popover.trigger;
1295
1303
  show(popover, this);
1296
1304
  documentClick(popover, this);
1297
1305
  }
1298
1306
  }
1299
1307
  function handlerKeydown(event) {
1300
- if (event.key === 'Escape') {
1301
- hideAll(this);
1308
+ switch (event.key) {
1309
+ case 'Escape':
1310
+ if (this.memory.trigger) {
1311
+ this.memory.trigger.focus();
1312
+ }
1313
+
1314
+ hideAll(this);
1315
+ return;
1316
+
1317
+ case 'Tab':
1318
+ this.collection.forEach(popover => {
1319
+ hideCheck(popover, this);
1320
+ });
1321
+ return;
1322
+
1323
+ default:
1324
+ return;
1302
1325
  }
1303
1326
  }
1304
1327
  function documentClick(popover, obj) {
@@ -3266,6 +3289,9 @@ class Popover {
3266
3289
  this.defaults = defaults;
3267
3290
  this.settings = _extends({}, this.defaults, options);
3268
3291
  this.collection = [];
3292
+ this.memory = {
3293
+ trigger: null
3294
+ };
3269
3295
  this.__handlerKeydown = handlerKeydown.bind(this);
3270
3296
  if (this.settings.autoInit) this.init();
3271
3297
  }