Collapse 折叠面板

如果项目中使用的是 0.x 版本的基础组件(@icedesign/base, @ali/ice, @alife/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @alifd/next@latest -S

开发指南

何时使用

可以折叠/展开的内容区域。

API

Collapse

参数说明类型默认值
dataSource使用数据模型构建Array-
defaultExpandedKeys默认展开keysArray-
expandedKeys受控展开keysArray-
onExpand展开状态发升变化时候的回调签名:Function() => voidFunctionfunc.noop
disabled所有禁用Boolean-
accordion手风琴模式,一次只能打开一个Booleanfalse

Collapse.Panel

参数说明类型默认值
disabled是否禁止用户操作Boolean-
title标题ReactNode-

ARIA and KeyBoard

按键说明
Tab切换到下一个collapse panel
Space切换collapse的折叠状态

代码示例

基本

Collapse 折叠面板 - 图1

查看源码在线预览

  1. import { Collapse, Radio } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. const RadioGroup = Radio.Group;
  4. const RTL = 'rtl';
  5. const LTR = 'ltr';
  6. class App extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. rtl: false
  11. };
  12. this.handleDirectionChange = this.handleDirectionChange.bind(this);
  13. }
  14. handleDirectionChange(v) {
  15. this.setState({
  16. rtl: !this.state.rtl
  17. });
  18. }
  19. render() {
  20. return (<div>
  21. <RadioGroup dataSource={['ltr', 'rtl']} value={this.state.rtl ? 'rtl' : 'ltr'} onChange={this.handleDirectionChange} />
  22. <Collapse rtl={this.state.rtl}>
  23. <Panel title="simple tile">
  24. <ul>
  25. <li>Promotions are marketing campaigns ran by Marketplace</li>
  26. <li>Participate to sale your products during that promotion and make a profit</li>
  27. </ul>
  28. </Panel>
  29. <Panel title="What are Promotion Products?">
  30. <ul>
  31. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  32. <li>You can choose which products should be available for the promotion</li>
  33. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  34. </ul>
  35. </Panel>
  36. <Panel title="Why can i not submit a higher price?">
  37. <ul>
  38. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  39. </ul>
  40. </Panel>
  41. <Panel title="What is Promo Stock?">
  42. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo Stock value you commit to have this amount of stock available while Promotion is active.
  43. </Panel>
  44. </Collapse>
  45. </div>);
  46. }
  47. }
  48. ReactDOM.render(
  49. <App />,
  50. mountNode);

数据

Collapse 折叠面板 - 图2

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const list = [
  3. {
  4. title: 'Well, hello there',
  5. content: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
  6. disabled: true
  7. },
  8. {
  9. title: 'Gigantomaniac Monster Text, very long, much width, wow',
  10. content: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
  11. },
  12. {
  13. title: 'Generic Title',
  14. content: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
  15. },
  16. {
  17. title: 'Login Infomation',
  18. content: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
  19. }
  20. ];
  21. ReactDOM.render(<Collapse dataSource={list}/>, mountNode);

手风琴

手风琴单例模式,每次只打开一个Panel。

Collapse 折叠面板 - 图3

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. ReactDOM.render(<Collapse accordion>
  4. <Panel
  5. title="There is a long title, you can set the multiTitle to multi line display, the associated configuration properties and a single height is not the same, the specific configuration platform configuration can be configured.">
  6. <ul>
  7. <li>Promotions are marketing campaigns ran by Marketplace</li>
  8. <li>Participate to sale your products during that promotion and make a profit</li>
  9. </ul>
  10. </Panel>
  11. <Panel title="What are Promotion Products?">
  12. <ul>
  13. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a
  14. certain time range
  15. </li>
  16. <li>You can choose which products should be available for the promotion</li>
  17. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas
  18. </li>
  19. </ul>
  20. </Panel>
  21. <Panel title="Why can i not submit a higher price?">
  22. <ul>
  23. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  24. </ul>
  25. </Panel>
  26. <Panel title="What is Promo Stock?">
  27. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo
  28. Stock value you commit to have this amount of stock available while Promotion is active.
  29. </Panel>
  30. </Collapse>, mountNode);

禁用

Collapse 折叠面板 - 图4

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. ReactDOM.render(
  4. <div>
  5. <Collapse disabled>
  6. <Panel title="disable collapse">
  7. <ul>
  8. <li>Promotions are marketing campaigns ran by Marketplace</li>
  9. <li>Participate to sale your products during that promotion and make a profit</li>
  10. </ul>
  11. </Panel>
  12. <Panel title="disable collapse">
  13. <ul>
  14. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  15. <li>You can choose which products should be available for the promotion</li>
  16. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  17. </ul>
  18. </Panel>
  19. <Panel title="disable collapse">
  20. <ul>
  21. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  22. </ul>
  23. </Panel>
  24. <Panel title="disable collapse">
  25. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo Stock value you commit to have this amount of stock available while Promotion is active.
  26. </Panel>
  27. </Collapse>
  28. <br />
  29. <Collapse>
  30. <Panel title="simple title(disabled)" disabled>
  31. <ul>
  32. <li>Promotions are marketing campaigns ran by Marketplace</li>
  33. <li>Participate to sale your products during that promotion and make a profit</li>
  34. </ul>
  35. </Panel>
  36. <Panel title="What are Promotion Products?(disabled)" disabled>
  37. <ul>
  38. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  39. <li>You can choose which products should be available for the promotion</li>
  40. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  41. </ul>
  42. </Panel>
  43. <Panel title="Why can i not submit a higher price?">
  44. <ul>
  45. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  46. </ul>
  47. </Panel>
  48. <Panel title="What is Promo Stock?">
  49. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo Stock value you commit to have this amount of stock available while Promotion is active.
  50. </Panel>
  51. </Collapse>
  52. </div>,
  53. mountNode);

