mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01: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:
parent
6ba3b7e282
commit
3f2bf36f6a
@ -42,6 +42,13 @@ export default class Tabs extends Component {
|
|||||||
const { children } = this.props
|
const { children } = this.props
|
||||||
const { activeTabIndex } = this.state
|
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]
|
return children[activeTabIndex]
|
||||||
? children[activeTabIndex].props.children
|
? children[activeTabIndex].props.children
|
||||||
: children.props.children
|
: children.props.children
|
||||||
|
Loading…
Reference in New Issue
Block a user