From 65574dd2dfeb4a544019d80e65419b61b980ecfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E4=B8=AD=E7=86=8A?= <1244026727@qq.com> Date: Sun, 19 Aug 2018 20:20:25 +0800 Subject: [PATCH] fix(module:cascader): should not change on hover work (#1991) close #1966 --- components/cascader/nz-cascader.component.ts | 3 ++- components/cascader/nz-cascader.spec.ts | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/components/cascader/nz-cascader.component.ts b/components/cascader/nz-cascader.component.ts index 1eeac575b7..8cda1bbebc 100644 --- a/components/cascader/nz-cascader.component.ts +++ b/components/cascader/nz-cascader.component.ts @@ -1082,7 +1082,8 @@ export class NzCascaderComponent implements OnInit, OnDestroy, ControlValueAcces this.clearDelaySelectTimer(); if (doSelect) { this.delaySelectTimer = setTimeout(() => { - this.setActiveOption(option, index, true); + // 鼠标滑入只展开,不进行选中操作 + this.setActiveOption(option, index); this.delaySelectTimer = null; }, 150); } diff --git a/components/cascader/nz-cascader.spec.ts b/components/cascader/nz-cascader.spec.ts index ba4c96a867..1ab9ac0d03 100644 --- a/components/cascader/nz-cascader.spec.ts +++ b/components/cascader/nz-cascader.spec.ts @@ -1176,7 +1176,7 @@ describe('cascader', () => { expect(overlayContainerElement.querySelectorAll('.ant-cascader-menu').length).toBe(0); // 0列 expect(testComponent.cascader.isMenuVisible()).toBe(false); })); - it('should change on hover work', fakeAsync(() => { + it('should not change on hover work', fakeAsync(() => { testComponent.nzChangeOnSelect = true; testComponent.nzExpandTrigger = 'hover'; fixture.detectChanges(); @@ -1199,9 +1199,7 @@ describe('cascader', () => { expect(testComponent.cascader.isMenuVisible()).toBe(true); expect(itemEl1.classList).toContain('ant-cascader-menu-item-active'); expect(overlayContainerElement.querySelectorAll('.ant-cascader-menu').length).toBe(2); // 2列 - expect(testComponent.values).toBeDefined(); - expect(testComponent.values.length).toBe(1); - expect(testComponent.values[ 0 ]).toBe('zhejiang'); + expect(testComponent.values).toBeNull(); // mouseenter does not trigger selection const itemEl2 = overlayContainerElement.querySelector('.ant-cascader-menu:nth-child(2) .ant-cascader-menu-item:nth-child(1)') as HTMLElement; // 第2列第1个 expect(itemEl1.classList).toContain('ant-cascader-menu-item-active'); @@ -1215,10 +1213,7 @@ describe('cascader', () => { expect(itemEl1.classList).toContain('ant-cascader-menu-item-active'); expect(itemEl2.classList).toContain('ant-cascader-menu-item-active'); expect(overlayContainerElement.querySelectorAll('.ant-cascader-menu').length).toBe(3); // 3列 - expect(testComponent.values).toBeDefined(); - expect(testComponent.values.length).toBe(2); - expect(testComponent.values[ 0 ]).toBe('zhejiang'); - expect(testComponent.values[ 1 ]).toBe('hangzhou'); + expect(testComponent.values).toBeNull(); // mouseenter does not trigger selection const itemEl3 = overlayContainerElement.querySelector('.ant-cascader-menu:nth-child(3) .ant-cascader-menu-item:nth-child(1)') as HTMLElement; // 第3列第1个 expect(itemEl1.classList).toContain('ant-cascader-menu-item-active'); @@ -1229,17 +1224,14 @@ describe('cascader', () => { tick(200); fixture.detectChanges(); - expect(testComponent.values).toBeDefined(); - expect(testComponent.values.length).toBe(2); - expect(testComponent.values[ 0 ]).toBe('zhejiang'); - expect(testComponent.values[ 1 ]).toBe('hangzhou'); + expect(testComponent.values).toBeNull(); // mouseenter does not trigger selection itemEl3.click(); fixture.detectChanges(); tick(200); fixture.detectChanges(); - expect(testComponent.values).toBeDefined(); + expect(testComponent.values).toBeDefined(); // click trigger selection expect(testComponent.values.length).toBe(3); expect(testComponent.values[ 0 ]).toBe('zhejiang'); expect(testComponent.values[ 1 ]).toBe('hangzhou');