Phenomenon
When a CSS media query is triggered (e.g., rotating a device or shifting container width), browsers often trigger a layout pass that can invalidate the current DOM selection in mobile browsers, leading to the virtual keyboard being dismissed.
Reproduction Steps
- Open a contenteditable field on a mobile device.
- Focus the field so the virtual keyboard appears.
- Rotate the device (Portrait to Landscape).
- Observe that the keyboard often disappears.
Observed Behavior
The viewport change triggers a reflow that causes the browser to lose the active element focus if the element’s bounding box moves significantly.