mirror of
https://github.com/fsolla/teqo.git
synced 2026-12-01 12:03:06 +00:00
B124: corrige foco ao apagar filtro e remove useId morto
Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
9d86510b57
commit
57b1790e12
2 changed files with 9 additions and 9 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
import { Trash2Icon } from 'lucide-react'
|
import { Trash2Icon } from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { usePathname, useSearchParams } from 'next/navigation'
|
import { usePathname, useSearchParams } from 'next/navigation'
|
||||||
import { useId } from 'react'
|
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
import { useMunicipalitySavedFilters } from '@/components/campaign/shared/useMunicipalitySavedFilters'
|
import { useMunicipalitySavedFilters } from '@/components/campaign/shared/useMunicipalitySavedFilters'
|
||||||
|
|
@ -34,7 +33,6 @@ export const MunicipalityNavSavedFilters = ({ onNavigate }: { onNavigate: () =>
|
||||||
const savedFilters = useMunicipalitySavedFilters()
|
const savedFilters = useMunicipalitySavedFilters()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const listId = useId()
|
|
||||||
|
|
||||||
const query = searchParams.toString()
|
const query = searchParams.toString()
|
||||||
const currentHref = query ? `${pathname}?${query}` : pathname
|
const currentHref = query ? `${pathname}?${query}` : pathname
|
||||||
|
|
@ -49,10 +47,13 @@ export const MunicipalityNavSavedFilters = ({ onNavigate }: { onNavigate: () =>
|
||||||
// <body> and strand a keyboard user at the top of the page. Resolve the
|
// <body> and strand a keyboard user at the top of the page. Resolve the
|
||||||
// survivor BEFORE the removal: emptying the group unmounts this whole
|
// survivor BEFORE the removal: emptying the group unmounts this whole
|
||||||
// component, so the fallback has to be the nav link.
|
// component, so the fallback has to be the nav link.
|
||||||
|
const menuItem = row?.closest('[data-sidebar="menu-item"]')
|
||||||
const successor =
|
const successor =
|
||||||
savedFilters.length > 1
|
savedFilters.length > 1
|
||||||
? row?.querySelector<HTMLElement>('[data-sidebar="menu-sub-button"]')
|
? (row?.nextElementSibling ?? row?.previousElementSibling)?.querySelector<HTMLElement>(
|
||||||
: row?.closest('li')?.querySelector<HTMLElement>('a')
|
'[data-sidebar="menu-sub-button"]',
|
||||||
|
) ?? menuItem?.querySelector<HTMLElement>('a')
|
||||||
|
: menuItem?.querySelector<HTMLElement>('a')
|
||||||
|
|
||||||
removeMunicipalitySavedFilter(entry.href)
|
removeMunicipalitySavedFilter(entry.href)
|
||||||
successor?.focus()
|
successor?.focus()
|
||||||
|
|
@ -72,11 +73,7 @@ export const MunicipalityNavSavedFilters = ({ onNavigate }: { onNavigate: () =>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenuSub
|
<SidebarMenuSub aria-label="Filtros salvos de Municípios" className="-mt-0.5 py-0">
|
||||||
id={listId}
|
|
||||||
aria-label="Filtros salvos de Municípios"
|
|
||||||
className="-mt-0.5 py-0"
|
|
||||||
>
|
|
||||||
{savedFilters.map((entry) => {
|
{savedFilters.map((entry) => {
|
||||||
const isActive = entry.href === activeHref
|
const isActive = entry.href === activeHref
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,9 @@ test.describe('Filtros salvos de Municípios', () => {
|
||||||
|
|
||||||
await page.reload()
|
await page.reload()
|
||||||
await expect(shortcut).toBeVisible(NAVIGATION)
|
await expect(shortcut).toBeVisible(NAVIGATION)
|
||||||
|
await expect(
|
||||||
|
page.getByRole('list', { name: 'Filtros salvos de Municípios' }),
|
||||||
|
).toBeVisible()
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole('button', { name: /filtros salvos de Municípios/i }),
|
page.getByRole('button', { name: /filtros salvos de Municípios/i }),
|
||||||
).toHaveCount(0)
|
).toHaveCount(0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue