Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [amp-carousel 0.2] Set width for responsive slides #31564

Merged
merged 1 commit into from
Jan 25, 2021

Conversation

micajuine-ho
Copy link
Contributor

@micajuine-ho micajuine-ho commented Dec 11, 2020

Let's try this again....
Closes #31304

Without a set width on the slide element (for type=carousel), the spacer (that gets created by runtime for responsive elements) inside the slide will have a height and width set to 0x0.

When the carousel lays out its children, runtime stops layoutCallback() from being called because it has 0 height and width (because spacer is not correctly inflating the element).

Screen Shot 2021-01-06 at 12 46 12 PM

The fix is to add width: 100% to the slides that are responsive (since this could affect a lot of pubs, let's be really restrictive on the CSS ruleset here).

Screen Shot 2021-01-06 at 12 53 59 PM

This issue doesn't occur in amp-base-carousel due to the immediate parent of the slides (the scroll container) having width:100% set. The same this is true of amp-carousel type=slides-- immediate parent of the slides (the wrapper in this case) has width:100% set.

*/

const TAG_NAME = 'amp-carousel';
const SCROLLABLE_SLIDE = 'amp-scrollable-carousel-slide';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a pattern here we could adopt similar to CSS Modules, allowing the test helper to import the name from the CSS file.

No reason to change for this PR, but in the future it would help to prevent skew between names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if this is possible.

@alanorozco
Copy link
Member

Do we need these image files?

test/manual/amp-carousel/img/bluegradient.png
...

Could the slides use a div with a background color instead?

Comment on lines +21 to +36
export function getSlides(controller) {
return controller.findElements(`${TAG_NAME} .${SCROLLABLE_SLIDE}`);
}

export async function getSlide(controller, n) {
const slides = await getSlides(controller);
return slides[n];
}

export function getNextArrow(controller) {
return controller.findElement(NEXT_ARROW_SELECTOR);
}

export function sleep(ms) {
return new Promise((res) => setTimeout(res, ms));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these appear to be taken from the helpers for amp-base-carousel tests. Can they be shared instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are (and same w/ the images), but I wasn't sure if cross extension dependencies (even if its just in tests) is good practice. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-carousel not showing images with layout="responsive" and type="carousel"
4 participants