Your search did not match any results.


The Accordion component contains several panels displayed one under another. Users can expand or collapse these panels, which makes this component useful to present information in a limited amount of space.

Bind Accordion to Data

You can display Accordion items from the items array or a dataSource. If you use the items array, specify the title and text properties.

Configure Item Selection and Collapsibility

Enable the multiple property to allow users to select multiple panels. Use the selectedItems array to store selected items. Toggle the "Multiple enabled" checkbox in the Options demo section to see how it affects the selection.

If you want to allow users to close panels on click, set the collapsible property to true. Check the "Collapsible enabled" checkbox in the Options demo section to enable this feature.

Configure Animation

The animationDuration property allows you to specify the animation duration when users expand/collapse a panel. Use the "Animation duration" slider in the Options demo section to see how it affects the animation.

Customize Item Appearance

Use the itemTemplate and itemTitleTemplate properties to customize the panel appearance. If you use the items array, you can also specify the icon property.

Backend API
Copy to CodeSandBox
import React from 'react'; import Accordion from 'devextreme-react/accordion'; import CheckBox from 'devextreme-react/check-box'; import TagBox from 'devextreme-react/tag-box'; import Slider, { Tooltip, Label } from 'devextreme-react/slider'; import service from './data.js'; import CustomTitle from './CustomTitle.js'; import CustomItem from './CustomItem.js'; class App extends React.Component { constructor(props) { super(props); this.companies = service.getCompanies(); this.state = { selectedItems: [this.companies[0]], multiple: false, collapsible: false, animationDuration: 300, }; this.selectionChanged = this.selectionChanged.bind(this); this.selectedItemsChanged = this.selectedItemsChanged.bind(this); this.multipleChanged = this.multipleChanged.bind(this); this.collapsibleChanged = this.collapsibleChanged.bind(this); this.animationDurationChanged = this.animationDurationChanged.bind(this); } render() { const { selectedItems, multiple, collapsible, animationDuration, } = this.state; return ( <div id="accordion"> <Accordion dataSource={this.companies} collapsible={collapsible} multiple={multiple} animationDuration={animationDuration} selectedItems={selectedItems} onSelectionChanged={this.selectionChanged} itemTitleRender={CustomTitle} itemRender={CustomItem} /> <div className="selected-data"> <span className="caption">Selected Items</span> <TagBox dataSource={this.companies} displayExpr="CompanyName" value={selectedItems} onValueChanged={this.selectedItemsChanged} disabled={!multiple} /> </div> <div className="options"> <div className="caption">Options</div> <div className="option"> <CheckBox text="Multiple enabled" value={multiple} onValueChanged={this.multipleChanged} /> </div> <div className="option"> <CheckBox text="Collapsible enabled" value={collapsible} onValueChanged={this.collapsibleChanged} /> </div> <div className="option"> <span>Animation duration</span> <Slider min={0} max={1000} value={animationDuration} onValueChanged={this.animationDurationChanged} > <Tooltip enabled={true} position="bottom" /> <Label visible={true} /> </Slider> </div> </div> </div> ); } selectionChanged(e) { let newItems = [...this.state.selectedItems]; e.removedItems.forEach((item) => { const index = newItems.indexOf(item); if (index >= 0) { newItems.splice(index, 1); } }); if (e.addedItems.length) { newItems = [...newItems, ...e.addedItems]; } this.setState({ selectedItems: newItems, }); } selectedItemsChanged(e) { this.setState({ selectedItems: e.value, }); } multipleChanged(e) { this.setState({ multiple: e.value, }); } collapsibleChanged(e) { this.setState({ collapsible: e.value, }); } animationDurationChanged(e) { this.setState({ animationDuration: e.value, }); } } export default App;
import React from 'react'; export default function CustomItem(data) { return ( <div> <div> <p> <b>{data.City} </b> (<span>{data.State}</span>) </p> <p> <span>{data.Zipcode} </span> <span>{data.Address}</span> </p> </div> <div> <p> Phone: <b>{data.Phone}</b> </p> <p> Fax: <b>{data.Fax}</b> </p> <p> Website: <a href={data.Website} target="_blank"> {data.Website} </a> </p> </div> </div> ); }
import React from 'react'; export default function CustomTitle(data) { return ( <h1>{data.CompanyName}</h1> ); }
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app'), );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src=""></script> <script src=""></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import("./index.js"); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
#accordion h1 { font-size: 20px; } #accordion h1, #accordion p { margin: 0; } .dx-theme-material #accordion .dx-accordion-item-title { display: flex; } .dx-theme-material #accordion h1 { align-self: center; } .options, .selected-data { padding: 20px; background-color: rgba(191, 191, 191, 0.15); margin-top: 20px; } .selected-data { position: relative; height: 36px; } .selected-data > .caption { position: relative; top: 5px; margin-right: 10px; font-weight: bold; font-size: 115%; } .selected-data > .dx-widget { position: absolute; left: 140px; right: 20px; top: 20px; } .options > .caption { font-weight: 500; font-size: 18px; } .option { margin-top: 10px; }
const companies = [{ ID: 1, CompanyName: 'Super Mart of the West', Address: '702 SW 8th Street', City: 'Bentonville', State: 'Arkansas', Zipcode: 72716, Phone: '(800) 555-2797', Fax: '(800) 555-2171', Website: '', }, { ID: 2, CompanyName: 'Electronics Depot', Address: '2455 Paces Ferry Road NW', City: 'Atlanta', State: 'Georgia', Zipcode: 30339, Phone: '(800) 595-3232', Fax: '(800) 595-3231', Website: '', }, { ID: 3, CompanyName: 'K&S Music', Address: '1000 Nicllet Mall', City: 'Minneapolis', State: 'Minnesota', Zipcode: 55403, Phone: '(612) 304-6073', Fax: '(612) 304-6074', Website: '', }, { ID: 4, CompanyName: "Tom's Club", Address: '999 Lake Drive', City: 'Issaquah', State: 'Washington', Zipcode: 98027, Phone: '(800) 955-2292', Fax: '(800) 955-2293', Website: '', }]; export default { getCompanies() { return companies; }, };
window.config = { transpiler: 'plugin-babel', meta: { 'devextreme/localization.js': { 'esModule': true, }, }, paths: { 'npm:': '', }, defaultExtension: 'js', map: { 'react': 'npm:react@17.0.2/umd/react.development.js', 'react-dom': 'npm:react-dom@17.0.2/umd/react-dom.development.js', 'prop-types': 'npm:prop-types@15.8.1/prop-types.js', 'rrule': 'npm:rrule@2.6.6/dist/es5/rrule.js', 'luxon': 'npm:luxon@1.28.0/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@21.2.7/cjs', 'devextreme-react': 'npm:devextreme-react@21.2.7', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.5.14/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.1.47/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@4.0.13/dist/dx-gantt.js', '@devextreme/runtime': 'npm:@devextreme/runtime@2.3.14', 'inferno': 'npm:inferno@7.4.11/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat@7.4.11/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.11/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.11/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode@7.4.11/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class@7.4.11/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras@7.4.11/dist/inferno-extras.min.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0.0.25/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js', }, packages: { 'devextreme': { defaultExtension: 'js', }, 'devextreme-react': { main: 'index.js', }, 'devextreme/events/utils': { main: 'index', }, 'devextreme/events': { main: 'index', }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js', }, }, packageConfigPaths: [ 'npm:@devextreme/*/package.json', 'npm:@devextreme/runtime@2.3.14/inferno/package.json', ], babelOptions: { sourceMaps: false, stage0: true, react: true, }, }; System.config(window.config);