Open-source personal finance manager. Self-hosted, privacy-first.
fix(onboarding): keep the tour buttons inside the card (#1132)
Rogerio Camorim803f75cff7a9
diff --git a/frontend/src/components/onboarding-tour.test.tsx b/frontend/src/components/onboarding-tour.test.tsxnew file mode 100644index 00000000..687bc640--- /dev/null+++ b/frontend/src/components/onboarding-tour.test.tsx@@ -0,0 +1,50 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { screen, waitFor } from '@testing-library/react'++import { OnboardingTour } from './onboarding-tour'+import { renderWithProviders, t } from '@/test/utils'++function addTarget(rect: Partial<DOMRect>) {+ const el = document.createElement('div')+ el.setAttribute('data-tour', 'sidebar')+ el.getBoundingClientRect = () =>+ ({ top: 0, left: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0, toJSON: () => ({}), ...rect }) as DOMRect+ document.body.appendChild(el)+ return el+}++// The tour measures its target on a short timer, so wait for the card to be placed.+async function tooltip() {+ const title = await screen.findByText(t('onboarding.sidebar'))+ const card = title.closest<HTMLElement>('.pointer-events-auto')!+ await waitFor(() => expect(card.style.display).not.toBe('none'))+ return card+}++describe('OnboardingTour layout (#1036)', () => {+ afterEach(() => {+ document.querySelectorAll('[data-tour]').forEach((el) => el.remove())+ vi.unstubAllGlobals()+ })++ it('gives the card a fixed width and lets the footer wrap', async () => {+ addTarget({ top: 100, left: 0, right: 240, bottom: 140, width: 240, height: 40 })+ renderWithProviders(<OnboardingTour onComplete={vi.fn()} />)++ const card = await tooltip()+ expect(card.style.width).toBe('320px')+ const footer = screen.getByRole('button', { name: t('onboarding.next') }).parentElement!.parentElement!+ expect(footer).toHaveClass('flex-wrap')+ })++ it('stays inside a phone-width viewport even when the target is off-screen', async () => {+ vi.stubGlobal('innerWidth', 375)+ addTarget({ top: 100, left: -280, right: -20, bottom: 140, width: 260, height: 40 })+ renderWithProviders(<OnboardingTour onComplete={vi.fn()} />)++ const card = await tooltip()+ expect(card.style.width).toBe('320px')+ expect(parseFloat(card.style.left)).toBeGreaterThanOrEqual(8)+ expect(parseFloat(card.style.left) + 320).toBeLessThanOrEqual(375)+ })+})diff --git a/frontend/src/components/onboarding-tour.tsx b/frontend/src/components/onboarding-tour.tsxindex 2675abfa..11720230 100644--- a/frontend/src/components/onboarding-tour.tsx+++ b/frontend/src/components/onboarding-tour.tsx@@ -64,20 +64,23 @@ export function OnboardingTour({ onComplete }: Props) {const step = STEPS[current]const pad = 6- // Tooltip position: to the right of the target element+ // Tooltip position: to the right of the target element. A fixed width+ // (never wider than the viewport) so the footer wraps inside the card+ // instead of pushing a long label past its edge (issue #1036).+ const tooltipWidth = Math.min(320, window.innerWidth - 16)const tooltipStyle: React.CSSProperties = rect? {position: 'fixed',top: Math.max(8, Math.min(rect.top, window.innerHeight - 220)),- left: rect.right + 16,+ left: Math.max(8, rect.right + 16),zIndex: 10001,- maxWidth: 320,+ width: tooltipWidth,}: { display: 'none' }// If tooltip would go off screen right, put it below instead- if (rect && rect.right + 16 + 320 > window.innerWidth) {- tooltipStyle.left = Math.max(8, rect.left)+ if (rect && rect.right + 16 + tooltipWidth > window.innerWidth) {+ tooltipStyle.left = Math.max(8, Math.min(rect.left, window.innerWidth - tooltipWidth - 8))tooltipStyle.top = rect.bottom + 12}@@ -139,11 +142,11 @@ export function OnboardingTour({ onComplete }: Props) {</span></div><p className="text-sm text-muted-foreground leading-relaxed">{t(step.descKey)}</p>- <div className="flex items-center justify-between pt-1">+ <div className="flex flex-wrap items-center justify-between gap-2 pt-1"><Button variant="ghost" size="sm" onClick={onComplete} className="text-muted-foreground">{t('onboarding.skip')}</Button>- <div className="flex gap-2">+ <div className="ml-auto flex gap-2">{current > 0 && (<Button variant="outline" size="sm" onClick={back}>{t('onboarding.back')}