Skip to content

Commit 5d35c6c

Browse files
committed
fix(list-group): include item object into "onSelect" argument list
1 parent c2c32c4 commit 5d35c6c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

demo/ListGroupExamples.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function ListGroupExamples() {
3535
{item.description}
3636
</>
3737
)}
38+
onSelect={console.warn}
3839
/>
3940
</div>
4041
<div className="col-6 mb-3">

src/list-group/ListGroupItem.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { safeClick } from '../utils/event-handlers';
44

5-
export function ListGroupItem({ index, isActive, children, linked, isDisabled, onSelect }) {
5+
export function ListGroupItem({ index, isActive, isDisabled, item, linked, onSelect, children }) {
66
const classes = [
77
'list-group-item',
88
isActive && 'active',
@@ -12,16 +12,18 @@ export function ListGroupItem({ index, isActive, children, linked, isDisabled, o
1212
.filter((v) => v)
1313
.join(' ');
1414

15+
const onClick = safeClick(onSelect, index, item);
16+
1517
if (linked) {
1618
return (
17-
<a href="#" className={classes} onClick={safeClick(onSelect, index)}>
19+
<a href="#" className={classes} onClick={onClick}>
1820
{children}
1921
</a>
2022
);
2123
}
2224

2325
return (
24-
<li className={classes} onClick={safeClick(onSelect, index)}>
26+
<li className={classes} onClick={onClick}>
2527
{children}
2628
</li>
2729
);
@@ -36,6 +38,7 @@ ListGroupItem.propTypes = {
3638
index: PropTypes.number.isRequired,
3739
isActive: PropTypes.bool,
3840
isDisabled: PropTypes.bool,
41+
item: PropTypes.object.isRequired,
3942
linked: PropTypes.bool.isRequired,
4043
onSelect: PropTypes.func,
4144
};

src/utils/event-handlers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export function safeClick(callback, callbackArgs) {
1+
export function safeClick(callback, ...callbackArgs) {
22
return (e) => {
33
stopPropagation(e);
44
e.preventDefault();
55

6-
callback(callbackArgs);
6+
callback(...callbackArgs);
77
};
88
}
99

0 commit comments

Comments
 (0)