Skip to content

Commit

Permalink
fix(module:auto-complete): should open the popover when the focused i…
Browse files Browse the repository at this point in the history
…nput is clicked (#8900)
  • Loading branch information
WwwHhhYran authored Jan 7, 2025
1 parent a3546a9 commit 79cc2f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/auto-complete/autocomplete-trigger.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function getNzAutocompleteMissingPanelError(): Error {
'(focusin)': 'handleFocus()',
'(blur)': 'handleBlur()',
'(input)': 'handleInput($event)',
'(keydown)': 'handleKeydown($event)'
'(keydown)': 'handleKeydown($event)',
'(click)': 'handleClick($event)'
}
})
export class NzAutocompleteTriggerDirective implements AfterViewInit, ControlValueAccessor, OnDestroy {
Expand Down Expand Up @@ -217,6 +218,12 @@ export class NzAutocompleteTriggerDirective implements AfterViewInit, ControlVal
}
}

handleClick(): void {
if (this.canOpen() && !this.panelOpen) {
this.openPanel();
}
}

handleBlur(): void {
this.onTouched();
}
Expand Down
17 changes: 17 additions & 0 deletions components/auto-complete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ describe('auto-complete', () => {
expect(overlayContainerElement.textContent).toEqual('');
}));

it('should open the panel when the input that has already been focused is clicked', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
flush();

const option = overlayContainerElement.querySelector('nz-auto-option') as HTMLElement;
option.click();
fixture.detectChanges();

tick(500);
expect(fixture.componentInstance.trigger.panelOpen).toBe(false);

dispatchFakeEvent(input, 'click');
fixture.detectChanges();
expect(fixture.componentInstance.trigger.panelOpen).toBe(true);
}));

it('should close the panel when an option is tap', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
Expand Down

0 comments on commit 79cc2f8

Please sign in to comment.