Skip to content

Commit

Permalink
fix(module:select): disabled option can be selected by Enter
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyship committed Oct 17, 2022
1 parent ee4872e commit c7fc989
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/select/select.component.ts
Expand Up @@ -449,7 +449,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
case ENTER:
e.preventDefault();
if (this.nzOpen) {
if (isNotNil(this.activatedValue)) {
if (isNotNil(this.activatedValue) && activatedIndex !== -1) {
this.onItemClick(this.activatedValue);
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions components/select/select.spec.ts
Expand Up @@ -276,6 +276,32 @@ describe('select', () => {
expect(selectElement.querySelector('input')!.getAttribute('disabled')).toBe('');
}));

it('should nzDisabled option works', fakeAsync(() => {
const flushChanges = (): void => {
fixture.detectChanges();
flush();
fixture.detectChanges();
};
component.listOfOption = [
{ nzValue: 'value', nzLabel: 'label' },
{ nzValue: 'disabledValue', nzLabel: 'disabledLabel', nzDisabled: true }
];
component.nzShowSearch = true;
component.nzOpen = true;

fixture.detectChanges();
const inputElement = selectElement.querySelector('input')!;
inputElement.value = 'disabled';

dispatchFakeEvent(inputElement, 'input');
flushChanges();
expect(component.searchValueChange).toHaveBeenCalledWith('disabled');

dispatchKeyboardEvent(inputElement, 'keydown', ENTER, inputElement);
flushChanges();
expect(component.value).not.toBe('disabledValue');
}));

it('should nzBackdrop works', fakeAsync(() => {
component.nzOpen = true;
component.nzBackdrop = true;
Expand Down

0 comments on commit c7fc989

Please sign in to comment.