Closed isaiahscheel closed 11 months ago
Assigned to future milestone for consideration when this work is prioritized.
Flagging as Help Wanted, as this appears to be a great candidate for inner sourcing.
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);
}
}
@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!
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"?
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.
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.
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.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
What it renders without the scroll method implementation we did:
What it looks like with the auto scroll to middle: