kobaltedev / kobalte

A UI toolkit for building accessible web apps and design systems with SolidJS.
https://kobalte.dev
MIT License
1.22k stars 62 forks source link

Tab Indicator doesn't stay with selected tab #218

Closed formbook closed 8 months ago

formbook commented 1 year ago

Describe the bug Tab indicator doesn't stay with the selected tab when tabs are dynamically updated.

To Reproduce Steps to reproduce the behavior:

  1. Select a tab
  2. Update the tab list with less or more tabs than the index of the selected tab

Expected behavior Expected the indicator to stay with the selected tab

Screenshots https://streamable.com/9mte9i

Desktop:

formbook commented 1 year ago

Current hack to get desired behaviour

 createEffect(() => {
    // update tabs ...
    // const tabs = [ 'tab 1', 'tab 2', 'tab 3' ]
    const tabIndicator = document.querySelector('.tabs__indicator') as HTMLElement;

    for (let i = 0; i < tabs.length; i++) {
        if (tabs[i] === selectedTab()) {
            tabIndicator.style.transform = `translateX(${tabIndicator.offsetWidth * i}px)`;
            break;
        }
    }
});
fabien-ml commented 1 year ago

Hi, thanks for reporting the issue.

Do you have a reproduction code, because the expected behavior seem to work fine in the doc https://kobalte.dev/docs/core/components/tabs#dynamic-tabs

jer3m01 commented 8 months ago

Closing this issue as can't reproduce and stale, if the issue persist please comment or reopen.