Skip to content

fix(Offcanvas): in-place panel stays interactive, focus returns on close - #284

Merged
xidedix merged 7 commits into
v5.7from
fix/offcanvas-in-place
Oct 7, 2026
Merged

xidedix merged 7 commits into
v5.7from
fix/offcanvas-in-place

Conversation

@xidedix

@xidedix xidedix commented Oct 7, 2026

Copy link
Copy Markdown
Member

A closed offcanvas that CSS lays out in place (responsive from its breakpoint up, .navbar-expand-* .offcanvas from the expand breakpoint up) was visible but dead: the host kept inert, role="dialog", aria-modal="true" and the hiding class from the first render, so nothing inside could be clicked or focused and screen readers announced a modal dialog. The dropdown in the dark navbar example did not open for that reason.

role and aria-modal are rendered only while the offcanvas is open, as in the vanilla edition. inert is dropped from a closed offcanvas once its computed position is read and is not fixed; until the first read, and on the server, it stays as before. The position is re-read after every render and on window resize. The hiding class is added only when an open offcanvas closes. The focus trap is enabled only while open and no longer auto-captures focus at init, which would have moved focus into an in-place panel on page load; opening focuses the offcanvas host as before.

An open offcanvas that was shown as a fixed panel is closed when a window resize lays it out in place, as in the vanilla edition. An offcanvas in .navbar-expand-* opened on a narrow window no longer stays a modal dialog with a backdrop after the window is widened. One that was never a fixed panel, for example kept position-absolute by author CSS, stays open, so a mobile soft keyboard does not close it. With portal the offcanvas sits in the container while open, stays a fixed panel and is not closed.

On close, and when an open offcanvas is destroyed, focus returns to the cOffcanvasToggle that opened it, else to the element focused when it opened. It moves only while focus is inside the offcanvas or on the body, and skips a target that is detached or cannot take focus. Returning to the toggle covers Safari, where clicking a button does not focus it. Docs: coreui/coreui-angular-docs branch fix/offcanvas-in-place.

role and aria-modal only while open; inert only for a closed panel (computed position fixed), re-read after render and on resize; hiding class only for a real hide; focus trap enabled only while open, no auto-capture.
…irst

On close or destroy while open, focus goes to the cOffcanvasToggle that opened the offcanvas, else to the element focused when it opened; only when focus is inside the offcanvas or on body, and skipping a target that is detached or cannot take focus.
@xidedix
xidedix merged commit a36c77f into v5.7 Oct 7, 2026
9 checks passed
@xidedix
xidedix deleted the fix/offcanvas-in-place branch October 8, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant