Your search did not match any results.
Accordion

Accordion

Documentation

The Accordion component contains several panels displayed one under another. These panels can be collapsed or expanded by a user, which makes this component very useful for presenting information in a limited amount of space.

Backend API
Copy to CodeSandBox
Apply
Reset
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="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></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: 'http://www.nowebsitesupermart.com', }, { 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: 'http://www.nowebsitedepot.com', }, { 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: 'http://www.nowebsitemusic.com', }, { 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: 'http://www.nowebsitetomsclub.com', }]; export default { getCompanies() { return companies; }, };
window.config = { transpiler: 'plugin-babel', meta: { 'devextreme/localization.js': { 'esModule': true, }, }, paths: { 'npm:': 'https://unpkg.com/', }, 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.7.2/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.3/cjs', 'devextreme-react': 'npm:devextreme-react@21.2.3', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.5.5/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.1.37/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@3.1.24/dist/dx-gantt.js', '@devextreme/vdom': 'npm:@devextreme/vdom@2.2.3', '@devextreme/runtime': 'npm:@devextreme/runtime@2.3.8', 'inferno': 'npm:inferno@7.4.10/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat@7.4.10/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.10/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom@1.0.7/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.10/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode@7.4.10/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class@7.4.10/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras@7.4.10/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/vdom': { 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.8/inferno/package.json', ], babelOptions: { sourceMaps: false, stage0: true, react: true, }, }; System.config(window.config);