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

Pickers: Fixed infinite loop when focus lost. #2514

Merged
merged 10 commits into from Aug 16, 2017
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Pickers: Fixed an issue where a loop would sometimes occur if values were resolved when input had an empty value.",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "joschect@microsoft.com"
}
Expand Up @@ -104,8 +104,15 @@ export class BasePicker<T, P extends IBasePickerProps<T>> extends BaseComponent<
@autobind
public dismissSuggestions() {
// Select the first suggestion if one is available when user leaves.
if (this.suggestionStore.hasSelectedSuggestion() && this.state.suggestionsVisible && this.state.suggestedDisplayValue) {
this.addItemByIndex(0);
let selectItemFunction = () => {
if (this.suggestionStore.hasSelectedSuggestion() && this.state.suggestedDisplayValue) {
this.addItemByIndex(0);
}
};
if (this.currentPromise) {
this.currentPromise.then(() => selectItemFunction());
} else {
selectItemFunction();
}
this.setState({ suggestionsVisible: false });
}
Expand Down Expand Up @@ -326,16 +333,6 @@ export class BasePicker<T, P extends IBasePickerProps<T>> extends BaseComponent<
suggestedDisplayValue: itemValue,
suggestionsVisible: this.input.value !== '' && this.input.inputElement === document.activeElement
});

/**
* If user exits the input box before suggestions are returned,
* select the first result upon promise resolution, if a suggestion
* is available.
*/
if (this.suggestionStore.hasSelectedSuggestion() &&
this.input.inputElement !== document.activeElement) {
this.addItemByIndex(0);
}
}

protected onChange(items?: T[]) {
Expand Down Expand Up @@ -528,6 +525,7 @@ export class BasePicker<T, P extends IBasePickerProps<T>> extends BaseComponent<
let newItems: T[] = this.state.items.concat([processedItemObject]);
this._updateSelectedItems(newItems);
}
this.setState({ suggestedDisplayValue: '' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this addition related to the fix, or is this just some housekeeping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Housekeeping. It ensures that when you click out of the picker that and it queues up an item to autoselect that it won't show incorrect text briefly.

}

@autobind
Expand Down