---
localeCode: en-US
order: 63
category: Show
title: List
subTitle: List
icon: doc-list
dir: column
brief: Lists display a set of related contents
---
## Demos
### How to import
```jsx import
import { List } from '@douyinfe/semi-ui';
```
### Basic Usage
You can use `size` to size list. Supported values include `large`, `default`, `Small`. Header and Footer customized.
```jsx live=true dir="column" noInline=true
import React from 'react';
import { List } from '@douyinfe/semi-ui';
class SimpleList extends React.Component {
render() {
const data = [
'Do not go gentle into that good night,',
'Old age should burn and rave at close of day;',
'Rage, rage against the dying of the light.',
];
return (
}
bordered
dataSource={data}
renderItem={item => {item}}
/>
);
}
}
render(SimpleList);
```
### Template
List.Item has a built-in template consisting of: `header`, `main`, and `extra`. The alignment of `header` and `main` set by `align` properties using one of `flex-start`(default), `flex-end`, `center`, `baseline`, and `stretch` .
```jsx live=true dir="column" noInline=true
import React from 'react';
import { List, ButtonGroup, Button, Avatar } from '@douyinfe/semi-ui';
class ContentList extends React.Component {
render() {
const data = [
// eslint-disable-next-line react/jsx-key
{`Life's but a walking shadow, a poor player, that struts and frets his hour upon the stage, and then is
heard no more; it is a tale told by an idiot, full of sound and fury, signifying nothing.`}
,
// eslint-disable-next-line react/jsx-key
Come what come may, time and the hour run through the roughest day.
,
// eslint-disable-next-line react/jsx-key
{`Where shall we three meet again in thunder, lightning, or in rain? When the hurlyburly's done, when the
battle's lost and won`}
,
];
return (
(
SE}
main={
Example
{item}
}
extra={
}
/>
)}
/>
);
}
}
render(ContentList);
```
### Layout
Use `layout` property to set list layout, one of `vertical`(default) or `horizontal`.
```jsx live=true dir="column" noInline=true
import React from 'react';
import { List, Avatar } from '@douyinfe/semi-ui';
class LayoutList extends React.Component {
render() {
const data = [
{
title: 'Title 1',
color: 'light-blue',
},
{
title: 'Title 2',
color: 'grey',
},
{
title: 'Title 3',
color: 'light-green',
},
];
return (
(
SE}
main={
{item.title}
{` Life's but a walking shadow, a poor player, that struts and frets his hour upon
the stage, and then is heard no more; it is a tale told by an idiot, full of
sound and fury, signifying nothing.`}
}
/>
)}
/>
);
}
}
render(LayoutList);
```
### Grid
Use `grid` property to set grid layout. Use `span` to set the number of occupying spaces for each item and `gutter` for spacing between items.
```jsx live=true dir="column" noInline=true
import React from 'react';
import { List, Descriptions, Rating, ButtonGroup, Button } from '@douyinfe/semi-ui';
class LayoutList extends React.Component {
render() {
const data = [
{
title: 'Platform A',
rating: 4.5,
feedbacks: 124,
},
{
title: 'Platform B',
rating: 4,
feedbacks: 108,
},
{
title: 'Platform C',
rating: 4.5,
feedbacks: 244,
},
{
title: 'Platform D',
feedbacks: 189,
},
];
const style = {
border: '1px solid var(--semi-color-border)',
backgroundColor: 'var(--semi-color-bg-2)',
borderRadius: '3px',
paddingLeft: '20px',
};
return (
);
}
}
render(DraggableList);
```
### With Pagination
You can use Pagination in combination to achieve a paged List
```jsx live=true dir="column" hideInDSM
import React, { useState } from 'react';
import { List, Pagination } from '@douyinfe/semi-ui';
() => {
const data = [
'Siege',
'The ordinary world',
'Three Body',
'Snow in the Snow',
'Saharan story',
'Those things in the Ming Dynasty',
'A little monk of Zen',
'Dune',
'The courage to be hated',
'Crime and Punishment',
'Moon and sixpence',
'The silent majority',
'First person singular',
];
const [page, onPageChange] = useState(1);
let pageSize = 4;
const getData = (page) => {
let start = (page - 1) * pageSize;
let end = page * pageSize;
return data.slice(start, end);
};
return (
{item}}
/>
onPageChange(cPage)} />
);
};
```
### With filter
You can use it by assembling Input to filter the List
```jsx live=true dir="column" hideInDSM
import React, { useState } from 'react';
import { List, Input } from '@douyinfe/semi-ui';
import { IconSearch } from '@douyinfe/semi-icons';
() => {
const data = [
'Siege',
'The ordinary world',
'Three Body',
'Snow in the Snow',
'Saharan story',
'Those things in the Ming Dynasty',
'A little monk of Zen',
'Dune',
'The courage to be hated',
'Crime and Punishment',
];
const [list, setList] = useState(data);
const onSearch = (string) => {
let newList;
if (string) {
newList = data.filter(item => item.includes(string));
} else {
newList = data;
}
setList(newList);
};
return (
updateList()}>
} style={{ marginRight: 4, color: 'var(--semi-color-info)' }}>
Add book
);
};
```
### Single or multiple selection
You can enhance the List into a list selector by combining Radio or Checkbox
```jsx live=true dir="column" hideInDSM
import React, { useState } from 'react';
import { List, Input, Button, Checkbox, Radio, RadioGroup, CheckboxGroup } from '@douyinfe/semi-ui';
() => {
const data = [
'Siege',
'The ordinary world',
'Three Body',
'Snow in the Snow',
'Saharan story',
'Those things in the Ming Dynasty',
'A little monk of Zen',
'Dune',
'The courage to be hated',
'Crime and Punishment',
'Moon and sixpence',
'The silent majority',
'First person singular',
];
const [page, onPageChange] = useState(1);
const [checkboxVal, setCV] = useState([...data[0]]);
const [radioVal, setRV] = useState(data[0]);
let pageSize = 8;
const getData = (page) => {
let start = (page - 1) * pageSize;
let end = page * pageSize;
return data.slice(start, end);
};
return (
setCV(value)}>
{item}}
/>
setRV(e.target.value)}>
{item}}
/>
);
};
```
### Keyboard events
You can monitor the keyboard events of the corresponding keys by yourself to realize the selection of different items. As in the following example, you can use the up and down arrow keys to select different items
```jsx live=true dir="column" hideInDSM
import React, { useState, useRef } from 'react';
import { List, Input, Button } from '@douyinfe/semi-ui';
() => {
const data = [
'Siege',
'The ordinary world',
'Three Body',
'Snow in the Snow ',
'Saharan story',
'Those things in the Ming Dynasty',
'A little monk of Zen',
'Dune',
'The courage to be hated',
'Crime and Punishment',
'Moon and sixpence',
'The silent majority',
'First person singular',
];
const [list, setList] = useState(data.slice(0, 10));
const [hoverIndex, setHi] = useState(-1);
const i = useRef(-1);
let changeIndex = (offset) => {
let currentIndex = i.current;
let index = currentIndex + offset;
if (index < 0) {
index = list.length - 1;
}
if (index >= list.length) {
index = 0;
}
i.current = index;
setHi(index);
};
useEffect(() => {
let keydownHandler = (event) => {
let key = event.keyCode;
switch (key) {
case 38: // KeyCode.UP
event.preventDefault();
changeIndex(-1);
break;
case 40: // KeyCode.DOWN
event.preventDefault();
changeIndex(1);
break;
default:
break;
}
};
window.addEventListener('keydown', keydownHandler);
return () => {
window.removeEventListener('keydown', keydownHandler);
};
}, []);
return (
{item}
}
/>
);
};
```
The custom styles involved in the Demo of the above book list example are as follows
```scss
.component-list-demo-booklist {
.list-item {
&:hover {
background-color: var(--semi-color-fill-0);
}
&:active {
background-color: var(--semi-color-fill-1);
}
}
}
body > .component-list-demo-drag-item {
font-size: 14px;
}
.component-list-demo-booklist-active-item {
background-color: var(--semi-color-fill-0);
}
```
## API reference
### List
| Properties | Instructions | type | Default |
| ------------ | ------------------------------------------------------------------ | -------------------------------- | ---------- |
| bordered | Toggle whether to display border | boolean | `false` |
| className | Class name | string | - |
| dataSource | List data source | any[] | - |
| emptyContent | Displayed content when empty | ReactNode | - |
| footer | Footer of list | ReactNode | - |
| grid | Grid configuration | [Grid](/en-US/basic/grid#API-reference) | - |
| header | Header of list | ReactNode | - |
| layout | Layout, one of `vertical`, `vertical` | string | `vertical` |
| loadMore | Loadmore button | ReactNode | - |
| loading | Toggle whether to display `Spin` when loading | boolean | `false` |
| renderItem | When using dataSource, you can customize rendering with renderItem | (item, ind) => ReactNode | - |
| size | Size, one of `small`, `default`, `large` | string | `default` |
| split | Toggle whether to display split line | boolean | `true` |
| style | Inline style | CSSProperties | - |
| onClick | Callback function when click an item **v>=1.0.0** | function | - |
| onRightClick | Callback function when right click an item **v>=1.0.0** | function | - |
### Listgrid props
**v>=1.7.0** Other grid properties are also supported. Refer to [Grid](/en-US/basic/grid).
| Properties | Instructions | type | Default |
| ---------- | ----------------------------------------------------------------------------- | -------------- | ------- |
| span | Number of grid spaces | number | - |
| gutter | Grid spacing | number | 0 |
| xs | `< 576px` responsive grid, a number or an object containing other attributes | number\|object | - |
| sm | `≥ 576px` responsive grid, a number or an object containing other properties | number\|object | - |
| md | `≥ 768px` responsive grid, a number or an object containing other properties | number\|object | - |
| lg | `≥ 992px` responsive grid, a number or an object containing other properties | number\|object | - |
| xl | `≥ 1200px` responsive grid, a number or an object containing other properties | number\|object | - |
| xxl | `≥ 1600px` responsive grid, a number or an object containing other properties | number\|object | - |
### List.Item
| Properties | Instructions | type | Default |
| ------------ | ------------------------------------------------------------------------------------------------------- | --------- | ------------ |
| align | Vertical alignment of header and main, one of `flex-start`, `flex-end`, `center`, `baseline`, `stretch` | string | `flex-start` |
| className | Class name | string | - |
| extra | Additional content | ReactNode | - |
| header | List item header content | ReactNode | - |
| main | List item body content | ReactNode | - |
| onClick | Callback function when click an item **v>=1.0.0** | function | - |
| onRightClick | Callback function when right click an item **v>=1.0.0** | function | - |
| style | Inline style | CSSProperties | - |
## Content Guidelines
- Capitalize the first letter
- do not follow punctuation at the end
- Grammatical parallelism: mixed use of active and passive, declarative and imperative sentences
## Design Tokens