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

[select] QueryList reset followups #2916

Merged
merged 5 commits into from
Sep 11, 2018
Merged

[select] QueryList reset followups #2916

merged 5 commits into from
Sep 11, 2018

Conversation

giladgray
Copy link
Contributor

Follow up from #2894

Changes proposed in this pull request:

  • always reset active item if it's now filtered or disabled (even if resetOnQuery=false).
    • this behavior existed before but didn't work very well. i refactored the state manipulation logic and now it works very well.
  • better handling of shouldCheckActiveItemInViewport so the active item is always visible in the viewport.
    • this behavior regressed at some point. no longer!
  • adjust omnibar example hotkey props for better experience.

CC @switz - followups from your recent PR.

(activeIndex < 0 || isItemDisabled(this.props.activeItem, activeIndex, this.props.itemDisabled))
) {
this.setFirstActiveItem();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was the bad logic. i think the setState callback above was the main culprit. refactored that to simply reuse the setQuery logic, and merged this logic into the reset check in setQuery below.

const { activeItem } = this.state;
// NOTE: this operation is O(n) so it should be avoided in render(). safe for events though.
return activeItem == null ? -1 : this.state.filteredItems.indexOf(activeItem);
return activeItem == null ? -1 : items.indexOf(activeItem);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

specifying the array allowed me to undo the setState callbacks.

@@ -36,7 +36,7 @@ export function selectComponentSuite<P extends IListItemsProps<IFilm>, S>(

describe("common behavior", () => {
it("itemRenderer is called for each child", () => {
const wrapper = render({ ...testProps, resetOnQuery: false });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@switz I was able to remove this prop! default props do the right thing now. the one below stays, which makes sense cuz those tests are about specific reset logic.

@blueprint-bot
Copy link

omnibar example hotkey props

Previews: documentation | landing | table

@blueprint-bot
Copy link

test comments

Previews: documentation | landing | table

global={true}
combo="shift + o"
label="Show Omnibar"
onKeyDown={this.handleToggle}
// prevent typing "O" in omnibar input
preventDefault={true}
Copy link
Contributor

Choose a reason for hiding this comment

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

heh

@@ -229,10 +227,10 @@ export class QueryList<T> extends React.Component<IQueryListProps<T>, IQueryList
return undefined;
}

private getActiveIndex() {
private getActiveIndex(items = this.state.filteredItems) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since this is private it doesn't matter much, but if you call getActiveIndex() elsewhere, maybe it'd be better just to use an explicit non-optional argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷‍♂️

@giladgray giladgray merged commit 009651c into develop Sep 11, 2018
@giladgray giladgray deleted the gg/query-reset-flup branch September 11, 2018 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants