Skip to content
Discussion options

You must be logged in to vote

@binhxn, the way to do this is to use the controlled API.

For example, something like:

const items = [
  { value: 'one',  title: '…', content: <></> },
  { value: 'two',  title: '…', content: <></> },
  { value: 'three',  title: '…', content: <></> },
];
const allValues = items.map(item => item.value);

function ToggleAllAccordions() {
  const [value, setValue] = useState([]);

  return (
    <>
      <button onClick={() => setValue(prev => prev.length > 0 ? [] : allValues}>Toggle all accordions</button>
      <Accordion.Root type="multiple" collapsible value={openItems} onValueChange={setOpenItems}>
        {items.map(item => <Accordion.Item value={item.value}></Accordion.Item>)}
      

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@benoitgrelard
Comment options

@binhxn
Comment options

Answer selected by binhxn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants