Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-accessible-accordion
Advanced tools
First, grab the package from npm:
npm install --save react-accessible-accordion
Then, import the editor and use it in your code. Here is a basic example:
import React from 'react';
import {
Accordion,
AccordionItem,
AccordionItemHeading,
AccordionItemButton,
AccordionItemPanel,
} from 'react-accessible-accordion';
// Demo styles, see 'Styles' section below for some notes on use.
import 'react-accessible-accordion/dist/fancy-example.css';
export default function Example() {
return (
<Accordion>
<AccordionItem>
<AccordionItemHeading>
<AccordionItemButton>
What harsh truths do you prefer to ignore?
</AccordionItemButton>
</AccordionItemHeading>
<AccordionItemPanel>
<p>
Exercitation in fugiat est ut ad ea cupidatat ut in
cupidatat occaecat ut occaecat consequat est minim minim
esse tempor laborum consequat esse adipisicing eu
reprehenderit enim.
</p>
</AccordionItemPanel>
</AccordionItem>
<AccordionItem>
<AccordionItemHeading>
<AccordionItemButton>
Is free will real or just an illusion?
</AccordionItemButton>
</AccordionItemHeading>
<AccordionItemPanel>
<p>
In ad velit in ex nostrud dolore cupidatat consectetur
ea in ut nostrud velit in irure cillum tempor laboris
sed adipisicing eu esse duis nulla non.
</p>
</AccordionItemPanel>
</AccordionItem>
</Accordion>
);
}
We strongly encourage you to write your own styles for your accordions, but we've published the styles used on our demo page to help you get up and running:
import 'react-accessible-accordion/dist/fancy-example.css';
We recommend that you copy them into your own app and modify them to suit your
needs, particularly if you're using your own className
s.
boolean
[optional, default: false
]Don't autocollapse items when expanding other items.
boolean
[optional, default: false
]Allow the only remaining expanded item to be collapsed.
string[]
[optional, default: []
]Accepts an array of strings and any AccordionItem
whose uuid
prop matches
any one of these strings will be expanded on mount.
string
[optional, default: 'accordion'
]Class(es) to apply to element.
(string[]) => void
[optional]Callback which is invoked when items are expanded or collapsed. Gets passed
uuid
s of the currently expanded AccordionItem
s.
string
[optional, default: accordion__item
]Class(es) to apply to element.
string|number
[optional]Recommended for use with onChange
. Will be auto-generated if not provided.
boolean
[optional]Enables external control of the expansion.
Warning: This may impact accessibility negatively, use at your own risk
string
[optional, default: 'accordion__heading'
]Class(es) to apply to the 'heading' element.
number
[optional, default: 3
]Semantics to apply to the 'heading' element. A value of 1
would make your
heading element hierarchically equivalent to an <h1>
tag, and likewise a value
of 6
would make it equivalent to an <h6>
tag.
string
[optional, default: 'accordion__button'
]Class(es) to apply to the 'button' element.
string
[optional, default: 'accordion__panel'
]Class(es) to apply to element.
boolean
Make the element have a region role.
({ expanded: boolean, disabled: boolean }): JSX.Element
[required](): void
Resets the internal counter for Accordion items' identifiers (including id
attributes). For use in test suites and isomorphic frameworks.
Authoring an 'accordion' component to the
WAI ARIA spec can be
complex, but React Accessible Accordion
does most of the heavy lifting for
you, including:
aria-expanded
, aria-controls
,
aria-disabled
, aria-hidden
and aria-labelledby
).role
attributes (button
, heading
, region
).tabindex
attributes.However, there's still a couple of things you need to keep in mind to remain spec-compliant:
AccordionItemHeading
component. If in doubt, use text only.aria-level
prop to your AccordionItemHeading
component, especially if you are nesting accordions. This attribute is a
signal used by assistive technologies (eg. screenreaders) to determine which
heading level (ie. h1
-h6
) to treat your heading as.If you have any questions about your implementation, then please don't be afraid to get in touch via our issues.
RAA supports React 18, and the new out-of-order streaming feature. See the CHANGELOG for details.
Those described by the WAI ARIA spec's description of an 'accordion':
An accordion is a vertically stacked set of interactive headings that each contain a title, content snippet, or thumbnail representing a section of content. The headings function as controls that enable users to reveal or hide their associated sections of content. Accordions are commonly used to reduce the need to scroll when presenting multiple sections of content on a single page.
Components which are "accordion-like" but do not match the WAI ARIA spec's description, as written above. By "accordion-like", we mean components which have collapsible items but require bespoke interactive mechanisms in order to expand, collapse and 'disable' them. This includes (but is not limited to) multi-step forms, like those seen in many cart/checkout flows, which we believe require (other) complex markup in order to be considered 'accessible'. This also includes disclosure widgets.
See "Which design patterns does this component NOT aim to solve?".
Supported browser / device versions:
Browser | Device/OS | Version |
---|---|---|
Mobile Safari | iOS | latest |
Chrome | Android | latest |
IE | Windows | 11 |
MS Edge | Windows | latest |
Chrome | Desktop | latest |
Firefox | Desktop | latest |
Safari | OSX | latest |
FAQs
Accessible Accordion component for React
We found that react-accessible-accordion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.