List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.
Basic Example
<ListGroup>
<ListGroup.Item>Cras justo odio</ListGroup.Item>
<ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item>
<ListGroup.Item>Morbi leo risus</ListGroup.Item>
<ListGroup.Item>Porta ac consectetur ac</ListGroup.Item>
<ListGroup.Item>Vestibulum at eros</ListGroup.Item>
</ListGroup>
Active items
Set the active prop to indicate the list groups current active selection.
<ListGroup as="ul">
<ListGroup.Item as="li" active>
Cras justo odio
</ListGroup.Item>
<ListGroup.Item as="li">Dapibus ac facilisis in</ListGroup.Item>
<ListGroup.Item as="li" disabled>
Morbi leo risus
</ListGroup.Item>
<ListGroup.Item as="li">Porta ac consectetur ac</ListGroup.Item>
</ListGroup>
Disabled items
Set the disabled prop to prevent actions on a <ListGroup.Item>. For elements that aren't naturally disable-able (like anchors) onClick handlers are added that call preventDefault to mimick disabled behavior.
<ListGroup>
<ListGroup.Item disabled>Cras justo odio</ListGroup.Item>
<ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item>
<ListGroup.Item>Morbi leo risus</ListGroup.Item>
<ListGroup.Item>Porta ac consectetur ac</ListGroup.Item>
</ListGroup>
Actionable items
Toggle the action prop to create actionable list group items, with disabled, hover and active styles. List item actions will render a <button> or <a> (depending on the presence of an href) by default but can be overridden by setting the as prop as usual.
List items actions are distinct from plain items to ensure that click or tap affordances aren't applied to non-interactive items.
function alertClicked() {
alert('You clicked the third ListGroupItem');
}
render(
<ListGroup defaultActiveKey="#link1">
<ListGroup.Item action href="#link1">
Link 1
</ListGroup.Item>
<ListGroup.Item action href="#link2" disabled>
Link 2
</ListGroup.Item>
<ListGroup.Item action onClick={alertClicked}>
This one is a button
</ListGroup.Item>
</ListGroup>,
);
Flush
Add the flush variant to remove outer borders and rounded corners to render list group items edge-to-edge in a parent container such as a Card.
<ListGroup variant="flush">
<ListGroup.Item>Cras justo odio</ListGroup.Item>
<ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item>
<ListGroup.Item>Morbi leo risus</ListGroup.Item>
<ListGroup.Item>Porta ac consectetur ac</ListGroup.Item>
</ListGroup>
Horizontal
Use the horizontal prop to make the ListGroup render horizontally. Currently horizontal list groups cannot be combined with flush list groups.
You can also use the Tab components to create ARIA compliant tabbable interfaces with the <ListGroup> component. Swap out the <Nav> component for the list group and you are good to go.
import ListGroup from 'react-bootstrap/ListGroup'Copy import code for the ListGroup component
Name
Type
Default
Description
activeKey
unknown
as
elementType
You can use a custom element type for this component.
defaultActiveKey
unknown
horizontal
true | 'sm' | 'md' | 'lg' | 'xl'
undefined
Changes the flow of the list group items from vertical to horizontal. A value of null (the default) sets it to vertical for all breakpoints; Just including the prop sets it for all breakpoints, while {sm|md|lg|xl} makes the list group horizontal starting at that breakpoint’s min-width.
onSelect
SelectCallback
variant
'flush'
undefined
Adds a variant to the list-group
bsPrefix
string
'list-group'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
ListGroup.Item
import ListGroup from 'react-bootstrap/ListGroup'Copy import code for the ListGroup component
Name
Type
Default
Description
action
boolean
Marks a ListGroupItem as actionable, applying additional hover, active and disabled styles for links and buttons.
active
boolean
false
Sets list item as active
as
elementType
<{div | a | button}>
You can use a custom element type for this component. For none action items, items render as li. For actions the default is an achor or button element depending on whether a href is provided.
disabled
boolean
false
Sets list item state as disabled
eventKey
string
A unique identifier for the Component, the eventKey makes it distinguishable from others in a set. Similar to React's key prop, in that it only needs to be unique amongst the Components siblings, not globally.
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.