Skip to content

Commit dc34bdb

Browse files
leventekkdanez
andauthored
fix: refactor defaultProps to disable warning from react (#518)
Co-authored-by: Daniel Tschinder <[email protected]>
1 parent 63ef752 commit dc34bdb

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

src/components/Tab.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ const Tab = (props) => {
4747
tabIndex,
4848
tabRef,
4949
...attributes
50-
} = props;
50+
} = {
51+
...defaultProps,
52+
...props,
53+
};
5154

5255
useEffect(() => {
5356
if (selected && focus) {
@@ -78,8 +81,8 @@ const Tab = (props) => {
7881
</li>
7982
);
8083
};
81-
Tab.propTypes = propTypes;
8284

85+
Tab.propTypes = propTypes;
8386
Tab.tabsRole = 'Tab';
84-
Tab.defaultProps = defaultProps;
87+
8588
export default Tab;

src/components/TabList.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const propTypes = {
1414
]),
1515
};
1616
const TabList = (props) => {
17-
const { children, className, ...attributes } = props;
17+
const { children, className, ...attributes } = {
18+
...defaultProps,
19+
...props,
20+
};
1821

1922
return (
2023
<ul {...attributes} className={cx(className)} role="tablist">
@@ -25,5 +28,5 @@ const TabList = (props) => {
2528

2629
TabList.tabsRole = 'TabList';
2730
TabList.propTypes = propTypes;
28-
TabList.defaultProps = defaultProps;
31+
2932
export default TabList;

src/components/TabPanel.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const TabPanel = (props) => {
2929
selected,
3030
selectedClassName,
3131
...attributes
32-
} = props;
32+
} = {
33+
...defaultProps,
34+
...props,
35+
};
3336

3437
return (
3538
<div
@@ -48,5 +51,5 @@ const TabPanel = (props) => {
4851

4952
TabPanel.tabsRole = 'TabPanel';
5053
TabPanel.propTypes = propTypes;
51-
TabPanel.defaultProps = defaultProps;
54+
5255
export default TabPanel;

src/components/Tabs.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,20 @@ For more information about controlled and uncontrolled mode of react-tabs see ht
6868
* It is initialized from the prop defaultFocus, and after the first render it is reset back to false. Later it can become true again when using keys to navigate the tabs.
6969
*/
7070
const Tabs = (props) => {
71-
const { children, defaultFocus, defaultIndex, focusTabOnClick, onSelect } =
72-
props;
71+
const {
72+
children,
73+
defaultFocus,
74+
defaultIndex,
75+
focusTabOnClick,
76+
onSelect,
77+
...attributes
78+
} = {
79+
...defaultProps,
80+
...props,
81+
};
7382

7483
const [focus, setFocus] = useState(defaultFocus);
75-
const [mode] = useState(getModeFromProps(props));
84+
const [mode] = useState(getModeFromProps(attributes));
7685
const [selectedIndex, setSelectedIndex] = useState(
7786
mode === MODE_UNCONTROLLED ? defaultIndex || 0 : null,
7887
);
@@ -93,7 +102,7 @@ const Tabs = (props) => {
93102
}, [tabsCount]);
94103
}
95104

96-
checkForIllegalModeChange(props, mode);
105+
checkForIllegalModeChange(attributes, mode);
97106

98107
const handleSelected = (index, last, event) => {
99108
// Call change event handler
@@ -113,7 +122,7 @@ const Tabs = (props) => {
113122
}
114123
};
115124

116-
let subProps = { ...props };
125+
let subProps = { ...props, ...attributes };
117126

118127
subProps.focus = focus;
119128
subProps.onSelect = handleSelected;
@@ -128,7 +137,6 @@ const Tabs = (props) => {
128137
};
129138

130139
Tabs.propTypes = propTypes;
131-
Tabs.defaultProps = defaultProps;
132140
Tabs.tabsRole = 'Tabs';
133141

134142
export default Tabs;

src/components/UncontrolledTabs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ const UncontrolledTabs = (props) => {
383383
disableUpDownKeys, // unused
384384
disableLeftRightKeys, // unused
385385
...attributes
386-
} = props;
386+
} = {
387+
...defaultProps,
388+
...props,
389+
};
387390
return (
388391
<div
389392
{...attributes}
@@ -400,6 +403,7 @@ const UncontrolledTabs = (props) => {
400403
</div>
401404
);
402405
};
403-
UncontrolledTabs.defaultProps = defaultProps;
406+
404407
UncontrolledTabs.propTypes = propTypes;
408+
405409
export default UncontrolledTabs;

0 commit comments

Comments
 (0)