Socket
Socket
Sign inDemoInstall

@chakra-ui/accordion

Package Overview
Dependencies
Maintainers
2
Versions
521
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chakra-ui/accordion

A simple and accessible accordion component for React & Chakra UI


Version published
Weekly downloads
596K
increased by7.73%
Maintainers
2
Weekly downloads
 
Created

What is @chakra-ui/accordion?

@chakra-ui/accordion is a component library for creating accessible and customizable accordion components in React applications. It is part of the Chakra UI library, which provides a set of accessible, reusable, and composable React components.

What are @chakra-ui/accordion's main functionalities?

Basic Accordion

This code demonstrates a basic accordion with two sections. Each section can be expanded or collapsed by clicking on the header.

import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function BasicAccordion() {
  return (
    <Accordion>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Accordion with Multiple Expandable Sections

This code demonstrates an accordion where multiple sections can be expanded at the same time. The `allowMultiple` prop enables this functionality.

import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function MultipleExpandableAccordion() {
  return (
    <Accordion allowMultiple>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Accordion with Controlled State

This code demonstrates an accordion with controlled state. The `index` state variable controls which sections are expanded, and the `onChange` handler updates this state.

import { useState } from 'react';
import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function ControlledAccordion() {
  const [index, setIndex] = useState([0]);

  return (
    <Accordion index={index} onChange={setIndex} allowMultiple>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Other packages similar to @chakra-ui/accordion

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc