-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
(activeIndex < 0 || isItemDisabled(this.props.activeItem, activeIndex, this.props.itemDisabled)) | ||
) { | ||
this.setFirstActiveItem(); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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.
omnibar example hotkey propsPreviews: documentation | landing | table |
test commentsPreviews: documentation | landing | table |
global={true} | ||
combo="shift + o" | ||
label="Show Omnibar" | ||
onKeyDown={this.handleToggle} | ||
// prevent typing "O" in omnibar input | ||
preventDefault={true} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️
Follow up from #2894
Changes proposed in this pull request:
resetOnQuery=false
).shouldCheckActiveItemInViewport
so the active item is always visible in the viewport.CC @switz - followups from your recent PR.