-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Portal): throw an error if React.Fragment passed as
trigger
(#3998
- Loading branch information
1 parent
7889c7a
commit 2ac8009
Showing
5 changed files
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import * as ReactIs from 'react-is' | ||
|
||
/** | ||
* Asserts that a passed element can be used cloned a props will be applied properly. | ||
*/ | ||
export default function validateTrigger(element) { | ||
if (element) { | ||
React.Children.only(element) | ||
|
||
if (ReactIs.isFragment(element)) { | ||
throw new Error('An "React.Fragment" cannot be used as a `trigger`.') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
|
||
import validateTrigger from 'src/addons/Portal/utils/validateTrigger' | ||
|
||
describe('validateTrigger', () => { | ||
it('throws on multiple elements passed', () => { | ||
expect(() => validateTrigger([<button key='trigger1' />, <button key='trigger2' />])).to.throw() | ||
}) | ||
|
||
it('throws on React.Fragment passed', () => { | ||
expect(() => validateTrigger(React.createElement(React.Fragment))).to.throw() | ||
}) | ||
}) |