1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Add additional prop validation to Tabs component (#8267)

The Tabs component expects the `children` prop to be either a single
Tab component or an array of Tab components, and the internal tab index
should always map onto one of these components. However, if an invalid
tab index was set, it was just returning the first tab contents.

Instead it will now validate that the tab being asked for does exist,
and throw an error otherwise.
This commit is contained in:
Mark Stacey 2020-04-01 11:29:33 -03:00 committed by GitHub
parent 6ba3b7e282
commit 3f2bf36f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,13 @@ export default class Tabs extends Component {
const { children } = this.props
const { activeTabIndex } = this.state
if (
(Array.isArray(children) && !children[activeTabIndex]) ||
(!Array.isArray(children) && activeTabIndex !== 0)
) {
throw new Error(`Tab at index '${activeTabIndex}' does not exist`)
}
return children[activeTabIndex]
? children[activeTabIndex].props.children
: children.props.children