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: Focus on the first suggestion in MultiSelect filter (#16728) #16786

Closed
wants to merge 10 commits into from
23 changes: 13 additions & 10 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1769,19 +1769,22 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
event.preventDefault();
}

onEnterKey(event) {
onEnterKey(event: KeyboardEvent) {
if (!this.overlayVisible) {
this.onArrowDownKey(event);
this.show(true);
this.focusedOptionIndex.set(this.findFirstFocusedOptionIndex());
} else {
if (this.focusedOptionIndex() !== -1) {
if (event.shiftKey) {
this.onOptionSelectRange(event, this.focusedOptionIndex());
} else {
this.onOptionSelect({ originalEvent: event, option: this.visibleOptions()[this.focusedOptionIndex()] });
const selectedOption = this.visibleOptions()[this.focusedOptionIndex()];
this.onOptionSelect({ originalEvent: event, option: selectedOption });
}
} else {
console.warn('No option is currently focused to select.');
}
}

event.preventDefault();
}

Expand Down Expand Up @@ -1873,13 +1876,13 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
onFilterInputChange(event: KeyboardEvent) {
let value: string = (event.target as HTMLInputElement).value;
this._filterValue.set(value);
this.focusedOptionIndex.set(-1);
this.onFilter.emit({ originalEvent: event, filter: this._filterValue() });

!this.virtualScrollerDisabled && this.scroller.scrollToIndex(0);
setTimeout(() => {
this.overlayViewChild.alignOverlay();
});
if (this.autoOptionFocus && this.visibleOptions().length > 0) {
this.focusedOptionIndex.set(0);
} else {
this.focusedOptionIndex.set(-1);
}
this.onFilter.emit({ originalEvent: event, filter: this._filterValue() });
}

onLastHiddenFocus(event) {
Expand Down