无障碍

组件内置了部分支持无障碍, 但是额外需要开发者手动事情才能完整支持无障碍: 给Collapse传入一个id, 组件会根据Collapse的id自动给每一个Panel生成Id。如果你想指定Panel的Id也可以, 给某个Panel传入Id属性,就会覆盖根据CollapseId生成的Id。

Collapse 折叠面板 - 图5

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. ReactDOM.render(<Collapse id="collapse-accessibility">
  4. <Panel
  5. id="panel-accessibility"
  6. title="There is a long title, you can set the multiTitle to multi line display, the associated configuration properties and a single height is not the same, the specific configuration platform configuration can be configured.">
  7. <ul>
  8. <li>Promotions are marketing campaigns ran by Marketplace</li>
  9. <li>Participate to sale your products during that promotion and make a profit</li>
  10. </ul>
  11. </Panel>
  12. <Panel title="What are Promotion Products?">
  13. <ul>
  14. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a
  15. certain time range
  16. </li>
  17. <li>You can choose which products should be available for the promotion</li>
  18. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas
  19. </li>
  20. </ul>
  21. </Panel>
  22. </Collapse>, mountNode);

事件

Collapse 折叠面板 - 图6

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. class Demo extends React.Component {
  4. constructor(props, context) {
  5. super(props, context);
  6. this.state = {
  7. expandedKeys: []
  8. };
  9. }
  10. onExpand(expandedKeys) {
  11. this.setState({
  12. expandedKeys
  13. });
  14. }
  15. onClick(key) {
  16. console.log('clicked', key);
  17. }
  18. render() {
  19. return (
  20. <Collapse onExpand={this.onExpand.bind(this)} expandedKeys={this.state.expandedKeys} >
  21. <Panel title="simple tile" onClick={this.onClick}>
  22. <ul>
  23. <li>Promotions are marketing campaigns ran by Marketplace</li>
  24. <li>Participate to sale your products during that promotion and make a profit</li>
  25. </ul>
  26. </Panel>
  27. <Panel title="What are Promotion Products?">
  28. <ul>
  29. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  30. <li>You can choose which products should be available for the promotion</li>
  31. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  32. </ul>
  33. </Panel>
  34. <Panel title="Why can i not submit a higher price?">
  35. <ul>
  36. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  37. </ul>
  38. </Panel>
  39. <Panel title="What is Promo Stock?">
  40. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo Stock value you commit to have this amount of stock available while Promotion is active.
  41. </Panel>
  42. </Collapse>
  43. );
  44. }
  45. }
  46. ReactDOM.render(<Demo />, mountNode);

基本

Collapse 折叠面板 - 图7

查看源码在线预览

  1. import { Collapse } from '@alifd/next';
  2. const Panel = Collapse.Panel;
  3. ReactDOM.render(
  4. <div>
  5. <Collapse>
  6. <Panel title="simple tile">
  7. <Collapse>
  8. <Panel title="simple tile">
  9. <ul>
  10. <li>Promotions are marketing campaigns ran by Marketplace</li>
  11. <li>Participate to sale your products during that promotion and make a profit</li>
  12. </ul>
  13. </Panel>
  14. <Panel title="What are Promotion Products?">
  15. <ul>
  16. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  17. <li>You can choose which products should be available for the promotion</li>
  18. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  19. </ul>
  20. </Panel>
  21. <Panel title="Why can i not submit a higher price?">
  22. <ul>
  23. <li>The Promotion requires a certain price to make sure that our customers are attracted</li>
  24. </ul>
  25. </Panel>
  26. <Panel title="What is Promo Stock?">
  27. Promo Stock is the criteria needed to be followed to be able to join Promotion. With setting particular Promo Stock value you commit to have this amount of stock available while Promotion is active.
  28. </Panel>
  29. </Collapse>
  30. </Panel>
  31. <Panel title="What are Promotion Products?">
  32. <ul>
  33. <li>Promotion Products is a service that helps you to promote products you list on Marketplace during a certain time range</li>
  34. <li>You can choose which products should be available for the promotion</li>
  35. <li>Not all Products of you will be available, because Promotions will only attract certain Product areas</li>
  36. </ul>
  37. </Panel>
  38. </Collapse>
  39. </div>,
  40. mountNode);

相关区块

Collapse 折叠面板 - 图8

暂无相关区块