Escape closes the Dropdown but does not return focus to the trigger
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- react, typescript
- Bereich
- accessibility, frontend
Rechercherichtung
Start with es/hooks/useAccessibility.js and its handleKeyDown and handleCloseMenuAndReturnFocus functions, then read es/index.js and the portal Escape listener described in the issue to trace listener ordering and cleanup. Reproduce with a real Escape key press in a browser, since the issue says scripted dispatchEvent may not expose the behavior. Done means closing the menu with Escape returns focus to the trigger; the issue names no test file.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Versions
- @rc-component/dropdown 1.0.3
- @rc-component/portal 2.2.1
- @rc-component/trigger 3.10.1
- antd 6.6.6
- react and react-dom 19.3.0
- Chrome 155 on macOS. Checked with real clicks and key presses on a bare page holding only the snippet below.
Steps
import { Button, Dropdown } from 'antd';
export default function App() {
return (
<Dropdown menu={{ items: [{ key: 'a', label: 'Rename' }] }} trigger={['click']}>
<Button>Actions</Button>
</Dropdown>
);
}
- Click "Actions". The menu opens.
- Press Tab. Focus moves into the menu.
- Press Escape.
Expected: the menu closes and focus goes back to the "Actions" button, as useAccessibility means it to (handleCloseMenuAndReturnFocus calls triggerRef.current.focus()).
Actual: the menu closes and document.activeElement is document.body. A keyboard user has lost their place on the page.
Cause, as far as we can tell
Two listeners on window handle the same Escape key press:
@rc-component/portal,es/useEscKeyDown.js:onGlobalKeyDowncallsonEscfor the popup on top of the stack. In@rc-component/trigger,es/index.js,onEsccallstriggerOpen(false).@rc-component/dropdown,es/hooks/useAccessibility.js:handleKeyDownonESCcallshandleCloseMenuAndReturnFocus(), which focuses the trigger.
The portal's listener is added first (the Portal is a child, so its effect runs before the Dropdown's), so it runs first. It closes the popup. React renders that close before the next listener runs, and the Dropdown's effect cleanup removes its own keydown listener. A listener removed during dispatch is not called, so the focus return never happens.
Note: a test that calls dispatchEvent from script may not show this, because microtasks do not run between listeners then, so React does not render the close in between. A real key press in a browser shows it.
Workaround we use
We pass our own onOpenChange that adds a capture-phase keydown listener on window while the menu is open, notes that Escape was pressed, and on close focuses the element with the ant-dropdown-open class. We would like to remove it once this is fixed here.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 181
- Forks
- 112
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus react-component/dropdown
-
Escape inside a focused submenu closes the entire Dropdown instead of returning to its parent itemOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 67/100
react-component/dropdown#274 ·
-
safari 浏览器手势放大后下拉菜单位置不正确Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
react-component/dropdown#245 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
react-component/dropdown#242 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
react-component/dropdown#241 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
react-component/dropdown#231 ·
Alle Issues in react-component/dropdown
Ähnliche Issues
-
area: infrastructure bug priority: low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
snapotter-hq/SnapOtter#4575 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
documentation server-memory v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/servers#5457 ·
Maintainer antworten meist innerhalb von 1 Tag
-
comp: ssr comp: zones type: feature version: current (v17+)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
angular/angularfire#3836 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag