Keep your coding agent up to date with the latest web best practices
Release v0.0.67
github-actions[bot]dc6dc6ad17a7
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex 375a564..31bba63 100644--- a/.claude-plugin/marketplace.json+++ b/.claude-plugin/marketplace.json@@ -8,7 +8,7 @@"name": "modern-web-guidance","source": "./","description": "Google Chrome's agent skills collection",- "version": "0.0.66"+ "version": "0.0.67"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex eb56d63..4666391 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's agent skills collection",- "version": "0.0.66",+ "version": "0.0.67","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex 1172126..f48cac6 100644--- a/README.md+++ b/README.md@@ -2,10 +2,10 @@This curated collection of skills, tools, and AI-ready documentation injects Chrome's web platform knowledge directly into your workflow, ensuring your coding agent builds apps that are modern, fast, and secure by default.-#### Skill Coverage in `v0.0.66`+#### Skill Coverage in `v0.0.67`<details>-<summary><strong>77 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>+<summary><strong>78 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intersection observer`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>- **[::backdrop](https://webstatus.dev/features/backdrop), [<dialog>](https://webstatus.dev/features/dialog), [overlay](https://webstatus.dev/features/overlay), [Popover](https://webstatus.dev/features/popover), [@starting-style](https://webstatus.dev/features/starting-style), [transition-behavior](https://webstatus.dev/features/transition-behavior)**- **animate-to-from-top-layer**: Animate elements such as dialogs, popovers, and tooltips as they're entering/exiting the top layer.@@ -94,8 +94,8 @@ This curated collection of skills, tools, and AI-ready documentation injects Chr- **deliver-optimized-decorative-images**: Deliver optimized decorative images (such as backgrounds, UI icons, or complex masks) by simultaneously providing next-generation image formats (like AVIF or WebP) alongside multiple pixel densities (like 1x and 2x) so the browser can dynamically negotiate the best combination of file size and visual quality for the user's device capabilities.- **[Individual transform properties](https://webstatus.dev/features/individual-transforms)**- **individual-transform-properties**: Animate or override individual CSS transform properties (e.g. translate, rotate, scale) independently of other transform properties on a single element.-- **[inert](https://webstatus.dev/features/inert), [Popover](https://webstatus.dev/features/popover), [Scroll snap](https://webstatus.dev/features/scroll-snap)**- - **light-dismiss-content-overlay**: Create swipeable layered navigation menus using native overlays and scroll gestures.+- **[inert](https://webstatus.dev/features/inert), [Intersection observer](https://webstatus.dev/features/intersection-observer), [Popover](https://webstatus.dev/features/popover), [Registered custom properties](https://webstatus.dev/features/registered-custom-properties), [Scroll-driven animations](https://webstatus.dev/features/scroll-driven-animations), [scroll-initial-target](https://webstatus.dev/features/scroll-initial-target), [Scroll snap](https://webstatus.dev/features/scroll-snap)**+ - **navigation-drawer**: Create a navigation drawer component that, when triggered from a menu button, slides in from the side overlayed on top of existing page content, and slides out when dismissed (by swiping away, tapping outside, or pressing escape).- **[Interest invokers](https://webstatus.dev/features/interest-invokers)**- **interest-triggered-action-previews**: Show a live preview of a button's effect when a user signals interest (e.g. hovering, focusing, or long-pressing) but before they commit to clicking.- **[Intl.DurationFormat](https://webstatus.dev/features/intl-duration-format), [Temporal](https://webstatus.dev/features/temporal)**diff --git a/gemini-extension.json b/gemini-extension.jsonindex 661a038..78153cd 100644--- a/gemini-extension.json+++ b/gemini-extension.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's web development agent skills.",- "version": "0.0.66",+ "version": "0.0.67","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex 4147784..e3ea3b7 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "modern-web-guidance","displayName": "Modern Web Guidance","description": "Curated collection of agent skills for modern web development.",- "version": "0.0.66",+ "version": "0.0.67","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web/guides/user-experience/light-dismiss-content-overlay.md b/skills/modern-web/guides/user-experience/light-dismiss-content-overlay.mddeleted file mode 100644index 7369246..0000000--- a/skills/modern-web/guides/user-experience/light-dismiss-content-overlay.md+++ /dev/null@@ -1,162 +0,0 @@-# Creating Swipeable Layered Navigation--Modern mobile navigation requires a "swipe to close" gesture. While the native `popover` API handles Top Layer promotion and accessibility well, it doesn't natively support swipe gestures.--We can achieve the best of both worlds by combining `popover="manual"` with a CSS Scroll Snap container, and inerting the page with JavaScript.--### Core Concept--1. **The Popover:** Acts as the top-layer container. Use `popover="manual"` to fully control its visibility and lifecycle. While `popover="auto"` provides native light dismissal, it actively conflicts with this scroll-snap gesture pattern (native backdrop clicks fail due to the element's 100vw bounding box, and native `Escape` dismissal instantly hides the menu abruptly without animation).-2. **The Scroll Container:** Inside the popover, we create a horizontally scrolling container with `scroll-snap-type: x mandatory`.-3. **The Drawer & Ghost:**- - The **Drawer** is the first snap point (visible when scrolled to 0).- - A **Ghost Element** (spacer) is the second snap point (visible when scrolled to the menu width).-4. **The Backdrop:** Use the native `::backdrop` pseudo-element for the dimmed background. By linking its opacity to the scroll position using CSS custom properties via a `scroll` event listener, the fade feels fully organic with the swipe gesture.-5. **Gesture Logic:** "Swiping left" naturally scrolls the container from the Drawer (0) to the Ghost (Width). This feels like pushing the menu away.--### Implementation Guidelines--* Use `popover="manual"` to ensure the menu appears above all other content (Top Layer), avoiding the strict native dismiss logic of `auto`.-* Rely on CSS Scroll Snap for gesture physics. It provides a native, smooth 1:1 touch response.-* Use the `scrollend` event (or a scroll polling fallback) to synchronize the JavaScript state (open/closed) with the physical scroll position.-* Tie the `::backdrop` opacity directly to the scroll position via CSS custom properties. It maps exactly 1-to-1 without artificial delays.-* **MANDATORY**: Manually manage the `inert` attribute on your main content. When the menu is open, the main content MUST be inert. When closed (scrolled away), it must be interactive.-* Manually handle backdrop clicks and the `Escape` key. Because we use `popover="manual"`, you must provide the logic to trigger the smooth scroll-out animation when the user intentionally dismisses the menu outside of swiping.--### Recommended Implementation--Here is a minimal example showing how to combine Popover and Scroll Snap for swipeable overlays.--**HTML Structure:**-```html-<!-- MANDATORY: Use popover="manual" to control lifecycle and avoid conflicts with gestures -->-<div id="swipe-overlay" popover="manual">- <!-- The actual menu/drawer -->- <nav class="drawer" id="side-nav">- <!-- Menu items go here -->- <button class="close-btn">Close</button>- </nav>- <!-- A ghost spacer is needed as the second snap point. You can use a real element or a pseudo-element like ::after -->-</div>-```--**Key CSS:**-```css-#swipe-overlay {- border: none;- padding: 0;- margin: 0;- width: 100vw;- height: 100vh;- background: transparent;-- /* Enable horizontal scroll snap */- overflow-x: auto;- scroll-snap-type: x mandatory;- overscroll-behavior-x: contain;- scroll-behavior: smooth;-}--#swipe-overlay:popover-open {- display: flex;-}--.drawer {- width: 280px; /* Or any width less than 100vw */- height: 100%;- flex-shrink: 0;- scroll-snap-align: start; /* Snap point 1 (Open) */-}--/* Ghost Spacer using pseudo-element */-#swipe-overlay::after {- content: '';- flex: 0 0 100vw;- height: 100%;- scroll-snap-align: start; /* Snap point 2 (Closed) */-}--/* Link backdrop opacity to a CSS variable */-#swipe-overlay::backdrop {- background-color: rgba(0, 0, 0, var(--backdrop-alpha, 0));-}-```--**Key JavaScript:**-```javascript-const overlay = document.getElementById('swipe-overlay');-const nav = document.getElementById('side-nav');-const main = document.getElementById('main-content');-let isAnimating = false;--function openMenu() {- overlay.showPopover();- // Snap to ghost spacer initially to animate in- overlay.scrollTo({ left: nav.offsetWidth, behavior: 'instant' });- main.setAttribute('inert', '');- isAnimating = true;-- // Force layout and animate to drawer open position- requestAnimationFrame(() => {- overlay.scrollTo({ left: 0, behavior: 'smooth' });- setTimeout(() => isAnimating = false, 500);- });-}--function closeMenu() {- // Animate to ghost spacer, triggering scrollend to hide popover- overlay.scrollTo({ left: nav.offsetWidth, behavior: 'smooth' });-}--// Live Backdrop Update (Immediate feedback during swipe)-overlay.addEventListener('scroll', () => {- const width = nav.offsetWidth;- // Calculate how far we have scrolled relative to the menu width- const fraction = 1 - (overlay.scrollLeft / width);- // Map this to a backdrop opacity (max 0.4 in this example)- overlay.style.setProperty('--backdrop-alpha', Math.max(0, fraction * 0.4));-}, { passive: true }); // Passive listener for performance--// Handle gestures completing-overlay.addEventListener('scrollend', () => {- if (isAnimating) return; // Prevent early closure during opening animation-- const width = nav.offsetWidth;- // If we scrolled past half the width, close the menu- if (overlay.scrollLeft > (width / 2)) {- if (overlay.matches(':popover-open')) {- overlay.hidePopover();- }- main.removeAttribute('inert');- } else {- // Otherwise keep it open and ensure main content is inert- main.setAttribute('inert', '');- }-});-```--### Fallback strategies--#### popover--Baseline status for Popover: Newly available. It's been Baseline since 2025-01-27.--The Popover API is not supported in older browsers. Without it, the menu cannot be promoted to the Top Layer, which means it won't naturally sit above all other page content and won't receive the `::backdrop` pseudo-element.--* **Guidance:** For browsers that do not support `popover`, fall back to a `<div>` positioned with `position: fixed` and a high `z-index`. Manually manage focus trapping and the backdrop overlay using JavaScript. Replace any `::backdrop` styles with a separate fixed-position overlay element and toggle visibility using a class. Check support with `'popover' in HTMLElement.prototype`.--#### scroll-snap--Baseline status for Scroll snap: Widely available. It's been Baseline since 2020-01-15.--CSS Scroll Snap is widely supported, but in environments where it is absent, the scroll container will still function — the drawer will open and close — but the snap-to-position physics will be missing, leaving the menu in an indeterminate in-between position after a swipe.--* **Guidance:** Listen for the `scrollend` event and programmatically snap the container to the nearest position (0 or the full drawer width) using `scrollTo({ left: targetX, behavior: 'smooth' })` if `scroll-snap-type` is not supported. Detect support with `CSS.supports('scroll-snap-type', 'x mandatory')`.--#### inert--Baseline status for inert: Widely available. It's been Baseline since 2023-04-11.--The `inert` attribute is broadly supported in modern browsers. In browsers that do not support it, the main page content will remain interactive while the menu is open, creating a keyboard trap and accessibility issue.--* **Guidance:** Use the `inert` polyfill to replicate the behavior in unsupported browsers. Conditionally load it only when needed: `if (!('inert' in HTMLElement.prototype)) { await import('path/to/inert-polyfill.js'); }`. As a manual fallback, set `aria-hidden="true"` on the main content and apply `tabindex="-1"` to all focusable descendants while the menu is open, reversing both on close.diff --git a/skills/modern-web/guides/user-experience/navigation-drawer.md b/skills/modern-web/guides/user-experience/navigation-drawer.mdnew file mode 100644index 0000000..15ff193--- /dev/null+++ b/skills/modern-web/guides/user-experience/navigation-drawer.md@@ -0,0 +1,347 @@+## Overview++A navigation drawer is a panel that slides in from the edge of the viewport over the page content, dimming everything behind it. It is opened from a trigger button and dismissed by swiping the panel off-screen, tapping the dimmed backdrop, or pressing Escape.++This guide implements the drawer as:++- A `popover="manual"` element promoted to the top layer so the panel and its `::backdrop` overlay every other element on the page, regardless of stacking context.+- A horizontally scrolling container with two CSS scroll-snap stops — one for "open", one for "closed" — so the swipe gesture is handled natively by the browser. This delivers momentum, velocity, and interruption tracking for free, with no JavaScript pointer-event code.+- A scroll-driven animation that ties the backdrop's opacity to the scroll position, so the dim fades in and out smoothly as the user drags the panel.+- An `IntersectionObserver` on the panel that detects when it has fully entered or fully left the viewport, and uses those moments to update focus, `aria-expanded`, and `inert`.++This approach is preferred over JavaScript-driven `transform` animations because the scroll mechanism gives the user direct control of the panel's position (their finger drives it, not a tween) and it much more closely matches the interaction patterns that users are accustomed to in native mobile apps.++## Implementation++### 1. Markup++The drawer is a single popover containing a horizontal scroller, which contains the visible "sheet". The trigger button lives in the page content.++```html+<!-- popover="manual" is REQUIRED. Do not use popover="auto" or "hint". -->+<div class="Drawer" id="drawer" popover="manual">+ <div class="Drawer-scroller">+ <nav class="Drawer-sheet" tabindex="-1">+ <!-- tabindex="-1" makes the sheet programmatically focusable so we+ can move focus into it when the drawer opens, without adding it+ to the natural tab order. -->+ <ul>+ <li><a href="/page-1">Page 1</a></li>+ <li><a href="/page-2">Page 2</a></li>+ <!-- ... -->+ </ul>+ </nav>+ </div>+</div>++<main>+ <header>+ <!-- aria-controls links the trigger to the drawer; aria-expanded+ reflects the current state for assistive tech. -->+ <button id="drawer-open"+ aria-label="Open menu"+ aria-expanded="false"+ aria-controls="drawer">+ <!-- menu icon SVG -->+ </button>+ </header>+ <!-- Page content. -->+</main>+```++### 2. Styles++#### Reset the popover and fill the viewport++The popover must cover the whole viewport so its `::backdrop` dims the entire page and the swipe surface extends edge-to-edge. The default user-agent popover styles (centered, auto-sized, bordered) get in the way and must be reset.++```css+.Drawer {+ /* min() caps the sheet width on large screens but on a phone leaves+ a 20% peek of page content visible, which is the affordance that+ tells the user they can tap outside to dismiss. */+ --drawer-width: min(20em, 80dvw);++ /* Custom property driven by the scroll-driven animation below.+ 0 = drawer fully closed (transparent backdrop).+ 1 = drawer fully open (visible backdrop). */+ --drawer-backdrop: 0;++ /* Reset UA popover style that would constrain the element. */+ width: auto;+ height: auto;+ background: transparent;+ border: 0;+ overflow: visible;+}++/* Style the popover's ::backdrop to achive the overlay effect and+ provide visual affordances indicating that the rest of the page is inert */+.Drawer::backdrop {+ background: #000;+ /* Use calc() to limit the opacity range so the content beneath is visible */+ opacity: calc(var(--drawer-backdrop) / 2);+}+```++#### Build the swipe surface with scroll snap++The scroller is a horizontal grid wider than the viewport: column 1 holds the sheet (width `--drawer-width`), column 2 is an empty pseudo-element spacer the width of the viewport. Snapping between the two columns is what opens and closes the drawer.++```css+.Drawer-scroller {+ position: relative;+ display: grid;+ /* Sheet on the left, full-viewport spacer on the right. The user+ scrolls between the two snap stops to open and close. */+ grid-template-columns: var(--drawer-width) 100%;++ overflow-x: scroll;+ /* Stop the swipe from chaining into the page's vertical scroll+ when the user reaches either snap edge. */+ overscroll-behavior: none;+ scrollbar-width: none;+ /* `mandatory` guarantees the drawer always settles fully open or+ fully closed — never half-open after a partial swipe. */+ scroll-snap-type: x mandatory;+}++/* Enable smooth scrolling natively, but only if the user has not+ requested reduced motion. */+@media (prefers-reduced-motion: no-preference) {+ .Drawer-scroller {+ scroll-behavior: smooth;+ }+}++/* The empty spacer that creates the "closed" snap stop. */+.Drawer-scroller::after {+ content: '';+ scroll-snap-align: end;+ /* Open the popover already scrolled to this stop (drawer off-screen),+ so the JS only needs to scroll to the open position to+ animate it in. */+ scroll-initial-target: nearest;+}++.Drawer-sheet {+ display: grid;+ grid-template-rows: auto 1fr;+ /* Use `svh` (small viewport height) — not `vh` or `dvh` — so the+ sheet height does not jump when the iOS Safari address bar+ resizes mid-swipe. */+ height: 100svh;++ background: #333;+ color: #fff;+ overflow-y: auto;+ scroll-snap-align: start;+ scrollbar-width: none;+}+```++#### Tie the backdrop opacity to the scroll position++A scroll-driven animation maps `--drawer-backdrop` from 1 (open) to 0 (closed) across the scroller's range, so the backdrop fades in and out perfectly synced with the drag.++```css+/* MANDATORY: Wrap this entire block in @supports. Browsers that don't+ support animation-timeline still parse the @keyframes and would+ apply the animation's `0%` value (--drawer-backdrop: 1) at all+ times, leaving the backdrop permanently opaque. The @supports gate+ ensures the animation is only registered where it actually works. */+@supports (animation-timeline: scroll()) {+ .Drawer {+ /* timeline-scope lets .Drawer reference a scroll-timeline that+ is defined on its descendant (the scroller). Without this, the+ timeline name is not visible to the .Drawer element. */+ timeline-scope: --drawer-fade;+ animation: fade-drawer-backdrop linear both;+ animation-timeline: --drawer-fade;+ }++ .Drawer-scroller {+ /* The horizontal scroll position of this element drives the+ timeline named `--drawer-fade`. */+ scroll-timeline: --drawer-fade x;+ }++ /* @property is REQUIRED. Without registering --drawer-backdrop with+ a `<number>` syntax, the browser treats it as a string and cannot+ interpolate it — the backdrop would jump from 0 to 1 with no+ fade. */+ @property --drawer-backdrop {+ syntax: '<number>';+ inherits: true;+ initial-value: 0;+ }++ @keyframes fade-drawer-backdrop {+ /* Scroll position 0 = drawer fully open = backdrop visible. */+ 0% { --drawer-backdrop: 1 }+ /* Scroll position 100% = drawer fully closed = backdrop hidden. */+ 100% { --drawer-backdrop: 0 }+ }+}+```++### 3. Open and close the drawer++Opening is two steps: promote the popover to the top layer, then scroll the sheet into view. Closing is one step: scroll back to the spacer; an observer (step 4) hides the popover once the sheet is fully off-screen.++```js+const drawer = document.getElementById('drawer');+const openBtn = document.getElementById('drawer-open');+const scroller = drawer.querySelector('.Drawer-scroller');+const sheet = drawer.querySelector('.Drawer-sheet');++function openDrawer() {+ // Show the popover first so the element is in the top layer before+ // we trigger any scrolling. `scroll-initial-target` (set on the+ // ::after spacer) places the initial scroll position at the closed+ // stop, so the drawer enters the top layer already off-screen.+ drawer.showPopover();++ // Scroll the sheet into view. The `behavior: 'auto'` option defers+ // to the CSS `scroll-behavior` property, which will be smooth unless+ // the user prefers reduced motion. Snap takes over at the end and+ // locks the drawer fully open.+ scroller.scrollTo({left: 0, behavior: 'auto'});+}++function closeDrawer() {+ // Scroll back to the spacer. Do NOT call hidePopover() here —+ // doing so would remove the element from the top layer mid-animation+ // and the close animation would not be visible. The+ // IntersectionObserver in step 4 hides the popover once the sheet+ // has actually left the viewport.+ scroller.scrollTo({left: scroller.offsetWidth, behavior: 'auto'});+}+```++### 4. Detect open and closed state++Use an `IntersectionObserver` on the sheet — not the scroll position — as the source of truth for the drawer's state. The observer fires regardless of how the sheet moved (user swipe, programmatic scroll, snap settle), so all dismissal paths converge in the same callback.++```js+function onDrawerOpened() {+ // Mark the rest of the page inert so keyboard and screen-reader+ // users cannot tab into content hidden behind the drawer.+ document.querySelector('main').inert = true;+ openBtn.setAttribute('aria-expanded', 'true');+ // Move focus into the drawer for keyboard users.+ sheet.focus();+}++function onDrawerClosed() {+ // Hide the popover only after the close animation completes,+ // so the slide-out is visible to the user.+ drawer.hidePopover();+ document.querySelector('main').inert = false;+ openBtn.setAttribute('aria-expanded', 'false');+}++// Treat "any pixel of the sheet visible inside the popover root" as+// "open enough to count as not closed". This threshold is intentionally+// tiny so the closed callback only fires once the sheet is truly gone.+const visibleThreshold = 1 / window.innerWidth;++const observer = new IntersectionObserver(+ (entries) => {+ // During programmatic scrolling the observer can deliver multiple+ // entries in one batch. Only the most recent describes the+ // current state; earlier entries are intermediate positions.+ const entry = entries.at(-1);+ if (entry.intersectionRatio < visibleThreshold) onDrawerClosed();+ if (entry.intersectionRatio === 1) onDrawerOpened();+ },+ // root: drawer makes the popover element the intersection root,+ // so the ratio reflects the sheet's visibility within the popover+ // (i.e. how much of it has been swiped on-screen).+ {root: drawer, threshold: [visibleThreshold, 1]},+);+observer.observe(sheet);+```++### 5. Wire up the trigger and dismissal handlers++```js+// Open trigger.+openBtn.addEventListener('click', openDrawer);++// Light-dismiss: a tap on the dimmed area (anywhere inside the+// popover but outside the sheet) closes the drawer. We implement+// this manually because popover="manual" disables the browser's+// built-in light-dismiss (which would also fire mid-swipe — see step 1).+drawer.addEventListener('click', (event) => {+ if (!sheet.contains(event.target)) closeDrawer();+});++// Escape key. Listen on document because focus may be inside the+// drawer when the user presses Escape.+document.addEventListener('keydown', (event) => {+ if (event.key === 'Escape') closeDrawer();+});+```++### Fallback strategies++The drawer's core mechanics — scroll snap, `IntersectionObserver`, and `inert` — are all Baseline Widely available and required for the component to function. The popover API, the scroll-driven animation that fades the backdrop, and `scroll-initial-target` are progressive enhancements with simple fallbacks that can be easily implemented if wide browser support is required.++#### Backdrop fade fallback (no `animation-timeline` support):++Scroll-driven animations has limited availability.++Detect with `CSS.supports('animation-timeline: scroll()')` and write `--drawer-backdrop` from a `scroll` event listener if not supported. The CSS `@supports` block in step 2 ensures the keyframes never apply in unsupported browsers, so the JavaScript value is the only writer.++```js+if (!CSS.supports('animation-timeline: scroll()')) {+ scroller.addEventListener('scroll', () => {+ // Same mapping as the @keyframes: 0 scroll = 1 (open),+ // sheet-width scroll = 0 (closed).+ const ratio = 1 - scroller.scrollLeft / sheet.offsetWidth;+ drawer.style.setProperty('--drawer-backdrop', ratio);+ });+}+```++#### Initial scroll position fallback (no `scroll-initial-target` support):++scroll-initial-target has limited availability.++Detect with `CSS.supports('scroll-initial-target', 'nearest')` and inside `openDrawer()`, jump-scroll the scroller to the closed position immediately after `showPopover()`. Without this, the drawer would appear instantly in the open position with no slide-in animation.++```js+async function openDrawer() {+ drawer.showPopover();++ if (!CSS.supports('scroll-initial-target', 'nearest')) {+ // Jump-scroll to the closed stop so the scroll below+ // animates the drawer in from off-screen.+ scroller.scrollTo({left: scroller.offsetWidth, behavior: 'instant'});+ // Wait two animation frames for the jump-scroll to commit.+ // A single rAF is not enough — the second `scrollTo` would+ // cancel the first before the browser has a chance to apply it.+ await new Promise((r) =>+ requestAnimationFrame(() => requestAnimationFrame(r))+ );+ }++ scroller.scrollTo({left: 0, behavior: 'auto'});+}+```++#### `@property` fallback (no registered custom properties):++Baseline status for Registered custom properties: Newly available. It's been Baseline since 2024-07-09.++`@property` is only needed because the scroll-driven animation interpolates `--drawer-backdrop` between keyframes — without registration, the property would be treated as a string and would jump between 0 and 1 with no fade. If the scroll-driven animation fallback above is in place, that JavaScript writes a fresh numeric string to `--drawer-backdrop` on every scroll frame and never interpolates, so no seprarate `@property` fallback is needed since all browsers that support scroll-driven animations also support `@property`.+++#### Popover API fallback (no `popover` attribute support):++Baseline status for the api.HTMLElement.showPopover capability: Newly available. It's been Baseline since 2024-04-16.++Because this component uses `popover="manual"` and implements dismissal entirely from JavaScript, it does not depend on the popover API's defining behaviors — light-dismiss, the `popovertarget` attribute, top-layer-managed Escape handling, or focus management. The only popover features it actually uses are top-layer promotion (via `showPopover()`) and the `::backdrop` pseudo-element, which have been Baseline since April 2024.++If wider browser support is needed, do not branch on feature detection — simply do not use popover at all. Drop the `popover="manual"` attribute, replace top-layer promotion with `position: fixed` and a high `z-index`, replace `::backdrop` with a sibling element styled identically (using the same `--drawer-backdrop` custom property), and toggle visibility from a class instead of `showPopover()`/`hidePopover()`. The rest of the component (scroll snap, the scroll-driven backdrop animation, the `IntersectionObserver`, and the dismissal handlers) is unchanged.