Skip to content

Commit

Permalink
Merge pull request alibaba-fusion#51 from alibaba-fusion/fix/message
Browse files Browse the repository at this point in the history
fix(Message): When there are multiple Message, the first can't close
  • Loading branch information
youluna authored Nov 26, 2018
2 parents 80adcf2 + c721069 commit f2e0e28
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
16 changes: 11 additions & 5 deletions src/message/toast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ const create = props => {

const newContext = ConfigProvider.getContext();

let mask, myRef;
let mask, myRef, destroyed = false;
const destroy = () => {
const inc = mask && mask.getInstance();
inc && inc.handleClose(true);
destroyed = true;
};

ReactDOM.render(
<ConfigProvider {...newContext}>
<NewMask afterClose={closeChain} {...others} ref={ref => {
Expand All @@ -110,14 +116,14 @@ const create = props => {
</ConfigProvider>
, div, function() {
mask = myRef;
if (mask && destroyed) {
destroy();
}
});

return {
component: mask,
destroy: () => {
const inc = mask && mask.getInstance();
inc && inc.handleClose(true);
}
destroy
};
};

Expand Down
32 changes: 22 additions & 10 deletions test/cascader/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe('Cascader', () => {
let wrapper;

afterEach(() => {
const overlay = document.querySelectorAll('.next-overlay-wrapper');
overlay.forEach(dom => {
document.body.removeChild(dom);
});
if (wrapper) {
wrapper.unmount();
wrapper = null;
}
const overlay = document.querySelectorAll('.next-overlay-wrapper');
overlay.forEach(dom => {
document.body.removeChild(dom);
});
if (wrapper) {
wrapper.unmount();
wrapper = null;
}
});

it('should render single cascader', () => {
Expand All @@ -60,12 +60,16 @@ describe('Cascader', () => {
changeCalled = true;
assert(v === '2980');
delete d.children;
delete d._source;
assert.deepEqual(d, {
value: '2980',
label: '铜川',
pos: '0-0-1'
});
e.selectedPath.forEach(d => delete d.children);
e.selectedPath.forEach(d => {
delete d.children;
delete d._source;
});
assert.deepEqual(e, {
selectedPath: [{
value: '2973',
Expand Down Expand Up @@ -100,12 +104,16 @@ describe('Cascader', () => {
changeCalled = true;
assert(v === '2980');
delete d.children;
delete d._source;
assert.deepEqual(d, {
value: '2980',
label: '铜川',
pos: '0-0-1'
});
e.selectedPath.forEach(d => delete d.children);
e.selectedPath.forEach(d => {
delete d.children;
delete d._source;
});
assert.deepEqual(e, {
selectedPath: [{
value: '2973',
Expand Down Expand Up @@ -208,6 +216,8 @@ describe('Cascader', () => {
let data;
let extra;
const handleChange = (v, d, e) => {
d.forEach(d => delete d._source);
e.checkedData.forEach(d => delete d._source);
assert.deepEqual(value, sortByValue(v, true));
assert.deepEqual(data, sortByValue(d));
e.checkedData = sortByValue(e.checkedData);
Expand Down Expand Up @@ -270,6 +280,8 @@ describe('Cascader', () => {
let data;
let extra;
const handleChange = (v, d, e) => {
d.forEach(d => delete d._source);
e.checkedData.forEach(d => delete d._source);
assert.deepEqual(value, sortByValue(v, true));
assert.deepEqual(data, sortByValue(d));
e.checkedData = sortByValue(e.checkedData);
Expand Down

0 comments on commit f2e0e28

Please sign in to comment.