From ab41e694d769cdbe76d90cef88f31c4b2f12b210 Mon Sep 17 00:00:00 2001 From: cbourget Date: Thu, 27 Apr 2017 16:55:40 -0400 Subject: [PATCH] feat(feature list): always focus the first query item --- .../feature-list-binding.directive.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/feature/feature-list/feature-list-binding.directive.ts b/src/lib/feature/feature-list/feature-list-binding.directive.ts index 1510cea94d..808b0321d5 100644 --- a/src/lib/feature/feature-list/feature-list-binding.directive.ts +++ b/src/lib/feature/feature-list/feature-list-binding.directive.ts @@ -33,7 +33,7 @@ export class FeatureListBindingDirective implements OnInit, OnDestroy { this.component.features = []; this.features$$ = this.featureService.features$ - .subscribe(features => this.component.features = features); + .subscribe(features => this.handleFeaturesChange(features)); // When there are multiple feature list with this directive, // selecting moving up and down using the keyboard skips some features. @@ -50,4 +50,17 @@ export class FeatureListBindingDirective implements OnInit, OnDestroy { this.focusedFeature$$.unsubscribe(); } + private handleFeaturesChange(features: Feature[]) { + // If the features change but are not cleared completely, + // we unfocus the focused feature to let the list + // focus on the first item. This is useful when + // the focused item can still be found in the new features. + // In this case, the first item would not be focused, unless + // it was the focused feature itself. + if (features.length > 0) { + this.component.focusedFeature = undefined; + } + this.component.features = features; + } + }