Permalink
Browse files

fix(module:cascader): search correctly when a root node is a leaf node (

#2108)

close #2104
  • Loading branch information...
zd5043039119 authored and vthinkxie committed Sep 17, 2018
1 parent bc1f6fa commit 28556e49e7f63ca2a13bf39640aa3f99c4cbf341
Showing with 60 additions and 2 deletions.
  1. +2 −2 components/cascader/nz-cascader.component.ts
  2. +58 −0 components/cascader/nz-cascader.spec.ts
@@ -1227,7 +1227,7 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces
if (!sNode.isLeaf) {
loopParent(sNode, disabled);
}
if (sNode.isLeaf || !sNode.children) {
if (sNode.isLeaf || !sNode.children || !sNode.children.length) {
loopChild(sNode, disabled);
}
});
@@ -1248,7 +1248,7 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces
path.pop();
};
this.oldColumnsHolder[ 0 ].forEach(node => loopParent(node));
this.oldColumnsHolder[ 0 ].forEach(node => (node.isLeaf || !node.children || !node.children.length) ? loopChild(node) : loopParent(node));
if (sorter) {
results.sort((a, b) => sorter(a.path, b.path, this._inputValue));
}
@@ -1441,6 +1441,30 @@ describe('cascader', () => {
fixture.detectChanges();
expect(itemEl1.classList).not.toContain('ant-cascader-menu-item-active');
});
it('should support search a root node have no children ', (done) => {
fixture.detectChanges();
testComponent.nzShowSearch = true;
testComponent.nzOptions = options5;
fixture.detectChanges();
const spy = spyOn(testComponent.cascader, 'focus');
cascader.nativeElement.click();
fixture.detectChanges();
expect(spy).toHaveBeenCalled();
testComponent.cascader.inputValue = 'Roo';
testComponent.cascader.setMenuVisible(true);
fixture.detectChanges();
const itemEl1 = overlayContainerElement.querySelector('.ant-cascader-menu:nth-child(1) .ant-cascader-menu-item:nth-child(1)') as HTMLElement;
expect(testComponent.cascader.inSearch).toBe(true);
expect(itemEl1.innerText).toBe('Root');
itemEl1.click();
fixture.whenStable().then(() => {
expect(testComponent.cascader.inSearch).toBe(false);
expect(testComponent.cascader.menuVisible).toBe(false);
expect(testComponent.cascader.inputValue).toBe('');
expect(testComponent.values.join(',')).toBe('root');
done();
});
});
});
describe('load data lazily', () => {
@@ -1731,6 +1755,40 @@ const options4 = [ {
} ]
} ]
} ];
const options5 = [ {
value : 'zhejiang',
label : 'Zhejiang',
children: [ {
value : 'hangzhou',
label : 'Hangzhou',
children: [ {
value : 'xihu',
label : 'West Lake',
isLeaf: true
} ]
}, {
value : 'ningbo',
label : 'Ningbo',
isLeaf: true
} ]
}, {
value : 'jiangsu',
label : 'Jiangsu',
children: [ {
value : 'nanjing',
label : 'Nanjing',
children: [ {
value : 'zhonghuamen',
label : 'Zhong Hua Men',
isLeaf: true
} ]
} ]
}, {
value : 'root',
label : 'Root',
isLeaf: true
} ];
@Component({
selector: 'nz-demo-cascader-default',
template: `

0 comments on commit 28556e4

Please sign in to comment.