@zag-js/popover 1.46.0 → 1.47.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.
@@ -191,6 +191,7 @@ var machine = (0, import_core.createMachine)({
191
191
  pointerBlocking: prop("modal"),
192
192
  exclude: [dom.getTriggerEl(scope), ...dom.getTriggerEls(scope)].filter(Boolean),
193
193
  defer: true,
194
+ getRootNode: scope.getRootNode,
194
195
  layerStyleTargets: [() => dom.getPositionerEl(scope)],
195
196
  onEscapeKeyDown(event) {
196
197
  prop("onEscapeKeyDown")?.(event);
@@ -209,8 +210,8 @@ var machine = (0, import_core.createMachine)({
209
210
  onFocusOutside: prop("onFocusOutside"),
210
211
  persistentElements: prop("persistentElements"),
211
212
  onRequestDismiss: prop("onRequestDismiss"),
212
- onDismiss() {
213
- send({ type: "CLOSE", src: "interact-outside", restoreFocus });
213
+ onDismiss(event) {
214
+ send({ type: "CLOSE", src: "interact-outside", restoreFocus, focusVisible: event?.type === "keydown" });
214
215
  }
215
216
  });
216
217
  },
@@ -305,14 +306,15 @@ var machine = (0, import_core.createMachine)({
305
306
  const eventRestoreFocus = event.restoreFocus ?? event.previousEvent?.restoreFocus;
306
307
  if (eventRestoreFocus != null && !eventRestoreFocus) return;
307
308
  if (!prop("restoreFocus")) return;
309
+ const focusOptions = getReturnFocusOptions(event);
308
310
  (0, import_dom_query.raf)(() => {
309
311
  const finalFocusEl = prop("finalFocusEl")?.();
310
312
  if (finalFocusEl) {
311
- finalFocusEl.focus({ preventScroll: true });
313
+ finalFocusEl.focus(focusOptions);
312
314
  return;
313
315
  }
314
316
  const element = dom.getActiveTriggerEl(scope, context.get("triggerValue"));
315
- element?.focus({ preventScroll: true });
317
+ element?.focus(focusOptions);
316
318
  });
317
319
  },
318
320
  invokeOnOpen({ prop, flush }) {
@@ -331,6 +333,10 @@ var machine = (0, import_core.createMachine)({
331
333
  }
332
334
  }
333
335
  });
336
+ function getReturnFocusOptions(event) {
337
+ const focusVisible = event.focusVisible ?? event.previousEvent?.focusVisible;
338
+ return focusVisible ? { preventScroll: true, focusVisible: true } : { preventScroll: true };
339
+ }
334
340
  // Annotate the CommonJS export names for ESM import in node:
335
341
  0 && (module.exports = {
336
342
  machine
@@ -157,6 +157,7 @@ var machine = createMachine({
157
157
  pointerBlocking: prop("modal"),
158
158
  exclude: [dom.getTriggerEl(scope), ...dom.getTriggerEls(scope)].filter(Boolean),
159
159
  defer: true,
160
+ getRootNode: scope.getRootNode,
160
161
  layerStyleTargets: [() => dom.getPositionerEl(scope)],
161
162
  onEscapeKeyDown(event) {
162
163
  prop("onEscapeKeyDown")?.(event);
@@ -175,8 +176,8 @@ var machine = createMachine({
175
176
  onFocusOutside: prop("onFocusOutside"),
176
177
  persistentElements: prop("persistentElements"),
177
178
  onRequestDismiss: prop("onRequestDismiss"),
178
- onDismiss() {
179
- send({ type: "CLOSE", src: "interact-outside", restoreFocus });
179
+ onDismiss(event) {
180
+ send({ type: "CLOSE", src: "interact-outside", restoreFocus, focusVisible: event?.type === "keydown" });
180
181
  }
181
182
  });
182
183
  },
@@ -271,14 +272,15 @@ var machine = createMachine({
271
272
  const eventRestoreFocus = event.restoreFocus ?? event.previousEvent?.restoreFocus;
272
273
  if (eventRestoreFocus != null && !eventRestoreFocus) return;
273
274
  if (!prop("restoreFocus")) return;
275
+ const focusOptions = getReturnFocusOptions(event);
274
276
  raf(() => {
275
277
  const finalFocusEl = prop("finalFocusEl")?.();
276
278
  if (finalFocusEl) {
277
- finalFocusEl.focus({ preventScroll: true });
279
+ finalFocusEl.focus(focusOptions);
278
280
  return;
279
281
  }
280
282
  const element = dom.getActiveTriggerEl(scope, context.get("triggerValue"));
281
- element?.focus({ preventScroll: true });
283
+ element?.focus(focusOptions);
282
284
  });
283
285
  },
284
286
  invokeOnOpen({ prop, flush }) {
@@ -297,6 +299,10 @@ var machine = createMachine({
297
299
  }
298
300
  }
299
301
  });
302
+ function getReturnFocusOptions(event) {
303
+ const focusVisible = event.focusVisible ?? event.previousEvent?.focusVisible;
304
+ return focusVisible ? { preventScroll: true, focusVisible: true } : { preventScroll: true };
305
+ }
300
306
  export {
301
307
  machine
302
308
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "1.46.0",
3
+ "version": "1.47.0",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,16 +29,16 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/anatomy": "1.46.0",
33
- "@zag-js/aria-hidden": "1.46.0",
34
- "@zag-js/core": "1.46.0",
35
- "@zag-js/dom-query": "1.46.0",
36
- "@zag-js/utils": "1.46.0",
37
- "@zag-js/dismissable": "1.46.0",
38
- "@zag-js/popper": "1.46.0",
39
- "@zag-js/remove-scroll": "1.46.0",
40
- "@zag-js/types": "1.46.0",
41
- "@zag-js/focus-trap": "1.46.0"
32
+ "@zag-js/anatomy": "1.47.0",
33
+ "@zag-js/aria-hidden": "1.47.0",
34
+ "@zag-js/core": "1.47.0",
35
+ "@zag-js/dom-query": "1.47.0",
36
+ "@zag-js/utils": "1.47.0",
37
+ "@zag-js/dismissable": "1.47.0",
38
+ "@zag-js/popper": "1.47.0",
39
+ "@zag-js/remove-scroll": "1.47.0",
40
+ "@zag-js/types": "1.47.0",
41
+ "@zag-js/focus-trap": "1.47.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "clean-package": "2.2.0"