Skip to content

Commit

Permalink
feat(feature list): always focus the first query item
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget committed Apr 27, 2017
1 parent a374ff8 commit ab41e69
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/feature/feature-list/feature-list-binding.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

}

0 comments on commit ab41e69

Please sign in to comment.