Skip to content

Commit 8233033

Browse files
glsdowntcbegley
andauthored
Add numbered ListGroup support (#895)
* Add numbered listgroup property * Add js test for numbered ListGroup * Add docs for ListGroup numbered Co-authored-by: Tom Begley <[email protected]>
1 parent 2a8721c commit 8233033

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

docs/components_page/components/list_group.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Add flush to change some of the styling, including removing borders, and roundin
3333

3434
{{example:components/list_group/flush.py:list_group}}
3535

36+
## Numbered
37+
38+
Add `numbered=True` to create an automatically numbered list group.
39+
40+
{{example:components/list_group/numbered.py:list_group}}
41+
3642
## Custom content
3743

3844
You can pass any Dash components to the children of `ListGroupItem`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import dash_bootstrap_components as dbc
2+
3+
list_group = dbc.ListGroup(
4+
[
5+
dbc.ListGroupItem("Item 1"),
6+
dbc.ListGroupItem("Item 2"),
7+
dbc.ListGroupItem("Item 3"),
8+
],
9+
numbered=True,
10+
)

src/components/listgroup/ListGroup.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const ListGroup = props => {
3434
};
3535

3636
ListGroup.defaultProps = {
37-
tag: 'ul'
37+
tag: 'ul',
38+
numbered: false
3839
};
3940

4041
ListGroup.propTypes = {
@@ -111,7 +112,12 @@ ListGroup.propTypes = {
111112
* Note that horizontal ListGroups cannot be combined with flush ListGroups,
112113
* so if flush is True then horizontal has no effect.
113114
*/
114-
horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
115+
horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
116+
117+
/**
118+
* Generate numbered list items.
119+
*/
120+
numbered: PropTypes.bool
115121
};
116122

117123
export default ListGroup;

src/components/listgroup/__tests__/ListGroup.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ describe('ListGroup', () => {
4141

4242
expect(listGroup).toHaveClass('list-group-flush');
4343
});
44+
45+
test('applies numbered styles with "numbered" prop', () => {
46+
const {
47+
container: {firstChild: listGroup}
48+
} = render(<ListGroup numbered />);
49+
50+
expect(listGroup).toHaveClass('list-group-numbered');
51+
});
4452
});

0 commit comments

Comments
 (0)