Skip to content

Add support for api.setDisabled? #1245

Answered by segunadebayo
amirzahavi asked this question in Q&A
Discussion options

You must be logged in to vote

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}>...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amirzahavi
Comment options

Answer selected by amirzahavi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1244 on February 12, 2024 19:38.