vertical-collection icon indicating copy to clipboard operation
vertical-collection copied to clipboard

Manual scrolling (updating idForFirstItem)

Open buschtoens opened this issue 7 years ago • 11 comments

As far as I can see, it's currently not possible to update idForFirstItem after the first render. The docs concur with this assessment.

https://github.com/html-next/vertical-collection/blob/b218268807b620854105ba76496844eb703d1959/addon/components/vertical-collection/component.js#L112-L121

Is this just not implemented yet or intentionally left out? In the latter case: how would you expect users of this addon to implement a "jump to" feature?

buschtoens avatar Nov 23 '17 15:11 buschtoens

This hasn’t been implemented yet, we’ve been waiting for v1.0 to work on it because the other issues we need to solve are a bit more fundamental (a11y, etc). But we do have a plan.

Scrolling through the collection is an imperative action, you want to tell the collection what to do, or potentially query it for the scrollTop of an item so you can animate the transition to it. This is not really like an action or argument - instead we want to yield back an API from the component that parent components can use.

This would be similar to registerAPI in ember-power-select. The hard part is figuring out what that API should look like, which is why we keep punting on it. I think the most minimal version would be to query for the position of an item given it’s id, so we might be able to start there.

pzuraq avatar Nov 23 '17 18:11 pzuraq

We want to use vertical-collection for implementing a long list of selectable items. However. after manually scrolling the collection, the selected item may be way out of view. The user should be able to select the next (or previous item) with 1 click, so that the new selected item scrolls automatically into view (at the top or bottom, whichever is closest). When do you think this behaviour will be possible ? If it takes too long we may fork the vertical-collection and start working out our own solution, but it would be better if we could know in advance the API you were thinking about.

hfranken avatar Dec 19 '17 09:12 hfranken

We're hoping to work on it early next year, I'll be needing this API soon too for some of the work I'm planning on doing next quarter on our internal select components.

The API would follow the registerAPI pattern used by ember-power-select and others to yield an imperative API upwards:

{{vertical-collection registerAPI=(action "registerAPI")}}
export default Component.extend({
  actions: {
    registerAPI(api) {
      this.set('collectionAPI', api);
    }
  } 
});

The two methods this API should have are:

  • offsetForIndex(index: number): number
  • offsetForId(id: any): number

Both should return the pixel value of the scroll offset for the index/id. This allows external contexts to control the way that the collection scrolls, whether it's just setting scrolltop instantly or animating to it with easing, etc.

pzuraq avatar Dec 19 '17 15:12 pzuraq

+1 This would be great!

Luiz-N avatar Apr 24 '18 19:04 Luiz-N

Any updates on this?

fpauser avatar Oct 16 '18 07:10 fpauser

I haven’t had time recently to work on this library unfortunately, so haven’t had a chance to implement this. Planning on coming back around to it at some point in the future, once some of my other obligations are fulfilled

pzuraq avatar Oct 16 '18 15:10 pzuraq

@pzuraq Can you please check if this works.

ahamedalthaf avatar Oct 11 '19 10:10 ahamedalthaf

Unfortunately I don't have bandwidth at the moment to work on this library, I'm unsure when I will 😩 it is something I do plan on coming back to, particularly once we're about to land some optimizations upstream in Glimmer which, ideally, will allow us to do even more performant work.

I'll try to find some time in the next few quarters to see if I can do some maintenance work. I have a few major refactors I'd like to do, including dropping support for Ember 1-2 so we can have a more streamlined API.

pzuraq avatar Oct 11 '19 16:10 pzuraq

@ahamedalthaf I actually was able to look at that PR and I think it's small enough that we can merge it, if we can get tests passing and add a test for it. Thanks for taking this on!

pzuraq avatar Oct 11 '19 18:10 pzuraq

@pzuraq Thanks

ahamedalthaf avatar Oct 15 '19 10:10 ahamedalthaf