vrembem 4.0.0-next.22 → 4.0.0-next.24

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/dev/index.js CHANGED
@@ -82,29 +82,6 @@ class Collection {
82
82
  });
83
83
  }
84
84
  }
85
- const not = {
86
- inert: ":not([inert]):not([inert] *)",
87
- negTabIndex: ':not([tabindex^="-"])',
88
- disabled: ":not(:disabled)"
89
- };
90
- const focusableSelectors = [
91
- `a[href]${not.inert}${not.negTabIndex}`,
92
- `area[href]${not.inert}${not.negTabIndex}`,
93
- `input:not([type="hidden"]):not([type="radio"])${not.inert}${not.negTabIndex}${not.disabled}`,
94
- `input[type="radio"]${not.inert}${not.negTabIndex}${not.disabled}`,
95
- `select${not.inert}${not.negTabIndex}${not.disabled}`,
96
- `textarea${not.inert}${not.negTabIndex}${not.disabled}`,
97
- `button${not.inert}${not.negTabIndex}${not.disabled}`,
98
- `details${not.inert} > summary:first-of-type${not.negTabIndex}`,
99
- // Discard until Firefox supports `:has()`
100
- // See: https://github.com/KittyGiraudel/focusable-selectors/issues/12
101
- // `details:not(:has(> summary))${not.inert}${not.negTabIndex}`,
102
- `iframe${not.inert}${not.negTabIndex}`,
103
- `audio[controls]${not.inert}${not.negTabIndex}`,
104
- `video[controls]${not.inert}${not.negTabIndex}`,
105
- `[contenteditable]${not.inert}${not.negTabIndex}`,
106
- `[tabindex]${not.inert}${not.negTabIndex}`
107
- ];
108
85
  class FocusTrap {
109
86
  constructor(el = null, selectorFocus = "[data-focus]") {
110
87
  __privateAdd(this, _focusable);
@@ -154,7 +131,8 @@ class FocusTrap {
154
131
  const focusable = [];
155
132
  const initFocus = document.activeElement;
156
133
  const initScrollTop = el.scrollTop;
157
- const els = el.querySelectorAll(focusableSelectors.join(","));
134
+ const selector = focusableSelectors.join(",");
135
+ const els = el.querySelectorAll(selector);
158
136
  els.forEach((el2) => {
159
137
  el2.focus();
160
138
  if (document.activeElement === el2) {
@@ -169,6 +147,24 @@ class FocusTrap {
169
147
  _focusable = new WeakMap();
170
148
  _handleFocusTrap = new WeakMap();
171
149
  _handleFocusLock = new WeakMap();
150
+ const notInert = ":not([inert])";
151
+ const notNegTabIndex = ':not([tabindex^="-"])';
152
+ const notDisabled = ":not(:disabled)";
153
+ const focusableSelectors = [
154
+ `a[href]${notInert}${notNegTabIndex}`,
155
+ `area[href]${notInert}${notNegTabIndex}`,
156
+ `input:not([type="hidden"]):not([type="radio"])${notInert}${notNegTabIndex}${notDisabled}`,
157
+ `input[type="radio"]${notInert}${notNegTabIndex}${notDisabled}`,
158
+ `select${notInert}${notNegTabIndex}${notDisabled}`,
159
+ `textarea${notInert}${notNegTabIndex}${notDisabled}`,
160
+ `button${notInert}${notNegTabIndex}${notDisabled}`,
161
+ `details${notInert} > summary:first-of-type${notNegTabIndex}`,
162
+ `iframe${notInert}${notNegTabIndex}`,
163
+ `audio[controls]${notInert}${notNegTabIndex}`,
164
+ `video[controls]${notInert}${notNegTabIndex}`,
165
+ `[contenteditable]${notInert}${notNegTabIndex}`,
166
+ `[tabindex]${notInert}${notNegTabIndex}`
167
+ ];
172
168
  function handleFocusTrap(event) {
173
169
  const isTab = event.key === "Tab" || event.keyCode === 9;
174
170
  if (!isTab) return;
@@ -1192,6 +1188,7 @@ const defaults = {
1192
1188
  autoMount: false,
1193
1189
  // Selectors
1194
1190
  selectorPopover: ".popover",
1191
+ selectorTooltip: ".popover_tooltip",
1195
1192
  selectorArrow: ".popover__arrow",
1196
1193
  // State classes
1197
1194
  stateActive: "is-active",
@@ -1316,9 +1313,9 @@ function getPopoverElements(query) {
1316
1313
  if (!trigger && !popover) {
1317
1314
  return { error: new Error(`No popover elements found using the ID: "${id}".`) };
1318
1315
  } else if (!trigger) {
1319
- return { error: new Error("No popover trigger associated with the provided popover.") };
1316
+ return { error: new Error(`No popover trigger associated with the provided popover: "${id}".`) };
1320
1317
  } else if (!popover) {
1321
- return { error: new Error("No popover associated with the provided popover trigger.") };
1318
+ return { error: new Error(`No popover associated with the provided popover trigger: "${id}".`) };
1322
1319
  } else {
1323
1320
  return { popover, trigger };
1324
1321
  }
@@ -1329,8 +1326,9 @@ function getPopoverElements(query) {
1329
1326
  async function close(query) {
1330
1327
  const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
1331
1328
  if (popover && popover.state === "opened") {
1329
+ popover.el.inert = true;
1332
1330
  popover.el.classList.remove(this.settings.stateActive);
1333
- if (popover.trigger.hasAttribute("aria-controls")) {
1331
+ if (!popover.isTooltip) {
1334
1332
  popover.trigger.setAttribute("aria-expanded", "false");
1335
1333
  }
1336
1334
  popover.popper.setOptions({
@@ -1359,10 +1357,11 @@ async function closeAll() {
1359
1357
  function closeCheck(popover) {
1360
1358
  if (popover.state != "opened") return;
1361
1359
  setTimeout(() => {
1362
- const isHovered = popover.el.closest(":hover") === popover.el || popover.trigger.closest(":hover") === popover.trigger;
1363
- const isFocused = document.activeElement.closest(
1360
+ const isHovered = popover.el.matches(":hover") === popover.el || popover.trigger.matches(":hover") === popover.trigger;
1361
+ let isFocused = document.activeElement.closest(
1364
1362
  `#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`
1365
1363
  );
1364
+ isFocused = isFocused ? isFocused.matches(":focus-visible") : false;
1366
1365
  if (!isHovered && !isFocused) {
1367
1366
  popover.close();
1368
1367
  }
@@ -1370,6 +1369,16 @@ function closeCheck(popover) {
1370
1369
  }, 1);
1371
1370
  }
1372
1371
  function handleClick(popover) {
1372
+ const tooltipId = popover.trigger.getAttribute("aria-describedby");
1373
+ if (tooltipId) {
1374
+ const entry = this.get(tooltipId);
1375
+ if (entry.isTooltip) {
1376
+ if (entry.toggleDelayId) {
1377
+ clearTimeout(entry.toggleDelayId);
1378
+ }
1379
+ entry.close();
1380
+ }
1381
+ }
1373
1382
  if (popover.state === "opened") {
1374
1383
  popover.close();
1375
1384
  } else {
@@ -1378,7 +1387,14 @@ function handleClick(popover) {
1378
1387
  handleDocumentClick.call(this, popover);
1379
1388
  }
1380
1389
  }
1381
- function handleMouseEnter(popover) {
1390
+ function handleMouseEnter(popover, event) {
1391
+ if (event.type == "focus" && !popover.trigger.matches(":focus-visible")) {
1392
+ return;
1393
+ }
1394
+ const isExpanded = popover.trigger.getAttribute("aria-expanded");
1395
+ if (isExpanded && isExpanded == "true") {
1396
+ return;
1397
+ }
1382
1398
  if (popover.toggleDelayId) {
1383
1399
  clearTimeout(popover.toggleDelayId);
1384
1400
  }
@@ -2812,8 +2828,9 @@ function deregisterEventListeners(entry) {
2812
2828
  }
2813
2829
  async function open(query) {
2814
2830
  const popover = getPopover.call(this, query);
2831
+ popover.el.inert = false;
2815
2832
  popover.el.classList.add(this.settings.stateActive);
2816
- if (popover.trigger.hasAttribute("aria-controls")) {
2833
+ if (!popover.isTooltip) {
2817
2834
  popover.trigger.setAttribute("aria-expanded", "true");
2818
2835
  }
2819
2836
  popover.config = getConfig(popover.el, this.settings);
@@ -2840,7 +2857,7 @@ async function register(el, trigger) {
2840
2857
  popper: createPopper(trigger, el),
2841
2858
  config: getConfig(el, this.settings),
2842
2859
  get isTooltip() {
2843
- return trigger.hasAttribute("aria-describedby");
2860
+ return !!el.closest(root.settings.selectorTooltip) || el.getAttribute("role") == "tooltip";
2844
2861
  },
2845
2862
  open() {
2846
2863
  return open.call(root, this);
@@ -2852,7 +2869,10 @@ async function register(el, trigger) {
2852
2869
  return deregister.call(root, this);
2853
2870
  }
2854
2871
  };
2855
- if (entry.trigger.hasAttribute("aria-controls")) {
2872
+ if (entry.isTooltip) {
2873
+ entry.el.setAttribute("role", "tooltip");
2874
+ }
2875
+ if (!entry.isTooltip) {
2856
2876
  entry.trigger.setAttribute("aria-expanded", "false");
2857
2877
  }
2858
2878
  registerEventListeners.call(this, entry);
@@ -2860,6 +2880,8 @@ async function register(el, trigger) {
2860
2880
  if (entry.el.classList.contains(this.settings.stateActive)) {
2861
2881
  await entry.open();
2862
2882
  handleDocumentClick.call(this, entry);
2883
+ } else {
2884
+ entry.el.inert = true;
2863
2885
  }
2864
2886
  entry.popper.setOptions({
2865
2887
  placement: entry.config["placement"]
@@ -2868,7 +2890,7 @@ async function register(el, trigger) {
2868
2890
  }
2869
2891
  function registerEventListeners(entry) {
2870
2892
  if (!entry.__eventListeners) {
2871
- const eventType = entry.config["event"];
2893
+ const eventType = entry.isTooltip ? "hover" : entry.config["event"];
2872
2894
  if (eventType === "hover") {
2873
2895
  entry.__eventListeners = [{
2874
2896
  el: ["trigger"],