Skip to content

How to open/close Accordion programmatically #824

Answered by jjenzz
irhamputra asked this question in Help
Discussion options

You must be logged in to vote

All of our components can be "controlled" if you would like to open/close them programmatically.

const [value, setValue] = React.useState('one');

return () => (
  <div>
	{/* Something outside of Accordion that controls the open content */}
    <button onClick={() => setValue('two')}>Open two</button>

    <Accordion.Root type="single" value={value} onValueChange={setValue}>
      <Accordion.Item value="one">
        <Accordion.Header>
          <Accordion.Trigger>One</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Content>
          Content for one
        <Accordion.Content>
      </Accordion.Item>
      <Accordion.Item value="two">
        <Accordion.Header>
          <

Replies: 4 comments 13 replies

Comment options

You must be logged in to vote
9 replies
@manavm1990
Comment options

@obrunofontana
Comment options

@TomasHubelbauer
Comment options

@manavm1990
Comment options

@jjenzz
Comment options

Answer selected by jjenzz
Comment options

You must be logged in to vote
4 replies
@joaom00
Comment options

@emilioaray-dev
Comment options

@jjenzz
Comment options

@jewel109
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet