Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:select): disabled option can be selected by Enter #7686

Merged
merged 1 commit into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
52 changes: 52 additions & 0 deletions components/select/select.spec.ts
Expand Up @@ -276,6 +276,58 @@ describe('select', () => {
expect(selectElement.querySelector('input')!.getAttribute('disabled')).toBe('');
}));

it('should select option by enter', 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 = 'label';

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

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

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