Skip to content

Commit

Permalink
fix(Overlay): support function children-#close-810
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkahn committed Jun 21, 2019
1 parent 384638f commit cff7566
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/overlay/overlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,10 @@ export default class Overlay extends Component {
let children =
stateVisible || (cache && this._isMounted) ? propChildren : null;
if (children) {
const child = Children.only(children);
let child = Children.only(children);
if (typeof child.type === 'function') {
child = <div role="none">{child}</div>;
}
const childClazz = classnames({
[`${prefix}overlay-inner`]: true,
[animation.in]: status === 'entering',
Expand Down
16 changes: 15 additions & 1 deletion test/overlay/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class PopupControlDemo extends React.Component {

describe('Overlay', () => {
let wrapper;
let wrapper2;

beforeEach(() => {
const nodeListArr = [].slice.call(
Expand Down Expand Up @@ -452,6 +451,21 @@ describe('Overlay', () => {
done();
}, 1000);
});

it('should support function children', () => {
const MyFuncComp = () => {
return 'content';
}
wrapper = render(
<Overlay visible>
<MyFuncComp />
</Overlay>
);

const overlay = wrapper.instance().getInstance();
const content = overlay.getContent();
assert(content.textContent.trim() === 'content');
})
});

describe('Popup', () => {
Expand Down

0 comments on commit cff7566

Please sign in to comment.