Skip to content

Commit 4c486b0

Browse files
authored
fix(select): two elements with focus frame (#DS-3407) (#826)
1 parent 1384c48 commit 4c486b0

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

packages/components/core/select/common.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CdkConnectedOverlay } from '@angular/cdk/overlay';
2-
import { AfterContentInit, Directive, Inject, OnDestroy, Optional } from '@angular/core';
2+
import { AfterContentInit, Directive, EventEmitter, Inject, OnDestroy, Optional } from '@angular/core';
33
import { END, ESCAPE, HOME, SPACE } from '@koobiq/cdk/keycodes';
44
import { Subscription } from 'rxjs';
55
import { KBQ_FORM_FIELD_REF, KbqFormFieldRef } from '../form-field';
@@ -33,14 +33,16 @@ export class KbqSelectFooter {}
3333
}
3434
})
3535
export class KbqSelectSearch implements AfterContentInit, OnDestroy {
36-
searchChangesSubscription: Subscription = new Subscription();
36+
readonly changes: EventEmitter<string> = new EventEmitter<string>();
3737

3838
isSearchChanged: boolean = false;
3939

4040
get ngControl() {
4141
return this.formField.control.ngControl;
4242
}
4343

44+
private searchChangesSubscription: Subscription = new Subscription();
45+
4446
constructor(@Optional() @Inject(KBQ_FORM_FIELD_REF) protected formField: KbqFormFieldRef) {
4547
formField.canCleanerClearByEsc = false;
4648
}
@@ -75,8 +77,9 @@ export class KbqSelectSearch implements AfterContentInit, OnDestroy {
7577
}
7678

7779
Promise.resolve().then(() => {
78-
this.searchChangesSubscription = this.ngControl.valueChanges!.subscribe(() => {
80+
this.searchChangesSubscription = this.ngControl.valueChanges!.subscribe((value) => {
7981
this.isSearchChanged = true;
82+
this.changes.next(value);
8083
});
8184
});
8285
}

packages/components/select/select.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export class KbqSelect
525525
}
526526

527527
get empty(): boolean {
528-
return !this.selectionModel || this.selectionModel.isEmpty();
528+
return !!this.selectionModel?.isEmpty();
529529
}
530530

531531
get firstSelected(): KbqOptionBase | null {
@@ -639,6 +639,14 @@ export class KbqSelect
639639
this.resetOptions();
640640
this.initializeSelection();
641641
});
642+
643+
this.search?.changes
644+
.pipe(
645+
takeUntilDestroyed(this.destroyRef),
646+
delay(0),
647+
filter(() => !this.keyManager.activeItem)
648+
)
649+
.subscribe(() => this.keyManager.updateActiveItem(0));
642650
}
643651

644652
ngAfterViewInit(): void {
@@ -1235,12 +1243,6 @@ export class KbqSelect
12351243
.subscribe((event) => {
12361244
this.onSelect(event.source, event.isUserInput);
12371245

1238-
if (this.search && this.search.isSearchChanged) {
1239-
Promise.resolve().then(() => this.keyManager.updateActiveItem(0));
1240-
1241-
this.search.isSearchChanged = false;
1242-
}
1243-
12441246
if (event.isUserInput && !this.multiple && this.panelOpen) {
12451247
this.close();
12461248
this.focus();

tools/public_api_guard/components/core.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,8 @@ export function kbqSelectScrollStrategyProviderFactory(overlay: Overlay): () =>
25072507
export class KbqSelectSearch implements AfterContentInit, OnDestroy {
25082508
constructor(formField: KbqFormFieldRef);
25092509
// (undocumented)
2510+
readonly changes: EventEmitter<string>;
2511+
// (undocumented)
25102512
focus(): void;
25112513
// (undocumented)
25122514
protected formField: KbqFormFieldRef;
@@ -2525,8 +2527,6 @@ export class KbqSelectSearch implements AfterContentInit, OnDestroy {
25252527
// (undocumented)
25262528
reset(): void;
25272529
// (undocumented)
2528-
searchChangesSubscription: Subscription;
2529-
// (undocumented)
25302530
setPlaceholder(value: string): void;
25312531
// (undocumented)
25322532
value(): any;

0 commit comments

Comments
 (0)