Skip to content

Commit d68e9c0

Browse files
committed
fix(color-picker): invoke onValueChangeEnd for EyeDropper API color selection
1 parent 64cf442 commit d68e9c0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/color-picker": patch
3+
---
4+
5+
Invoke `onValueChangeEnd` when the user picks a color with the EyeDropper API, consistent with ending a drag on the area or channel sliders.

packages/machines/color-picker/src/color-picker.machine.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export const machine = createMachine<ColorPickerSchema>({
437437
},
438438
},
439439
actions: {
440-
openEyeDropper({ scope, context }) {
440+
openEyeDropper({ scope, context, prop }) {
441441
const win = scope.getWin()
442442
const isSupported = "EyeDropper" in win
443443
if (!isSupported) return
@@ -448,6 +448,13 @@ export const machine = createMachine<ColorPickerSchema>({
448448
const format = context.get("value").getFormat()
449449
const color = parseColor(sRGBHex).toFormat(format) as Color
450450
context.set("value", color)
451+
return color
452+
})
453+
.then((value) => {
454+
prop("onValueChangeEnd")?.({
455+
value,
456+
valueAsString: value.toString(context.get("format")),
457+
})
451458
})
452459
.catch(() => void 0)
453460
},

0 commit comments

Comments
 (0)