Skip to content

Commit

Permalink
Suggestions: Fix suggestions arrow scroll bug (microsoft#4881)
Browse files Browse the repository at this point in the history
* fix a bug where sometimes suggestions would not scroll correctly

* adding change file
  • Loading branch information
joschect committed May 17, 2018
1 parent 9c689f1 commit 12b6df6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Suggestions: Fix a bug where arrow keys would not scroll correctly",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "joschect@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export class Suggestions<T> extends BaseComponent<ISuggestionsProps<T>, ISuggest
selectedActionType: SuggestionActionType.none,
};
}

public componentDidMount(): void {
this.scrollSelected();
this.activeSelectedElement = this._selectedElement ? this._selectedElement.current : null;
}

public componentDidUpdate(): void {
// Only scroll to selected element if the selected element has changed. Otherwise do nothing.
// This prevents some odd behavior where scrolling the active element out of view and clicking on a selected element
// will trigger a focus event and not give the clicked element the click.
if (this.activeSelectedElement && this._selectedElement.current && this.activeSelectedElement !== this._selectedElement.current) {
if (this._selectedElement.current && this.activeSelectedElement !== this._selectedElement.current) {
this.scrollSelected();
this.activeSelectedElement = this._selectedElement.current;
}
Expand Down

0 comments on commit 12b6df6

Please sign in to comment.