Skip to content

Commit c665a17

Browse files
authored
fix: NavigationUIComponent not treat wrapAfter properly (#20006)
1 parent 2a5fea1 commit c665a17

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

projects/storefrontlib/cms-components/navigation/navigation/navigation-ui.component.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,12 @@ describe('Navigation UI Component', () => {
167167
});
168168

169169
it('should return 2 for 11', () => {
170-
expect(navigationComponent.getColumnCount(11)).toEqual(2);
170+
expect(navigationComponent.getColumnCount(11)).toEqual(3);
171171
});
172172

173173
it('should return 2 for 12', () => {
174-
expect(navigationComponent.getColumnCount(12)).toEqual(2);
174+
console.log(navigationComponent.wrapAfter);
175+
expect(navigationComponent.getColumnCount(12)).toEqual(3);
175176
});
176177

177178
it('should return 3 for 13', () => {

projects/storefrontlib/cms-components/navigation/navigation/navigation-ui.component.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,17 @@ export class NavigationUIComponent implements OnInit, OnDestroy {
337337
}
338338

339339
getColumnCount(length: number): number {
340-
return Math.round(length / (this.wrapAfter || length));
340+
if (!this.wrapAfter || length <= 0) {
341+
return 1;
342+
}
343+
344+
let subSectionColumns = Math.floor(length / this.wrapAfter);
345+
346+
if (subSectionColumns >= 1 && length % this.wrapAfter > 0) {
347+
subSectionColumns += 1;
348+
}
349+
350+
return subSectionColumns;
341351
}
342352

343353
focusAfterPreviousClicked(event: MouseEvent) {

0 commit comments

Comments
 (0)