Skip to content

Commit 39dc799

Browse files
committed
fix: color picker in dialog
1 parent 90fbe81 commit 39dc799

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

.changeset/upset-facts-enjoy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/color-picker": patch
3+
---
4+
5+
Fix issue where clicking whitespace around content could cause it to close

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

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export function connect<T extends PropTypes>(
184184
...parts.content.attrs,
185185
id: dom.getContentId(scope),
186186
dir: prop("dir"),
187+
tabIndex: -1,
187188
"data-placement": currentPlacement,
188189
"data-state": open ? "open" : "closed",
189190
hidden: !open,

packages/machines/radio-group/src/radio-group.connect.ts

+15-21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function connect<T extends PropTypes>(
1515

1616
function getItemState(props: ItemProps): ItemState {
1717
return {
18+
value: props.value,
1819
invalid: !!props.invalid,
1920
disabled: !!props.disabled || groupDisabled,
2021
checked: context.get("value") === props.value,
@@ -25,30 +26,23 @@ export function connect<T extends PropTypes>(
2526
}
2627

2728
function getItemDataAttrs<T extends ItemProps>(props: T) {
28-
const radioState = getItemState(props)
29+
const itemState = getItemState(props)
2930
return {
30-
"data-focus": dataAttr(radioState.focused),
31-
"data-focus-visible": dataAttr(radioState.focused && context.get("focusVisible")),
32-
"data-disabled": dataAttr(radioState.disabled),
31+
"data-focus": dataAttr(itemState.focused),
32+
"data-focus-visible": dataAttr(itemState.focused && context.get("focusVisible")),
33+
"data-disabled": dataAttr(itemState.disabled),
3334
"data-readonly": dataAttr(readOnly),
34-
"data-state": radioState.checked ? "checked" : "unchecked",
35-
"data-hover": dataAttr(radioState.hovered),
36-
"data-invalid": dataAttr(radioState.invalid),
35+
"data-state": itemState.checked ? "checked" : "unchecked",
36+
"data-hover": dataAttr(itemState.hovered),
37+
"data-invalid": dataAttr(itemState.invalid),
3738
"data-orientation": prop("orientation"),
3839
"data-ssr": dataAttr(context.get("ssr")),
3940
}
4041
}
4142

4243
const focus = () => {
43-
const firstEnabledAndCheckedInput = dom.getFirstEnabledAndCheckedInputEl(scope)
44-
45-
if (firstEnabledAndCheckedInput) {
46-
firstEnabledAndCheckedInput.focus()
47-
return
48-
}
49-
50-
const firstEnabledInput = dom.getFirstEnabledInputEl(scope)
51-
firstEnabledInput?.focus()
44+
const nodeToFocus = dom.getFirstEnabledAndCheckedInputEl(scope) ?? dom.getFirstEnabledInputEl(scope)
45+
nodeToFocus?.focus()
5246
}
5347

5448
return {
@@ -139,20 +133,20 @@ export function connect<T extends PropTypes>(
139133
},
140134

141135
getItemControlProps(props) {
142-
const controlState = getItemState(props)
136+
const itemState = getItemState(props)
143137

144138
return normalize.element({
145139
...parts.itemControl.attrs,
146140
dir: prop("dir"),
147141
id: dom.getItemControlId(scope, props.value),
148-
"data-active": dataAttr(controlState.active),
142+
"data-active": dataAttr(itemState.active),
149143
"aria-hidden": true,
150144
...getItemDataAttrs(props),
151145
})
152146
},
153147

154148
getItemHiddenInputProps(props) {
155-
const inputState = getItemState(props)
149+
const itemState = getItemState(props)
156150

157151
return normalize.input({
158152
"data-ownedby": dom.getRootId(scope),
@@ -190,8 +184,8 @@ export function connect<T extends PropTypes>(
190184
send({ type: "SET_ACTIVE", value: null })
191185
}
192186
},
193-
disabled: inputState.disabled,
194-
defaultChecked: inputState.checked,
187+
disabled: itemState.disabled,
188+
defaultChecked: itemState.checked,
195189
style: visuallyHiddenStyle,
196190
})
197191
},

packages/machines/radio-group/src/radio-group.types.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -150,27 +150,31 @@ export interface ItemProps {
150150

151151
export interface ItemState {
152152
/**
153-
* Whether the radio is invalid
153+
* The value of the item
154+
*/
155+
value: string
156+
/**
157+
* Whether the item is invalid
154158
*/
155159
invalid: boolean
156160
/**
157-
* Whether the radio is disabled
161+
* Whether the item is disabled
158162
*/
159163
disabled: boolean
160164
/**
161-
* Whether the radio is checked
165+
* Whether the item is checked
162166
*/
163167
checked: boolean
164168
/**
165-
* Whether the radio is focused
169+
* Whether the item is focused
166170
*/
167171
focused: boolean
168172
/**
169-
* Whether the radio is hovered
173+
* Whether the item is hovered
170174
*/
171175
hovered: boolean
172176
/**
173-
* Whether the radio is active or pressed
177+
* Whether the item is active or pressed
174178
*/
175179
active: boolean
176180
}

0 commit comments

Comments
 (0)