@zag-js/color-picker 1.45.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.
@@ -103,8 +103,7 @@ function connect(service, normalize) {
103
103
  },
104
104
  format: context.get("format"),
105
105
  setFormat(format2) {
106
- const formatValue = value.toFormat(format2);
107
- send({ type: "VALUE.SET", value: formatValue, src: "set-format" });
106
+ send({ type: "FORMAT.SET", format: format2, src: "set-format" });
108
107
  },
109
108
  alpha: value.getChannelValue("alpha"),
110
109
  setAlpha(alphaValue) {
@@ -76,8 +76,7 @@ function connect(service, normalize) {
76
76
  },
77
77
  format: context.get("format"),
78
78
  setFormat(format2) {
79
- const formatValue = value.toFormat(format2);
80
- send({ type: "VALUE.SET", value: formatValue, src: "set-format" });
79
+ send({ type: "FORMAT.SET", format: format2, src: "set-format" });
81
80
  },
82
81
  alpha: value.getChannelValue("alpha"),
83
82
  setAlpha(alphaValue) {
@@ -398,6 +398,8 @@ var machine = (0, import_core.createMachine)({
398
398
  type: "popover",
399
399
  exclude: dom.getTriggerEl(scope),
400
400
  defer: true,
401
+ getRootNode: scope.getRootNode,
402
+ layerStyleTargets: [() => dom.getPositionerEl(scope)],
401
403
  onInteractOutside(event) {
402
404
  prop("onInteractOutside")?.(event);
403
405
  if (event.defaultPrevented) return;
@@ -405,8 +407,8 @@ var machine = (0, import_core.createMachine)({
405
407
  },
406
408
  onPointerDownOutside: prop("onPointerDownOutside"),
407
409
  onFocusOutside: prop("onFocusOutside"),
408
- onDismiss() {
409
- send({ type: "INTERACT_OUTSIDE" });
410
+ onDismiss(event) {
411
+ send({ type: "INTERACT_OUTSIDE", focusVisible: event?.type === "keydown" });
410
412
  }
411
413
  });
412
414
  },
@@ -597,9 +599,12 @@ var machine = (0, import_core.createMachine)({
597
599
  element.focus({ preventScroll: true });
598
600
  });
599
601
  },
600
- setReturnFocus({ scope }) {
602
+ setReturnFocus({ scope, event }) {
603
+ const contentEl = dom.getContentEl(scope);
604
+ const focusOptions = getReturnFocusOptions(event);
601
605
  (0, import_dom_query.raf)(() => {
602
- dom.getTriggerEl(scope)?.focus({ preventScroll: true });
606
+ if ((0, import_dom_query.isFocusOutside)(scope.getActiveElement(), [contentEl])) return;
607
+ dom.getTriggerEl(scope)?.focus(focusOptions);
603
608
  });
604
609
  },
605
610
  syncFormatSelectElement({ context, scope }) {
@@ -639,6 +644,10 @@ function syncFormatSelect(scope, format) {
639
644
  if (!selectEl) return;
640
645
  (0, import_dom_query.raf)(() => (0, import_dom_query.setElementValue)(selectEl, format));
641
646
  }
647
+ function getReturnFocusOptions(event) {
648
+ const focusVisible = event.focusVisible ?? event.previousEvent?.focusVisible;
649
+ return focusVisible ? { preventScroll: true, focusVisible: true } : { preventScroll: true };
650
+ }
642
651
  // Annotate the CommonJS export names for ESM import in node:
643
652
  0 && (module.exports = {
644
653
  machine
@@ -6,6 +6,7 @@ import {
6
6
  disableTextSelection,
7
7
  dispatchInputValueEvent,
8
8
  getInitialFocus,
9
+ isFocusOutside,
9
10
  raf,
10
11
  setElementValue,
11
12
  trackFormControl,
@@ -372,6 +373,8 @@ var machine = createMachine({
372
373
  type: "popover",
373
374
  exclude: dom.getTriggerEl(scope),
374
375
  defer: true,
376
+ getRootNode: scope.getRootNode,
377
+ layerStyleTargets: [() => dom.getPositionerEl(scope)],
375
378
  onInteractOutside(event) {
376
379
  prop("onInteractOutside")?.(event);
377
380
  if (event.defaultPrevented) return;
@@ -379,8 +382,8 @@ var machine = createMachine({
379
382
  },
380
383
  onPointerDownOutside: prop("onPointerDownOutside"),
381
384
  onFocusOutside: prop("onFocusOutside"),
382
- onDismiss() {
383
- send({ type: "INTERACT_OUTSIDE" });
385
+ onDismiss(event) {
386
+ send({ type: "INTERACT_OUTSIDE", focusVisible: event?.type === "keydown" });
384
387
  }
385
388
  });
386
389
  },
@@ -571,9 +574,12 @@ var machine = createMachine({
571
574
  element.focus({ preventScroll: true });
572
575
  });
573
576
  },
574
- setReturnFocus({ scope }) {
577
+ setReturnFocus({ scope, event }) {
578
+ const contentEl = dom.getContentEl(scope);
579
+ const focusOptions = getReturnFocusOptions(event);
575
580
  raf(() => {
576
- dom.getTriggerEl(scope)?.focus({ preventScroll: true });
581
+ if (isFocusOutside(scope.getActiveElement(), [contentEl])) return;
582
+ dom.getTriggerEl(scope)?.focus(focusOptions);
577
583
  });
578
584
  },
579
585
  syncFormatSelectElement({ context, scope }) {
@@ -613,6 +619,10 @@ function syncFormatSelect(scope, format) {
613
619
  if (!selectEl) return;
614
620
  raf(() => setElementValue(selectEl, format));
615
621
  }
622
+ function getReturnFocusOptions(event) {
623
+ const focusVisible = event.focusVisible ?? event.previousEvent?.focusVisible;
624
+ return focusVisible ? { preventScroll: true, focusVisible: true } : { preventScroll: true };
625
+ }
616
626
  export {
617
627
  machine
618
628
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/color-picker",
3
- "version": "1.45.0",
3
+ "version": "1.47.0",
4
4
  "description": "Core logic for the color-picker widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,14 +30,14 @@
30
30
  "url": "https://github.com/chakra-ui/zag/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@zag-js/core": "1.45.0",
34
- "@zag-js/anatomy": "1.45.0",
35
- "@zag-js/dom-query": "1.45.0",
36
- "@zag-js/dismissable": "1.45.0",
37
- "@zag-js/utils": "1.45.0",
38
- "@zag-js/color-utils": "1.45.0",
39
- "@zag-js/popper": "1.45.0",
40
- "@zag-js/types": "1.45.0"
33
+ "@zag-js/core": "1.47.0",
34
+ "@zag-js/anatomy": "1.47.0",
35
+ "@zag-js/dom-query": "1.47.0",
36
+ "@zag-js/dismissable": "1.47.0",
37
+ "@zag-js/utils": "1.47.0",
38
+ "@zag-js/color-utils": "1.47.0",
39
+ "@zag-js/popper": "1.47.0",
40
+ "@zag-js/types": "1.47.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "clean-package": "2.2.0"