Skip to content

Commit 0f275b9

Browse files
KarlGetaion
authored andcommitted
Bugfix/styled components (react-bootstrap#3715)
* fix: defaultProps "as" not compatible with styled-components Moved all defaultProps "as" to props destructuring instead of defaultProps Added tests for *most* instances * Added tests * Added comment to each default "as" to reference issue Removed tests for defaultprops Reverted style changes that no longer need to pass tests Removed empty defaultprops stubs
1 parent 7b7f3b6 commit 0f275b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+246
-111
lines changed

src/AbstractNav.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ class AbstractNav extends React.Component {
2727
activeKey: PropTypes.any,
2828
};
2929

30-
static defaultProps = {
31-
as: 'ul',
32-
};
33-
3430
constructor(...args) {
3531
super(...args);
3632

@@ -112,7 +108,8 @@ class AbstractNav extends React.Component {
112108

113109
render() {
114110
const {
115-
as: Component,
111+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
112+
as: Component = 'ul',
116113
onSelect: _,
117114
parentOnSelect: _0,
118115
getControlledId: _1,

src/Accordion.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ const propTypes = {
2222
defaultActiveKey: PropTypes.string,
2323
};
2424

25-
const defaultProps = {
26-
as: 'div',
27-
};
28-
2925
const Accordion = React.forwardRef((props, ref) => {
3026
let {
31-
as: Component,
27+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
28+
as: Component = 'div',
3229
activeKey,
3330
bsPrefix,
3431
children,
@@ -57,7 +54,6 @@ const Accordion = React.forwardRef((props, ref) => {
5754
});
5855

5956
Accordion.propTypes = propTypes;
60-
Accordion.defaultProps = defaultProps;
6157

6258
Accordion.Toggle = AccordionToggle;
6359
Accordion.Collapse = AccordionCollapse;

src/AccordionToggle.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ const propTypes = {
1919
children: PropTypes.element,
2020
};
2121

22-
const defaultProps = {
23-
as: 'button',
24-
};
25-
2622
const AccordionToggle = React.forwardRef(
27-
({ as: Component, children, eventKey, onClick, ...props }, ref) => {
23+
(
24+
{
25+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
26+
as: Component = 'button',
27+
children,
28+
eventKey,
29+
onClick,
30+
...props
31+
},
32+
ref,
33+
) => {
2834
const onSelect = useContext(SelectableContext);
2935

3036
return (
@@ -43,6 +49,5 @@ const AccordionToggle = React.forwardRef(
4349
);
4450

4551
AccordionToggle.propTypes = propTypes;
46-
AccordionToggle.defaultProps = defaultProps;
4752

4853
export default AccordionToggle;

src/Breadcrumb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const propTypes = {
2626
const defaultProps = {
2727
label: 'breadcrumb',
2828
listProps: {},
29-
as: 'nav',
3029
};
3130

3231
const Breadcrumb = React.forwardRef(
@@ -37,7 +36,8 @@ const Breadcrumb = React.forwardRef(
3736
listProps,
3837
children,
3938
label,
40-
as: Component,
39+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
40+
as: Component = 'nav',
4141
...props
4242
},
4343
ref,

src/BreadcrumbItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ const propTypes = {
3333

3434
const defaultProps = {
3535
active: false,
36-
as: 'li',
3736
};
3837

3938
const BreadcrumbItem = React.forwardRef(
40-
({ bsPrefix, active, className, as: Component, ...props }, ref) => {
39+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
40+
({ bsPrefix, active, className, as: Component = 'li', ...props }, ref) => {
4141
const prefix = useBootstrapPrefix(bsPrefix, 'breadcrumb-item');
4242

4343
const { href, title, target, ...elementProps } = props;

src/ButtonGroup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const defaultProps = {
4141
vertical: false,
4242
toggle: false,
4343
role: 'group',
44-
as: 'div',
4544
};
4645

4746
const ButtonGroup = React.forwardRef((props, ref) => {
@@ -51,7 +50,8 @@ const ButtonGroup = React.forwardRef((props, ref) => {
5150
toggle,
5251
vertical,
5352
className,
54-
as: Component,
53+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
54+
as: Component = 'div',
5555
...rest
5656
} = props;
5757

src/Card.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const propTypes = {
5050
};
5151

5252
const defaultProps = {
53-
as: 'div',
5453
body: false,
5554
};
5655

@@ -64,7 +63,8 @@ const Card = React.forwardRef(
6463
border,
6564
body,
6665
children,
67-
as: Component,
66+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
67+
as: Component = 'div',
6868
...props
6969
},
7070
ref,

src/CardImg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const propTypes = {
2222
};
2323

2424
const defaultProps = {
25-
as: 'img',
2625
variant: null,
2726
};
2827

2928
const CardImg = React.forwardRef(
30-
({ bsPrefix, className, variant, as: Component, ...props }, ref) => {
29+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
30+
({ bsPrefix, className, variant, as: Component = 'img', ...props }, ref) => {
3131
const prefix = useBootstrapPrefix(bsPrefix, 'card-img');
3232

3333
return (

src/Carousel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const propTypes = {
102102
};
103103

104104
const defaultProps = {
105-
as: 'div',
106105
slide: true,
107106
fade: false,
108107
interval: 5000,
@@ -423,7 +422,8 @@ class Carousel extends React.Component {
423422

424423
render() {
425424
const {
426-
as: Component,
425+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
426+
as: Component = 'div',
427427
bsPrefix,
428428
slide,
429429
fade,

src/Col.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ const propTypes = {
7070
xl: column,
7171
};
7272

73-
const defaultProps = {
74-
as: 'div',
75-
};
76-
7773
const Col = React.forwardRef(
78-
({ bsPrefix, className, as: Component, ...props }, ref) => {
74+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
75+
({ bsPrefix, className, as: Component = 'div', ...props }, ref) => {
7976
const prefix = useBootstrapPrefix(bsPrefix, 'col');
8077
const spans = [];
8178
const classes = [];
@@ -118,6 +115,5 @@ const Col = React.forwardRef(
118115

119116
Col.displayName = 'Col';
120117
Col.propTypes = propTypes;
121-
Col.defaultProps = defaultProps;
122118

123119
export default Col;

src/Container.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const propTypes = {
2121
};
2222

2323
const defaultProps = {
24-
as: 'div',
2524
fluid: false,
2625
};
2726

2827
const Container = React.forwardRef(
29-
({ bsPrefix, fluid, as: Component, className, ...props }, ref) => {
28+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
29+
({ bsPrefix, fluid, as: Component = 'div', className, ...props }, ref) => {
3030
const prefix = useBootstrapPrefix(bsPrefix, 'container');
3131
return (
3232
<Component

src/Dropdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const propTypes = {
8383
};
8484

8585
const defaultProps = {
86-
as: 'div',
8786
navbar: false,
8887
};
8988

@@ -97,7 +96,8 @@ const Dropdown = React.forwardRef((uncontrolledProps, ref) => {
9796
onSelect,
9897
onToggle,
9998
focusFirstItemOnShow,
100-
as: Component,
99+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
100+
as: Component = 'div',
101101
navbar: _4,
102102
...props
103103
} = useUncontrolled(uncontrolledProps, { show: 'onToggle' });

src/DropdownMenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const propTypes = {
5757

5858
const defaultProps = {
5959
alignRight: false,
60-
as: 'div',
6160
flip: true,
6261
};
6362

@@ -71,7 +70,8 @@ const DropdownMenu = React.forwardRef(
7170
flip,
7271
popperConfig,
7372
show: showProps,
74-
as: Component,
73+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
74+
as: Component = 'div',
7575
...props
7676
},
7777
ref,

src/Feedback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const propTypes = {
1414

1515
const defaultProps = {
1616
type: 'valid',
17-
as: 'div',
1817
};
1918

2019
const Feedback = React.forwardRef(
21-
({ as: Component, className, type, ...props }, ref) => (
20+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
21+
({ as: Component = 'div', className, type, ...props }, ref) => (
2222
<Component
2323
{...props}
2424
ref={ref}

src/Form.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ const propTypes = {
4242

4343
const defaultProps = {
4444
inline: false,
45-
as: 'form',
4645
};
4746

4847
const Form = React.forwardRef(
4948
(
50-
{ bsPrefix, inline, className, validated, as: Component, ...props },
49+
{
50+
bsPrefix,
51+
inline,
52+
className,
53+
validated,
54+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
55+
as: Component = 'form',
56+
...props
57+
},
5158
ref,
5259
) => {
5360
bsPrefix = useBootstrapPrefix(bsPrefix, 'form');

src/FormControl.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ const propTypes = {
7575
isInvalid: PropTypes.bool,
7676
};
7777

78-
const defaultProps = {
79-
as: 'input',
80-
};
81-
8278
const FormControl = React.forwardRef(
8379
(
8480
{
@@ -91,7 +87,8 @@ const FormControl = React.forwardRef(
9187
isInvalid,
9288
plaintext,
9389
readOnly,
94-
as: Component,
90+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
91+
as: Component = 'input',
9592
...props
9693
},
9794
ref,
@@ -136,7 +133,6 @@ const FormControl = React.forwardRef(
136133

137134
FormControl.displayName = 'FormControl';
138135
FormControl.propTypes = propTypes;
139-
FormControl.defaultProps = defaultProps;
140136

141137
FormControl.Feedback = Feedback;
142138

src/FormGroup.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ const propTypes = {
2929
_ref: PropTypes.any,
3030
};
3131

32-
const defaultProps = {
33-
as: 'div',
34-
};
35-
3632
const FormGroup = React.forwardRef(
3733
(
38-
{ bsPrefix, className, children, controlId, as: Component, ...props },
34+
{
35+
bsPrefix,
36+
className,
37+
children,
38+
controlId,
39+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
40+
as: Component = 'div',
41+
...props
42+
},
3943
ref,
4044
) => {
4145
bsPrefix = useBootstrapPrefix(bsPrefix, 'form-group');
@@ -57,6 +61,5 @@ const FormGroup = React.forwardRef(
5761

5862
FormGroup.displayName = 'FormGroup';
5963
FormGroup.propTypes = propTypes;
60-
FormGroup.defaultProps = defaultProps;
6164

6265
export default FormGroup;

src/FormText.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ const propTypes = {
2727
as: PropTypes.elementType,
2828
};
2929

30-
const defaultProps = {
31-
as: 'small',
32-
};
33-
3430
const FormText = React.forwardRef(
35-
({ bsPrefix, className, as: Component, ...props }, ref) => {
31+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
32+
({ bsPrefix, className, as: Component = 'small', ...props }, ref) => {
3633
bsPrefix = useBootstrapPrefix(bsPrefix, 'form-text');
3734
return (
3835
<Component
@@ -46,6 +43,5 @@ const FormText = React.forwardRef(
4643

4744
FormText.displayName = 'FormText';
4845
FormText.propTypes = propTypes;
49-
FormText.defaultProps = defaultProps;
5046

5147
export default FormText;

src/InputGroup.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ class InputGroup extends React.Component {
2929
as: PropTypes.elementType,
3030
};
3131

32-
static defaultProps = {
33-
as: 'div',
34-
};
35-
3632
render() {
37-
const { bsPrefix, size, className, as: Component, ...props } = this.props;
33+
const {
34+
bsPrefix,
35+
size,
36+
className,
37+
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
38+
as: Component = 'div',
39+
...props
40+
} = this.props;
3841

3942
return (
4043
<Component

0 commit comments

Comments
 (0)