-
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] feat(QueryList): add ref
to ItemRendererProps
#5815
Conversation
0de3a04
to
d05dc10
Compare
@adidahiya Apologies for the direct ping, but do you have any thoughts on the proposed change? |
The code seems reasonable so far, can you demonstrate usage of this new prop in the docs somehow? I think you'd need to design a new example option which uses |
Makes sense! To be honest I just blindly followed the suggestion in the linked issue, but I think it’s a bit awkward to use (although it does satisfy my use case). I’ll try to see if there’s a better way to solve this and update the PR (might be a couple of weeks as I’m going on vacation though). Thanks for your review anyway! |
5fe690b
to
fcc349e
Compare
@adidahiya I've updated the Select example to include a grouped option that uses this new prop. That being said, I think it would be better to enhance |
d1cf787
to
c658f2a
Compare
c658f2a
to
7120387
Compare
getActiveElement
propref
to ItemRendererProps
prop
ref
to ItemRendererProps
propref
to ItemRendererProps
a1f24f5
to
48ab10e
Compare
@@ -419,10 +428,12 @@ export class QueryList<T> extends AbstractComponent2<QueryListProps<T>, IQueryLi | |||
if (this.itemsParentRef != null) { | |||
if (isCreateNewItem(activeItem)) { | |||
const index = this.isCreateItemFirst() ? 0 : this.state.filteredItems.length; | |||
return this.itemsParentRef.children.item(index) as HTMLElement; | |||
return this.itemRefs.get(index) ?? (this.itemsParentRef.children.item(index) as HTMLElement); |
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.
The fallback is for backwards compat (if a user didn't wire up the new ref
to elementRef
on the MenuItem
for example)
@adidahiya I've changed the approach but kept the grouped example for you to verify scroll behaviour. I'm happy to drop the example though to keep the diff small. |
@@ -394,6 +396,13 @@ export class QueryList<T> extends AbstractComponent2<QueryListProps<T>, IQueryLi | |||
index, | |||
modifiers, | |||
query, | |||
ref: node => { |
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.
48ab10e
to
e7b3f31
Compare
@@ -422,7 +431,9 @@ export class QueryList<T> extends AbstractComponent2<QueryListProps<T>, IQueryLi | |||
return this.itemsParentRef.children.item(index) as HTMLElement; |
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.
Strictly speaking, we could also wire up a ref to createNewItemRenderer
so that we can easily look it up, but I think even without doing so 0
and this.state.filteredItems.length
should be good enough as indices.
e7b3f31
to
6578ac0
Compare
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.
ref
to ItemRendererProps
ref
to ItemRendererProps
Fixes #3369
Checklist
Changes proposed in this pull request:
See #3369 (comment)
I didn't add any tests because it seems like there's no tests for scrolling, and I wasn't sure how to best write such a test:
blueprint/packages/select/test/queryListTests.tsx
Lines 215 to 217 in b6c1518
Reviewers should focus on:
getActiveElement
being exposed as desiredScreenshot