AlaskaAirlines / auro-carousel

Custom element that ....
https://auro.alaskaair.com/components/auro/carousel
Apache License 2.0
0 stars 4 forks source link

auro-carousel: Center on Selected Item #19

Closed isaiahscheel closed 2 years ago

isaiahscheel commented 2 years ago

Is your feature request related to a problem? Please describe.

Not centered: image

Centered:

image

Describe the solution you'd like

blackfalcon commented 2 years ago

@geoffrich you had a huge hand in creating this element, I seem to remember this issue happening during dev. Do you have any insight into that and any guidance on how we can do this update?

geoffrich commented 2 years ago

This sounds vaguely familiar - I have some ideas, will hack on it a bit and let you know what I think.

geoffrich commented 2 years ago

@blackfalcon @isaiahscheel what about something like this? https://github.com/AlaskaAirlines/auro-carousel/commit/6fadca8e2a2bcaedf96b96c3669ab21379eed0eb

We can add a centerElement method to the carousel that will center the given element inside the carousel. This makes it generic -- you can pass the selected pane yourself, or any element inside the carousel that you want to center. I didn't want to add any logic to the carousel that was coupled to auro-pane.

It can be used like so:

const carousel = document.querySelector('auro-carousel') // or bind:this in Svelte
const selected = document.querySelector('auro-pane[selected]');
carousel.centerElement(selected);

I added an example to the demo page that centers the selected element every time it's clicked:

https://github.com/AlaskaAirlines/auro-carousel/blob/cb4f0e032e49c09ed14b26d3347a70517977fbb8/demo/index.html#L90-L98

Will this API work for you?

center-carousel

ftaylor-alaska commented 2 years ago

@geoffrich This would be a very helpful! Having the carousel do the calculation and scrolling would be a very welcome feature.

blackfalcon commented 2 years ago

@geoffrich this is all you buddy... please mark in progress when you have started work.

AuroDesignSystem commented 2 years ago

:tada: This issue has been resolved in version 1.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: