diff --git a/lib/KBreadcrumbs.vue b/lib/KBreadcrumbs.vue index 589d7813b..ed4bd09e3 100644 --- a/lib/KBreadcrumbs.vue +++ b/lib/KBreadcrumbs.vue @@ -1,137 +1,65 @@ + +
@@ -72,6 +87,13 @@ type: [Object, String], default: null, }, + overflowDirection: { + type: String, + default: 'end', + validator(value) { + return ['start', 'end'].includes(value); + }, + }, }, data() { return { @@ -131,6 +153,8 @@ */ setOverflowItems() { const { list, listWrapper, moreButtonWrapper } = this.$refs; + + // Exit early if necessary refs are not available if (!this.mounted || !listWrapper || !list) { this.overflowItems = []; return; @@ -153,15 +177,13 @@ const itemSize = this.getSize(item); itemsSizes.push(itemSize); } - + const indexSequence = [...Array(list.children.length).keys()]; + const directionIndexes = + this.overflowDirection === 'start' ? indexSequence.reverse() : indexSequence; const overflowItemsIdx = []; - for (let i = 0; i < list.children.length; i++) { - const item = list.children[i]; + directionIndexes.forEach(i => { const itemWidth = itemsSizes[i].width; - - // If the item dont fit in the available space or if we have already - // overflowed items, we hide it. This means that once one item overflows, - // all the following items will be hidden. + const item = list.children[i]; if (itemWidth >= availableWidth || overflowItemsIdx.length > 0) { overflowItemsIdx.push(i); item.style.visibility = 'hidden'; @@ -176,7 +198,7 @@ maxHeight = itemHeight; } } - } + }); // check if overflowed items would fit if the moreButton were not visible const overflowedWidth = overflowItemsIdx.reduce( @@ -203,6 +225,7 @@ list.style.maxWidth = `${maxWidth}px`; list.style.maxHeight = `${maxHeight}px`; }, + /** * Fixes the visibility of the dividers that are shown and hidden when the list overflows. * The visible list should not end with a divider, and the overflowed items should not @@ -256,10 +279,9 @@ +