Skip to content

Commit 950fab5

Browse files
committed
fix: CListGroup, CListGroupItem fixes:
- fix accent styling - delete 'variant' from CListGroup (N/A) and role prop - delete role prop, CListGroupItem: - fix passing innerRef to CLink, - add lacking 'list-group-item' class CLink: prevent default link behavior when passed 'href' is equal '#'
1 parent ddf287e commit 950fab5

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

src/CLink.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CLink = props => {
2020

2121
const to = rest ? rest.to : null
2222
const click = e => {
23-
if (!href && !to) {
23+
if ((!href && !to) || href === '#') {
2424
e.preventDefault()
2525
}
2626
onClick && onClick(e)

src/CListGroup.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import classNames from 'classnames';
4-
import {tagPropType, mapToCssModules} from './Shared/helper.js';
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import classNames from 'classnames'
4+
import {tagPropType, mapToCssModules} from './Shared/helper.js'
55

66
//component - CoreUI / CListGroup
77

8-
const CListGroup = props=>{
8+
const CListGroup = props => {
99

1010
const {
1111
tag: Tag,
@@ -15,23 +15,30 @@ const CListGroup = props=>{
1515
innerRef,
1616
horizontal,
1717
flush,
18-
variant,
18+
accent,
1919
...attributes
2020
} = props;
2121

2222
// render
2323

2424
const classes = mapToCssModules(classNames(
2525
className,
26-
'list-group',
27-
horizontal ? `list-group-horizontal-${horizontal}` : false,
28-
flush ? 'list-group-flush' : false,
29-
variant ? 'list-group-'+variant : false
26+
'list-group',
27+
{
28+
[`list-group-horizontal-${horizontal}`]: horizontal,
29+
'list-group-flush': flush,
30+
'list-group-accent': accent
31+
}
3032
), cssModule);
3133

3234
return (
33-
<Tag {...attributes} className={classes} ref={innerRef} />
34-
);
35+
<Tag
36+
className={classes}
37+
role="list-items"
38+
{...attributes}
39+
ref={innerRef}
40+
/>
41+
)
3542

3643
}
3744

@@ -43,13 +50,11 @@ CListGroup.propTypes = {
4350
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
4451
flush: PropTypes.bool,
4552
horizontal: PropTypes.string,
46-
role: PropTypes.string,
47-
variant: PropTypes.string
53+
accent: PropTypes.bool
4854
};
4955

5056
CListGroup.defaultProps = {
5157
tag: 'ul',
52-
role: 'list-items'
5358
};
5459

55-
export default CListGroup;
60+
export default CListGroup

src/CListGroupItem.js

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import classNames from 'classnames';
4-
import {tagPropType, mapToCssModules} from './Shared/helper.js';
5-
import CLink from './CLink';
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import classNames from 'classnames'
4+
import { tagPropType, mapToCssModules } from './Shared/helper.js'
5+
import CLink from './CLink'
66

77
//component - CoreUI / CListGroupItem
88

9-
const CListGroupItem = props=>{
9+
const CListGroupItem = props => {
1010

1111
let {
1212
tag: Tag,
@@ -19,37 +19,31 @@ const CListGroupItem = props=>{
1919
action,
2020
color,
2121
accent,
22-
...attributes
23-
} = props;
24-
25-
if (disabled) {
26-
attributes.onClick = e=>{
27-
e.preventDefault();
28-
};
29-
}
22+
...rest
23+
} = props
3024

3125
//render
3226

3327
const classes = mapToCssModules(classNames(
34-
className,
35-
active ? 'active' : false,
36-
disabled ? 'disabled' : false,
37-
action||attributes.href||attributes.to||Tag=='button' ? 'list-group-item-action' : false,
38-
color ? `list-group-item-${color}` : false,
39-
accent ? `list-group-item-accent-${accent}` : false,
40-
'list-group-item'
41-
), cssModule);
28+
className, 'list-group-item',
29+
{
30+
'list-group-item-action': action||rest.href||rest.to||Tag=='button',
31+
active,
32+
disabled,
33+
[`list-group-item-${color}`]: color,
34+
[`list-group-item-accent-${accent}`]: accent
35+
}
36+
), cssModule)
4237

4338
if (props.href || props.to){
44-
Tag = CLink;
4539
return (
46-
<Tag {...attributes} className={classes} />
47-
);
40+
<CLink {...rest} className={classes} innerRef={innerRef}/>
41+
)
4842
}
4943
else {
5044
return (
51-
<Tag {...attributes} className={classes} ref={innerRef} />
52-
);
45+
<Tag {...rest} className={classes} ref={innerRef}/>
46+
)
5347
}
5448

5549
}
@@ -71,4 +65,4 @@ CListGroupItem.defaultProps = {
7165
tag: 'li'
7266
};
7367

74-
export default CListGroupItem;
68+
export default CListGroupItem

0 commit comments

Comments
 (0)