Skip to content

Commit c9f19ce

Browse files
committed
fix: improve safari support
1 parent 7cee298 commit c9f19ce

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/little-planes-switch.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@zag-js/radio-group": patch
3+
"@zag-js/switch": patch
4+
---
5+
6+
Improve focus behavior in Safari browser

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dataAttr, visuallyHiddenStyle } from "@zag-js/dom-query"
1+
import { dataAttr, isSafari, visuallyHiddenStyle } from "@zag-js/dom-query"
22
import { isFocusVisible } from "@zag-js/focus-visible"
33
import type { NormalizeProps, PropTypes } from "@zag-js/types"
44
import { parts } from "./radio-group.anatomy"
@@ -121,6 +121,11 @@ export function connect<T extends PropTypes>(
121121
if (itemState.disabled) return
122122
send({ type: "SET_ACTIVE", value: null })
123123
},
124+
onClick() {
125+
if (!itemState.disabled && isSafari()) {
126+
dom.getItemHiddenInputEl(scope, props.value)?.focus()
127+
}
128+
},
124129
})
125130
},
126131

packages/machines/switch/src/switch.connect.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dataAttr, getEventTarget, visuallyHiddenStyle } from "@zag-js/dom-query"
1+
import { dataAttr, getEventTarget, isSafari, visuallyHiddenStyle } from "@zag-js/dom-query"
22
import { isFocusVisible } from "@zag-js/focus-visible"
33
import type { NormalizeProps, PropTypes } from "@zag-js/types"
44
import { parts } from "./switch.anatomy"
@@ -58,6 +58,9 @@ export function connect<T extends PropTypes>(service: SwitchService, normalize:
5858
if (target === dom.getHiddenInputEl(scope)) {
5959
event.stopPropagation()
6060
}
61+
if (isSafari()) {
62+
dom.getHiddenInputEl(scope)?.focus()
63+
}
6164
},
6265
})
6366
},

0 commit comments

Comments
 (0)