
The Final Off-Canvas Navigation: Revisited
The Final Off-Canvas Navigation: Revisited êŽë š
So I may have used the word âfinalâ rather ambitiously when I blogged âThe Final Off-Canvas Navigation?â two years ago. At least I left the door open with a question mark? Iâve since made big changes to the implementation.
The New (New) Version
Checkout my new demo on CodePen (dbushell).
All the good stuff remains like focus state, keyboard navigation, right-to-left styles. This is still experimental I donât consider it ready to use just yet.
Dialog and Popover
Modern web browsers now support dialog elements and popover attributes. These two allow for accessible interactivity with zero JavaScript. That means less code. There is no longer a need for the âno scriptâ version that looks and behaves differently. Core functionality just works. Iâm using a sprinkling of JavaScript for minor improvements.
CSS Animations
My previous version used overflow and scroll-snap to show and hide sub-menus. That proved to be janky and gave little control over the transition effect. Now popover does the hard work with CSS animations.
Adding an opening transition is easy with the :popover-open pseudo-class. Closing transitions are tricky. Chrome appears to respect closing animations. Other browsers hide the popover immediately. I donât know what is âspecâ here. For now Iâve used JavaScript to delay the actual hidePopover() until the animation ends.
Iâve also found ::backdrop transitions to behave strangely for some CSS properties. In fact this pseudo-element behaves just plain weird from my experience.
Ready to use?
Short answer: I donât know, so I wouldnât recommend it. While browser support is strong itâs all very recent. Iâd appreciate any accessibility related feedback on this implementation.
Find me at @db (social.lol or email me.
A closing thought: do you really want your entire navigation dumped into an off-canvas <dialog> modal?