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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor KBreadcrumbs to utilize KListWithOverflow #693

Open
1 task
MisRob opened this issue Jul 26, 2024 · 6 comments
Open
1 task

Refactor KBreadcrumbs to utilize KListWithOverflow #693

MisRob opened this issue Jul 26, 2024 · 6 comments
Assignees
Labels
Component: KBreadcrumbs Component: KListWithOverflow help wanted Open source contributors welcome P3 - low Priority: Stretch goal

Comments

@MisRob
Copy link
Member

MisRob commented Jul 26, 2024

🌱 Are you new to the codebase? Welcome! Please see the contributing guidelines.

In times when KListWithOverflow component didn't yet exist, we used the "duplicate markup" technique in the KBreadcrumbs component to achieve their overflow behavior when breadcrumb items were collapsed to the dropdown menu on the left:

breadcrumbs

The duplicate markup technique is based on keeping a hidden copy of visible breadcrumbs (breadcrumbs-offscreen) in the markup so that elements are available for recalculations:

<!-- This is a duplicate of breacrumbs-visible-items to help to reference sizes. -->
<div class="breadcrumbs breadcrumbs-offscreen" aria-hidden="true">
<ol class="breadcrumbs-visible-items">
<template v-for="(crumb, index) in crumbs">
<li
v-if="index !== crumbs.length - 1"
:ref="`crumb${index}`"
:key="index"
class="breadcrumbs-visible-item breadcrumbs-visible-item-notlast"
>
<KRouterLink v-if="crumb.link" :text="crumb.text" :to="crumb.link" tabindex="-1">
<template #text="{ text }">
<span class="breadcrumbs-crumb-text">{{ text }}</span>
</template>
</KRouterLink>
<span v-else>{{ crumb.text }}</span>
</li>
<li
v-else
:ref="`crumb${index}`"
:key="index"
class="breadcrumb-visible-item-last breadcrumbs-visible-item"
>
<span
class="breadcrumbs-crumb-text"
:style="{ maxWidth: lastBreadcrumbMaxWidth }"
>
{{ crumb.text }}
</span>
</li>
</template>
</ol>
</div>
</div>

Now that we have KListWithOverflow that is designed to take care of overflowing items to a menu, it would be good to remove this other implementation from KBreadcrumbs and refactor them to utilize KListWithOverflow instead.

The Value Add

Easier maintenance, development efficiency.

Guidance

Note that KListWithOverflow will likely need some updates to be able to display the button on the left side, and possibly some other adjustments so that these two components can collaborate smoothly.

Acceptance criteria

  • There are no regressions in places where KBreadcrumbs and KListWithOverflow are used:
    • Live examples on their documentation pages
    • In Kolibri and Studio
@MisRob MisRob added help wanted Open source contributors welcome Component: KBreadcrumbs Component: KListWithOverflow P3 - low Priority: Stretch goal labels Jul 26, 2024
@sruthin21
Copy link

Hey @MisRob I want to work on this Issue Please Assign this to me

@AlexVelezLl
Copy link
Member

Hey @sruthin21! Thank you! I just assigned you this issue. Please let us know if you have any question. I was thinking to propose something for this issue but probably will be able to do that tomorrow :). But you can start looking at the issue for now.

@sruthin21
Copy link

@AlexVelezLl Thank You for assigning

@AlexVelezLl
Copy link
Member

Hey @sruthin21! I am back with some things we will need for this:

  1. We need to update KListWithOverflow since now we need to allow hiding overflowed items from the beginning, instead of from the end of the list as we courrently do. For this:
  • We need to define a new prop overflowDirection that accepts as values start or end, with end as default value as this would be the current behaviour.
  • We need to position the more button at the beginning or at the end of the list, depending on the overflowDirection prop.
  • We need to modify the hiding elements logic inside the setOverflowItems method to support hiding elements from the beginning. This is probably the biggest challenge of the issue. I suggest to try to look for mathematical operations to achieve the reverse overflow instead of duplicating the logic for both overflowDirection values.
  1. Update KBreadcrums to use KListWithOverflow.
  • To prepare the items for this, we will need to add a { type: "separator" } object between every element, and use the #divider slot to render the "> " icon.
  • We have this fixDividerVisibility method in KListWithOverflow to avoid having a separator at the beginning or at the end, and this will mess with the requirement of KBreadcrums to have the ">" icon just after the more button, so the easiest way to achieve that will be that the #more slot renders both, the more button, and the ">" separator icon. With this, we will avoid having to care about that.

There will problably be a lot of things that I am missing, so please let us know if you have any questions 🤗.

@sruthin21
Copy link

What this throttle function do And what will be the output of the function

@AlexVelezLl
Copy link
Member

AlexVelezLl commented Sep 17, 2024

This is just a way to optimize the number of calls we do to the setOverflowItems method, you can ignore it, and assume we will be always calling setOverflowItem each time the parent element is resized. You can read more about thottling here https://dev.to/jeetvora331/throttling-in-javascript-easiest-explanation-1081.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: KBreadcrumbs Component: KListWithOverflow help wanted Open source contributors welcome P3 - low Priority: Stretch goal
Projects
None yet
Development

No branches or pull requests

3 participants