expose firstIndex in virtual scroller#823
expose firstIndex in virtual scroller#823lygaret wants to merge 4 commits intosolidjs-community:mainfrom
firstIndex in virtual scroller#823Conversation
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.
while you're at it, you can also expose lastIndex.
There was a problem hiding this comment.
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.
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.
|
@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.
Shouldn't it be items.length if it is -1?
There was a problem hiding this comment.
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.
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: