Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ <h3 *ngIf="result.products?.length">
[template]="carouselItem"
itemWidth="160px"
(keybordEvent)="carouselEventPropagator($event)"
(mousedown)="preventDefault($event)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this can be breaking change for customers, example:
Customer registered event listener, something like: this.el.nativeElement.addEventListener('focus', this.onFocus, true); and implement some custom logic on focus.
When you are adding (mousedown)="preventDefault($event)" it will not be triggered.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rmch91 That's true, but the question that comes to mind is why would he do it in such a complicated way? If he extends the class, that forces him to have its own HTML structure (which will not be automatically updated from here). The fact that we cannot fix the behavior in his code - it's beyond our control if there is any customization, the question is only whether we are able to break something in his code/ui behavior this way?

Copy link
Contributor

Choose a reason for hiding this comment

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

User can do it without any customization of the component. just register an event listener on cx-carousel in app.component and apply his own logic.
After this change it will not work. So seems that it is breaking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the fix opt-in via a preventNavigationFocus input flag (defaults to false), so it's only enabled in search-box and doesn't affect existing carousels or customer event listeners.

>
</cx-carousel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ <h2 *ngIf="title">{{ title }}</h2>
<button
*ngIf="size < items.length"
class="next"
(click)="
$event.stopPropagation();
activeSlide > items.length - size - 1
? null
: (activeSlide = activeSlide + size)
"
(click)="onNextClick($event, size)"
[attr.aria-disabled]="activeSlide > items.length - size - 1"
[attr.aria-label]="'carousel.nextSlide' | cxTranslate"
[attr.title]="'carousel.nextSlide' | cxTranslate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ export class CarouselComponent implements OnInit, OnChanges {
.getItemsPerSlide(this.el.nativeElement, this.itemWidth)
.pipe(tap(() => (this.activeSlide = 0)));
}
/**
* Handler for the "next" button click.
*/
onNextClick(event: MouseEvent, size: number): void {
event.stopPropagation();

const itemsLength = this.items?.length ?? 0;
const canMove = this.activeSlide <= itemsLength - size - 1;

if (canMove) {
this.activeSlide = this.activeSlide + size;
}
}

onItemKeydown(event: KeyboardEvent, size: number): void {
switch (event.key) {
Expand Down
Loading