feat(carousel): add viewport adjustment test and refine gap handling in layout calculations
This commit is contained in:
@@ -58,9 +58,7 @@ export class CarouselComponent<T> implements AfterViewInit {
|
||||
this.refreshLayout();
|
||||
|
||||
const resizeObserver =
|
||||
typeof ResizeObserver === 'undefined'
|
||||
? null
|
||||
: new ResizeObserver(() => this.refreshLayout());
|
||||
typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(() => this.refreshLayout());
|
||||
resizeObserver?.observe(this.host.nativeElement);
|
||||
|
||||
const mutationObserver =
|
||||
@@ -152,10 +150,7 @@ export class CarouselComponent<T> implements AfterViewInit {
|
||||
}
|
||||
|
||||
const gap = this.resolvedGap();
|
||||
const fittingItems = Math.max(
|
||||
1,
|
||||
Math.floor((availableWidth + gap) / (itemWidth + gap)),
|
||||
);
|
||||
const fittingItems = Math.max(1, Math.floor((availableWidth + gap) / (itemWidth + gap)));
|
||||
const visibleItems = Math.min(fittingItems, viewport.children.length);
|
||||
const fittedWidth = visibleItems * itemWidth + Math.max(visibleItems - 1, 0) * gap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user