Skip to content

Commit 79cc2f8

Browse files
authored
fix(module:auto-complete): should open the popover when the focused input is clicked (#8900)
1 parent a3546a9 commit 79cc2f8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

components/auto-complete/autocomplete-trigger.directive.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export function getNzAutocompleteMissingPanelError(): Error {
6060
'(focusin)': 'handleFocus()',
6161
'(blur)': 'handleBlur()',
6262
'(input)': 'handleInput($event)',
63-
'(keydown)': 'handleKeydown($event)'
63+
'(keydown)': 'handleKeydown($event)',
64+
'(click)': 'handleClick($event)'
6465
}
6566
})
6667
export class NzAutocompleteTriggerDirective implements AfterViewInit, ControlValueAccessor, OnDestroy {
@@ -217,6 +218,12 @@ export class NzAutocompleteTriggerDirective implements AfterViewInit, ControlVal
217218
}
218219
}
219220

221+
handleClick(): void {
222+
if (this.canOpen() && !this.panelOpen) {
223+
this.openPanel();
224+
}
225+
}
226+
220227
handleBlur(): void {
221228
this.onTouched();
222229
}

components/auto-complete/autocomplete.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ describe('auto-complete', () => {
213213
expect(overlayContainerElement.textContent).toEqual('');
214214
}));
215215

216+
it('should open the panel when the input that has already been focused is clicked', fakeAsync(() => {
217+
dispatchFakeEvent(input, 'focusin');
218+
fixture.detectChanges();
219+
flush();
220+
221+
const option = overlayContainerElement.querySelector('nz-auto-option') as HTMLElement;
222+
option.click();
223+
fixture.detectChanges();
224+
225+
tick(500);
226+
expect(fixture.componentInstance.trigger.panelOpen).toBe(false);
227+
228+
dispatchFakeEvent(input, 'click');
229+
fixture.detectChanges();
230+
expect(fixture.componentInstance.trigger.panelOpen).toBe(true);
231+
}));
232+
216233
it('should close the panel when an option is tap', fakeAsync(() => {
217234
dispatchFakeEvent(input, 'focusin');
218235
fixture.detectChanges();

0 commit comments

Comments
 (0)