Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use default parameters #518

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const Tab = (props) => {
tabIndex,
tabRef,
...attributes
} = props;
} = {
...defaultProps,
...props,
};

useEffect(() => {
if (selected && focus) {
Expand Down Expand Up @@ -78,8 +81,8 @@ const Tab = (props) => {
</li>
);
};
Tab.propTypes = propTypes;

Tab.propTypes = propTypes;
Tab.tabsRole = 'Tab';
Tab.defaultProps = defaultProps;

export default Tab;
7 changes: 5 additions & 2 deletions src/components/TabList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const propTypes = {
]),
};
const TabList = (props) => {
const { children, className, ...attributes } = props;
const { children, className, ...attributes } = {
...defaultProps,
...props,
};

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

TabList.tabsRole = 'TabList';
TabList.propTypes = propTypes;
TabList.defaultProps = defaultProps;

export default TabList;
7 changes: 5 additions & 2 deletions src/components/TabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const TabPanel = (props) => {
selected,
selectedClassName,
...attributes
} = props;
} = {
...defaultProps,
...props,
};

return (
<div
Expand All @@ -48,5 +51,5 @@ const TabPanel = (props) => {

TabPanel.tabsRole = 'TabPanel';
TabPanel.propTypes = propTypes;
TabPanel.defaultProps = defaultProps;

export default TabPanel;
20 changes: 14 additions & 6 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ For more information about controlled and uncontrolled mode of react-tabs see ht
* 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.
*/
const Tabs = (props) => {
const { children, defaultFocus, defaultIndex, focusTabOnClick, onSelect } =
props;
const {
children,
defaultFocus,
defaultIndex,
focusTabOnClick,
onSelect,
...attributes
} = {
...defaultProps,
...props,
};

const [focus, setFocus] = useState(defaultFocus);
const [mode] = useState(getModeFromProps(props));
const [mode] = useState(getModeFromProps(attributes));
const [selectedIndex, setSelectedIndex] = useState(
mode === MODE_UNCONTROLLED ? defaultIndex || 0 : null,
);
Expand All @@ -93,7 +102,7 @@ const Tabs = (props) => {
}, [tabsCount]);
}

checkForIllegalModeChange(props, mode);
checkForIllegalModeChange(attributes, mode);

const handleSelected = (index, last, event) => {
// Call change event handler
Expand All @@ -113,7 +122,7 @@ const Tabs = (props) => {
}
};

let subProps = { ...props };
let subProps = { ...props, ...attributes };

subProps.focus = focus;
subProps.onSelect = handleSelected;
Expand All @@ -128,7 +137,6 @@ const Tabs = (props) => {
};

Tabs.propTypes = propTypes;
Tabs.defaultProps = defaultProps;
Tabs.tabsRole = 'Tabs';

export default Tabs;
8 changes: 6 additions & 2 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ const UncontrolledTabs = (props) => {
disableUpDownKeys, // unused
disableLeftRightKeys, // unused
...attributes
} = props;
} = {
...defaultProps,
...props,
};
return (
<div
{...attributes}
Expand All @@ -400,6 +403,7 @@ const UncontrolledTabs = (props) => {
</div>
);
};
UncontrolledTabs.defaultProps = defaultProps;

UncontrolledTabs.propTypes = propTypes;

export default UncontrolledTabs;