This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.
Here, a dialog is an element your component renders over the page, not a popup page that opens with @wix/site-service-lightbox.
To keep keyboard focus inside an open dialog, follow these steps:
Before the dialog opens, save the element that has focus, so you can return focus to it later:
Once the dialog element is on the page, set the trap with the value of its id attribute:
Move focus to the first control in the dialog. The service doesn't move focus:
When the dialog closes, release the trap and return focus to the element you saved:
If the component can unmount while the dialog is open, release the trap then too. Release it only while the dialog is open, because reset() also releases a trap that another component set. In a React component, return the release from an effect that depends on your own isOpen state for the dialog:
To keep keyboard focus in a menu and the button that opens it, follow these steps:
Collect the values of the id attributes of the menu element and its toggle button.
When the menu opens, set the trap with both IDs:
Move focus to the first item in the menu, because the service doesn't move focus:
When the menu closes, release the trap and return focus to the toggle button:
Last updated: 21 October 2026