Add support for api.setDisabled
?
#1245
-
🚀 Feature request
First of all thank you for this amazing project! ❤️ 🧱 Problem Statement / Justification
I'm using SolidJs and to sync props change i'm using import * as radio from '@zag-js/radio-group';
import { normalizeProps, useMachine } from '@zag-js/solid';
export function RadioGroup(props){
const [state, send] = useMachine(
radio.machine({ ...props, id: createUniqueId() })
);
const api = createMemo(() => radio.connect(state, send, normalizeProps));
createEffect(() => {
if (props.value) {
api().setValue(props.value);
}
});
return <div {...api().rootProps}>...</div>
}
} when disable prop is changed there is no way for me to disable the component dynamically. ✅ Proposed solution or API
add ↩️ Alternatives
it could be that the import {mergeProps} from 'solid-js';
import * as radio from '@zag-js/radio-group';
import { normalizeProps, useMachine } from '@zag-js/solid';
export function RadioGroup(props){
const machineProps = mergeProps(props, {
id: createUniqueId(),
})
const [state, send] = useMachine(
radio.machine(machineProps)
);
// rest of comp.
} 📝 Additional Information
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @amirzahavi, We could improve the doc a bit more, but you can already do that with the following snippet. import * as radio from '@zag-js/radio-group';
import { normalizeProps, useMachine } from '@zag-js/solid';
import { splitProps } from 'solid-js'
export function RadioGroup(props){
// 1. Split the props you need to be reactive
const [contextProps, localProps] = splitProps(props, ["value", "disabled"])
const [state, send] = useMachine(
radio.machine({ id: createUniqueId() }),
// 2. Transiently update the machine with the props
{ context: contextProps }
);
const api = createMemo(() => radio.connect(state, send, normalizeProps));
return <div {...api().rootProps}>...</div>
}
} Related Docs: https://zagjs.com/overview/programmatic-control#transient-updates |
Beta Was this translation helpful? Give feedback.
Hi @amirzahavi,
We could improve the doc a bit more, but you can already do that with the following snippet.