Before
The modal opens, but keyboard focus can escape to background controls. Escape doesn’t close.
Tip: open the modal, then press Tab a few times. You can reach background controls even though a modal is on screen.
These should ideally be unreachable while the modal is open.
After
The modal traps keyboard focus, supports Escape, and returns focus to the opener on close.
Tip: after opening, Tab stays inside the modal. Esc closes and returns focus to “Open inventory modal”.
In a real app you’d also “inert” the background. Here we use aria-hidden while the modal is open.
Tip: press Space to toggle emphasis.