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: Render on the Selected Pane/center on it - Low Priority #24

Closed isaiahscheel closed 11 months ago

isaiahscheel commented 1 year ago

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

Describe the solution you'd like

A clear and concise description of what you want to happen.

What it renders without the scroll method implementation we did:

image

What it looks like with the auto scroll to middle:

image

blackfalcon commented 1 year ago

Assigned to future milestone for consideration when this work is prioritized.

Patrick-Daly-AA commented 1 year ago

Flagging as Help Wanted, as this appears to be a great candidate for inner sourcing.

fajar-apri-alaska commented 1 year ago

idk, I have done a bit of research, I don't think we can have the selected children in the middle on component render with our current code. Some other carousel element out there also have this 'centerMode' property. If they have the first children as the selected one, it clones one or more components of the last index child, and puts it before the first child. [ -3 -2 -1 0 1 2 3 ] something like that While ours did nothing with the case.

The best that I can propose right now is to automatically scroll to the selected children (using Promises.all to all of the children updateComplete property to resolve first)

firstUpdated() {
    ...
    if (this.centerSelectedOnRender) { // just a flag for someone that doesn't want to center the selected one
      this.actionOnChildrenReady();
    }
  }

  actionOnChildrenReady() {
    const promises = [];

    [...this.children].forEach((child) => {
      promises.push(child.updateComplete);
    })

    Promise.all(promises).then(() => {
      this.scrollToSelected();
    });
  }

  scrollToSelected() {
    const selectedChildren = [...this.children].find((child) => child.hasAttribute('selected'));

    if (selectedChildren) {
      this.centerElement(selectedChildren);
    }
  }
blackfalcon commented 1 year ago

@fajar-apri-alaska I like where you are going with this. Please address this as an OSS contribution. Fork the repo and submit a PR from your fork.

Thanks!

isaiahscheel commented 11 months ago

I am a little confused on this new attribute, in the code it is called centerSelectedOnRender but on the doc site it is centerSelected. Also it is a string? Is there an example on how to use this or just set it equal to "true"?

blackfalcon commented 11 months ago

Please see the API page https://auro.alaskaair.com/components/auro/carousel/api

The reference to centerSelectedOnRender was an incorrect reference in the local demo page. This has been addressed. There is no demo on the docsite yet, we are working on a Node 18 update of the repo with new examples, this will be updated in that work.

The scope of this update is that ON PAGE RENDER, when a node is preselected and the attribute of centerSelected is on the auro-carousel element, the UI will center that element.

centerSElected

isaiahscheel commented 11 months ago

Thanks @blackfalcon, let me play around with it a little more then and I will reach out if I hav emore questions. I appreciate you looking into it.