Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: observe resize segment for better indicator display (#565)
# Motivation Tests in #563 were failing. After debugging, I figured out that the potential display issue actually already existed on the main branch. Specifically, since the segment buttons have no fixed width, depending on the rendering, it's possible that on mount, the buttons are not yet fully rendered—meaning they haven't occupied their full width yet—resulting in the indicator position not being accurately calculated. Similarly, the buttons might be rendered, but the font could take time to load, causing the indicator position to be calculated with the fallback font instead of the final one. Additionally, if the language is changed at runtime, it might result in a change in the buttons' length. Long story short, observing the size of the container and repositioning the indicator when the size changes ensures that the indicator is always correctly positioned. # Changes - Use a `ResizeObserver` to set the indicator position. - Mock `ResizeObserver` globally for vitest # Screenshots Before on main: <img width="1536" alt="Capture d’écran 2025-01-21 à 07 19 52" src="https://github.com/user-attachments/assets/615979f4-fb10-45c1-a1c2-d841d3ea8795" /> After: <img width="1536" alt="Capture d’écran 2025-01-21 à 07 19 37" src="https://github.com/user-attachments/assets/745806a2-cf0b-497a-8924-0aa638c8aa0c" /> # Tests Tests of #563 should pass.
- Loading branch information