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

Fix reset of active item when query hasn't changed #3072

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/select/src/components/query-list/queryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,21 @@ export class QueryList<T> extends React.Component<IQueryListProps<T>, IQueryList

public setQuery(query: string, resetActiveItem = this.props.resetOnQuery) {
this.shouldCheckActiveItemInViewport = true;
if (query !== this.state.query) {
const hasQueryChanged = query !== this.state.query;
if (hasQueryChanged) {
Utils.safeInvoke(this.props.onQueryChange, query);
}

const filteredItems = getFilteredItems(query, this.props);
this.setState({ filteredItems, query });

// always reset active item if it's now filtered or disabled
const activeIndex = this.getActiveIndex(filteredItems);
if (
resetActiveItem ||
activeIndex < 0 ||
isItemDisabled(this.state.activeItem, activeIndex, this.props.itemDisabled)
hasQueryChanged &&
(resetActiveItem ||
activeIndex < 0 ||
isItemDisabled(this.state.activeItem, activeIndex, this.props.itemDisabled))
Copy link
Contributor

Choose a reason for hiding this comment

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

well this is just yucky formatting. perhaps pull the parenthetical out to a local variable shouldResetActiveItem?

) {
this.setActiveItem(getFirstEnabledItem(filteredItems, this.props.itemDisabled));
}
Expand Down