-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Enable innerRef on Backdrop, List, MenuList and Paper (#13722)
* [core] Add testRef test util * [core] Add support for innerRef to critical components This enabled by using withStyles innerRef in conjunction with forwardRef. * [docs] Fix component definition not found for forwardRef component * [core] Remove lint exception for named function callbacks This was only needed for forwardRef but since displayName support is not really ready yet we don't need it anyway * [core] Fix size limit build error * [core] Fix next failing on React.forwardRef * [core] Switch back to stable next * [docs] Fix size limit * [docs] use official react-docgen release * [core] adjust size limit from last merge
- Loading branch information
Showing
13 changed files
with
99 additions
and
16 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
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 |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import React from 'react'; | ||
import { assert } from 'chai'; | ||
import { createShallow, getClasses } from '@material-ui/core/test-utils'; | ||
import { createMount, createShallow, getClasses, testRef } from '@material-ui/core/test-utils'; | ||
import Backdrop from './Backdrop'; | ||
|
||
describe('<Backdrop />', () => { | ||
let mount; | ||
let shallow; | ||
let classes; | ||
|
||
before(() => { | ||
mount = createMount(); | ||
shallow = createShallow({ dive: true }); | ||
classes = getClasses(<Backdrop open />); | ||
}); | ||
|
||
after(() => { | ||
mount.cleanUp(); | ||
}); | ||
|
||
it('should render a backdrop div', () => { | ||
const wrapper = shallow(<Backdrop open className="woofBackdrop" />); | ||
assert.strictEqual(wrapper.childAt(0).hasClass('woofBackdrop'), true); | ||
assert.strictEqual(wrapper.childAt(0).hasClass(classes.root), true); | ||
}); | ||
|
||
it('does forward refs', () => { | ||
testRef(<Backdrop open />, mount); | ||
}); | ||
}); |
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
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
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,12 @@ | ||
import * as React from 'react'; | ||
import createMount from './createMount'; | ||
|
||
/** | ||
* Utility method to make assertions about the ref on an element | ||
* @param onRef - Make your assertions here | ||
*/ | ||
export default function testRef<T>( | ||
element: React.ReactElement<{ innerRef: React.RefObject<T> }>, | ||
mount: ReturnType<typeof createMount>, | ||
onRef: (ref: T) => void, | ||
): void; |
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,21 @@ | ||
import React from 'react'; | ||
import { assert } from 'chai'; | ||
|
||
function assertDOMNode(node) { | ||
// duck typing a DOM node | ||
assert.ok(node.nodeName); | ||
} | ||
|
||
/** | ||
* | ||
* @param {React.ReactElement} element - The element should have a component wrapped | ||
* in withStyles as the root | ||
* @param {function} mount - Should be returnvalue of createMount | ||
* @param {function} onRef - Callback, first arg is the ref. | ||
* Assert that the ref is a DOM node by default | ||
*/ | ||
export default function testRef(element, mount, onRef = assertDOMNode) { | ||
const ref = React.createRef(); | ||
mount(<>{React.cloneElement(element, { innerRef: ref })}</>); | ||
onRef(ref.current); | ||
} |
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