List groups are a flexible and powerful component for displaying not only simple lists of elements, but complex ones with custom content.
<ListGroup> <ListGroupItem>Item 1</ListGroupItem> <ListGroupItem>Item 2</ListGroupItem> <ListGroupItem>...</ListGroupItem> </ListGroup>;
Set the href
or onClick
prop on ListGroupItem
, to create a linked or clickable element.
function alertClicked() { alert('You clicked the third ListGroupItem'); } render( <ListGroup> <ListGroupItem href="#link1">Link 1</ListGroupItem> <ListGroupItem href="#link2">Link 2</ListGroupItem> <ListGroupItem onClick={alertClicked}>Trigger an alert</ListGroupItem> </ListGroup> );
Set the active
or disabled
prop to true
to mark or disable the item.
<ListGroup> <ListGroupItem href="#" active> Link 1 </ListGroupItem> <ListGroupItem href="#">Link 2</ListGroupItem> <ListGroupItem href="#" disabled> Link 3 </ListGroupItem> </ListGroup>;
Set the bsStyle
prop to style the item
<ListGroup> <ListGroupItem bsStyle="success">Success</ListGroupItem> <ListGroupItem bsStyle="info">Info</ListGroupItem> <ListGroupItem bsStyle="warning">Warning</ListGroupItem> <ListGroupItem bsStyle="danger">Danger</ListGroupItem> </ListGroup>;
Set the header
prop to create a structured item, with a heading and a body area.
<ListGroup> <ListGroupItem header="Heading 1">Some body text</ListGroupItem> <ListGroupItem header="Heading 2" href="#"> Linked item </ListGroupItem> <ListGroupItem header="Heading 3" bsStyle="danger"> Danger styling </ListGroupItem> </ListGroup>;
When using ListGroupItems directly, ListGroup looks at whether the items have href or onClick props to determine which DOM elements to emit. However, with custom item components as children to ListGroup
, set thecomponentClass
prop to specify which element ListGroup
should output.
function CustomComponent({ children }) { return ( <li className="list-group-item" onClick={() => {}}> {children} </li> ); } render( <ListGroup componentClass="ul"> <CustomComponent>Custom Child 1</CustomComponent> <CustomComponent>Custom Child 2</CustomComponent> <CustomComponent>Custom Child 3</CustomComponent> </ListGroup> );
Name | Type | Default | Description |
---|---|---|---|
componentClass | elementType | You can use a custom element type for this component. If not specified, it will be treated as | |
bsClass | string | 'list-group' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
active | any | ||
disabled | any | ||
header | node | ||
listItem | boolean | false | |
onClick | function | ||
href | string | ||
type | string | ||
bsStyle | one of: "success" , "warning" , "danger" , "info" | Component visual or contextual style variants. | |
bsClass | string | 'list-group-item' | Base CSS class and prefix for the component. Generally one should only change |