-
Notifications
You must be signed in to change notification settings - Fork 145
expose firstIndex in virtual scroller
#823
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
base: main
Are you sure you want to change the base?
Conversation
lastIndex is actually _exclusive_, which would require math, and I don't feel like it's likely to be as useful as firstIndex
🦋 Changeset detectedLatest commit: 16727c1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| containerHeight: items.length * rowHeight, | ||
| viewerTop: firstIndex * rowHeight, | ||
| visibleItems: items.slice(firstIndex, lastIndex) as unknown as T, | ||
| firstIndex, |
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.
while you're at it, you can also expose lastIndex.
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.
Sure, I can. I did originally, but removed it because its a little weird semantically: when a list is empty, should it return -1, or undefined?
firstIndex being zero makes sense, kinda, but I didn't know what to do with last's typing, so I skipped it.
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.
Right now, it's more like nextIndex than last because it's an exclusive range.
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
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.
That's fine, too.
|
@atk I ended up going with
let me know your thoughts and I'll move that direction, thank you! |
| visibleItems: items.slice(firstIndex, lastIndex) as unknown as T, | ||
| firstIndex, | ||
| lastIndex: lastIndex > 0 ? lastIndex - 1 : undefined, | ||
| // -1 because slice is an exclusive range |
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.
Shouldn't it be items.length if it is -1?
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.
I'm sorry, I'm not sure what you're asking.
The -1 is an explanation of the reason we're not just passing it in straight, and it's already based on items.length, hence the whole thing ?
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.
Ah, I read the whole thing in a different order. My bad, I'm currently down with a flu.
|
Now all that is left to do is add a changeset using |
I'd like to be able to use a virtual list with an
<ol>element, since that's semantically correct for my application.Currently, in order to correctly set the
startattribute, I'm currently dividingviewTopbyrowHeight, which is just how it's defined, and lets me get at the value correctly, but it's a very ugly hack to get the value which is just hidden under the lambda.In use, this looks like: