@zag-js/popover 0.78.1 → 0.78.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.
package/dist/index.js CHANGED
@@ -6,9 +6,9 @@ var popper = require('@zag-js/popper');
6
6
  var ariaHidden = require('@zag-js/aria-hidden');
7
7
  var core = require('@zag-js/core');
8
8
  var dismissable = require('@zag-js/dismissable');
9
+ var focusTrap = require('@zag-js/focus-trap');
9
10
  var removeScroll = require('@zag-js/remove-scroll');
10
11
  var utils = require('@zag-js/utils');
11
- var focusTrap = require('focus-trap');
12
12
  var types = require('@zag-js/types');
13
13
 
14
14
  // src/popover.anatomy.ts
@@ -337,29 +337,14 @@ function machine(userContext) {
337
337
  },
338
338
  trapFocus(ctx2) {
339
339
  if (!ctx2.modal) return;
340
- let trap;
341
- domQuery.nextTick(() => {
342
- const contentEl = dom.getContentEl(ctx2);
343
- if (!contentEl) return;
344
- trap = focusTrap.createFocusTrap(contentEl, {
345
- escapeDeactivates: false,
346
- allowOutsideClick: true,
347
- preventScroll: true,
348
- returnFocusOnDeactivate: true,
349
- document: dom.getDoc(ctx2),
350
- fallbackFocus: contentEl,
351
- initialFocus: domQuery.getInitialFocus({
352
- root: dom.getContentEl(ctx2),
353
- getInitialEl: ctx2.initialFocusEl,
354
- enabled: ctx2.autoFocus
355
- })
356
- });
357
- try {
358
- trap.activate();
359
- } catch {
360
- }
340
+ const contentEl = () => dom.getContentEl(ctx2);
341
+ return focusTrap.trapFocus(contentEl, {
342
+ initialFocus: () => domQuery.getInitialFocus({
343
+ root: dom.getContentEl(ctx2),
344
+ getInitialEl: ctx2.initialFocusEl,
345
+ enabled: ctx2.autoFocus
346
+ })
361
347
  });
362
- return () => trap?.deactivate();
363
348
  }
364
349
  },
365
350
  actions: {
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
- import { createScope, getFocusables, isSafari, dataAttr, proxyTabFocus, nextTick, getInitialFocus, raf } from '@zag-js/dom-query';
2
+ import { createScope, getFocusables, isSafari, dataAttr, proxyTabFocus, getInitialFocus, raf } from '@zag-js/dom-query';
3
3
  import { getPlacementStyles, getPlacement } from '@zag-js/popper';
4
4
  import { ariaHidden } from '@zag-js/aria-hidden';
5
5
  import { createMachine } from '@zag-js/core';
6
6
  import { trackDismissableElement } from '@zag-js/dismissable';
7
+ import { trapFocus } from '@zag-js/focus-trap';
7
8
  import { preventBodyScroll } from '@zag-js/remove-scroll';
8
9
  import { createSplitProps, compact } from '@zag-js/utils';
9
- import { createFocusTrap } from 'focus-trap';
10
10
  import { createProps } from '@zag-js/types';
11
11
 
12
12
  // src/popover.anatomy.ts
@@ -335,29 +335,14 @@ function machine(userContext) {
335
335
  },
336
336
  trapFocus(ctx2) {
337
337
  if (!ctx2.modal) return;
338
- let trap;
339
- nextTick(() => {
340
- const contentEl = dom.getContentEl(ctx2);
341
- if (!contentEl) return;
342
- trap = createFocusTrap(contentEl, {
343
- escapeDeactivates: false,
344
- allowOutsideClick: true,
345
- preventScroll: true,
346
- returnFocusOnDeactivate: true,
347
- document: dom.getDoc(ctx2),
348
- fallbackFocus: contentEl,
349
- initialFocus: getInitialFocus({
350
- root: dom.getContentEl(ctx2),
351
- getInitialEl: ctx2.initialFocusEl,
352
- enabled: ctx2.autoFocus
353
- })
354
- });
355
- try {
356
- trap.activate();
357
- } catch {
358
- }
338
+ const contentEl = () => dom.getContentEl(ctx2);
339
+ return trapFocus(contentEl, {
340
+ initialFocus: () => getInitialFocus({
341
+ root: dom.getContentEl(ctx2),
342
+ getInitialEl: ctx2.initialFocusEl,
343
+ enabled: ctx2.autoFocus
344
+ })
359
345
  });
360
- return () => trap?.deactivate();
361
346
  }
362
347
  },
363
348
  actions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "0.78.1",
3
+ "version": "0.78.2",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,16 +26,16 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "focus-trap": "7.6.2",
30
- "@zag-js/anatomy": "0.78.1",
31
- "@zag-js/aria-hidden": "0.78.1",
32
- "@zag-js/core": "0.78.1",
33
- "@zag-js/dom-query": "0.78.1",
34
- "@zag-js/utils": "0.78.1",
35
- "@zag-js/dismissable": "0.78.1",
36
- "@zag-js/popper": "0.78.1",
37
- "@zag-js/remove-scroll": "0.78.1",
38
- "@zag-js/types": "0.78.1"
29
+ "@zag-js/anatomy": "0.78.2",
30
+ "@zag-js/aria-hidden": "0.78.2",
31
+ "@zag-js/core": "0.78.2",
32
+ "@zag-js/dom-query": "0.78.2",
33
+ "@zag-js/utils": "0.78.2",
34
+ "@zag-js/dismissable": "0.78.2",
35
+ "@zag-js/popper": "0.78.2",
36
+ "@zag-js/remove-scroll": "0.78.2",
37
+ "@zag-js/types": "0.78.2",
38
+ "@zag-js/focus-trap": "0.78.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "clean-package": "2.2.0"