A lot of the JavaScript in a component library rebuilds things the browser has since learned to do: focus traps for modals, scroll locks, menu positioning, error messages, scroll listeners. For Velocity 2.7 we went through the kit with Chrome’s modern web guidance and replaced the parts the platform now covers. That means less code to ship, fewer bugs to own, and behaviour that matches what visitors already know from their browser and operating system.
Nothing in your pages needs to change. The one API change and the visual changes are listed under Upgrading.
At a glance
| 2.6 | 2.7 | |
|---|---|---|
| Dialog | <div role="dialog">, hand-written focus trap, overflow: hidden on body | Native <dialog> with showModal() |
| Dropdown | Absolutely positioned, clipped by overflow parents | Native popover in the top layer, anchored to its button |
| Form errors | Shown only when the server rejects a submission | Shown after you leave a field, in the site’s language |
| Dark mode | Scrollbars and form controls stay light | color-scheme follows the theme |
| Next page | Prefetched on hover | Still prefetched on hover, with opt-in prerendering in Chromium |
| Destructive buttons | Unstyled (the token was never mapped) | Red, and passing WCAG AA in both themes |
Dialogs on the native <dialog>
Dialog used to be a <div> with role="dialog", roughly 60 lines of focus trapping, an Escape handler, and overflow: hidden on <body> to stop the page scrolling. That last part removed the scrollbar, so the whole layout shifted sideways every time a dialog opened.
Now it’s a <dialog> opened with showModal(). The browser contains focus, makes the rest of the page inert, closes it on Escape and on Android’s back gesture, and returns focus to the button that opened it. overscroll-behavior: contain stops the page scrolling behind it without touching the scrollbar. Backdrop clicks use the new closedby="any" attribute, with a short fallback for Safari, which doesn’t support it yet. Dialogs also animate out now, using @starting-style and transition-behavior: allow-discrete.
Opening one no longer needs a script:
<Button data-dialog-open="delete-dialog">Delete project</Button>
<Dialog id="delete-dialog" title="Delete project?" size="sm">
<p>All deployments will be removed.</p>
<div slot="footer" class="flex justify-end gap-3 px-6 pb-6">
<Button variant="outline" data-dialog-close>Cancel</Button>
<Button variant="destructive" data-dialog-close>Delete</Button>
</div>
</Dialog>window.openDialog(id) still works. The React island moved to <dialog> too and keeps the same open and onClose props.
Sheet was already built on <dialog>. It now also animates out, contains scrolling, and closes on a backdrop click everywhere.
Menus that can’t be clipped
Dropdown used to be an absolutely positioned <div>, so a parent with overflow: hidden or a lower z-index could cut it off. It’s now a native popover, which renders in the browser’s top layer above everything else. Escape and clicks outside close it without any script. The trigger announces itself as a menu button with its expanded state. Arrow keys, Home and End move through the items, and the menu is a single Tab stop instead of one per item.
Dropdown and Popover are placed with CSS anchor positioning, and flip above their button when there isn’t room below. Browsers without anchor positioning fall back to a few lines of script that measure and place the panel, so placement works everywhere.
Form errors when they help
Until now, Velocity’s forms only showed errors after the server rejected a submission. In 2.7, Input, Textarea and Select show an error once a visitor has left a field that isn’t valid. They use the browser’s :user-invalid state, so nothing turns red while someone is still typing and nothing appears on page load. The message is linked to the field with aria-describedby and aria-invalid, so screen readers read it with the field, and it clears as soon as the value is valid.
We nearly used the browser’s built-in message text, but that follows the visitor’s browser language, not your site’s. A French site would show English errors to anyone browsing in English. The messages now come from ui.ts in English, Spanish and French, and they say how to fix the problem: “Use at least 10 characters (you have 9).”
The contact form’s minlength and maxlength now match its server-side schema, so most mistakes are caught before a request is sent. Textarea also grows with what you type, using field-sizing: content (set autoResize={false} to turn it off).
Dark mode that reaches the browser
Velocity’s colours switch on a .dark class, but nothing told the browser about it, so scrollbars, date pickers, <select> popups and autofill stayed light on dark pages. color-scheme now follows the theme.
The theme toggle also handles one case better. If you switch to dark and then back to light on a light-mode system, it used to save “light”, which pinned the site to light even after your OS switched to dark at sunset. Now, switching back to what the default would show clears the saved choice, and the site goes back to following your system. The toggle also follows OS changes while the page is open, stays in sync across tabs, and keeps working when site data is blocked.
Instant next pages, if you want them
Velocity already prefetches internal links on hover. 2.7 adds speculation rules as an opt-in: set speculation: 'prerender' in site.config.ts, and Chromium browsers render the page in the background while the visitor is still hovering the link, so it opens the moment they click. The rules are served through InlineScript, so they’re hashed into the Content Security Policy like every other inline script.
We left it off by default on purpose. A prerendered page runs its scripts before anyone sees it. Google Analytics and Tag Manager handle that and wait until the page is shown. Ad pixels, other analytics tools and call-tracking scripts may not, and could count a visit that never happened. A starter kit shouldn’t make that call for every site built on it, so check the tags your site loads, then turn it on. Actions, assets, feeds, links that open in a new tab, downloads and logout-style URLs are excluded, and data-no-prerender leaves out any other link.
Smaller things
- Carousel: previous and next move one slide at a time instead of a fixed width. It adds a marker per position and announces “Slide 2 of 4” once scrolling settles. Slides that are links keep their link semantics.
- Mobile menu: the page behind it is now inert as well as blurred, so keyboard and screen-reader users stay in the menu. Escape returns focus to the menu button, and the menu closes if the window widens past the breakpoint.
- Floating header: an
IntersectionObserverreplaces a listener that ran on every scroll frame.
The bug we found along the way
While checking contrast on the new error states, we found that --color-destructive had never been mapped into Tailwind’s theme. Every bg-destructive, text-destructive and border-destructive class (about 60 of them) compiled to nothing. Destructive buttons weren’t red, and server-side form errors had no colour.
Mapping the token showed the next problem: the theme’s red failed WCAG AA, at 3.9:1 with white text in light mode and 3.6:1 in dark. The default and Midnight themes now use a deeper red in light mode (6.1:1) and a light red with dark text in dark mode (7.1:1). New end-to-end tests run axe on destructive buttons and visible field errors in both modes, so this can’t silently break again.
Tests
2.7 adds end-to-end tests for the native modal (Escape and focus return), Dropdown’s keyboard behaviour, the theme toggle’s storage and color-scheme, Carousel stepping and markers, field errors that wait for interaction and use the site’s language, and contrast for destructive and error states. That’s 80 end-to-end tests, all passing, along with 352 unit tests and the scaffold matrix across all nine project shapes.
Upgrading
Commit your work, then run:
npm create velocity-astro@latest upgrade
npm install
npm run validateWhat to check afterwards:
dialogElement.open(): if your own code called this, switch towindow.openDialog(id)orshowModal(). On a<dialog>,openis a built-in property, not a method.close()still works.- Destructive styling now renders. Expect red delete buttons and red error text where you used them.
- Custom themes: if you wrote your own theme file, check that
--destructivehas at least 4.5:1 contrast with--destructive-foregroundand with your background. - Prerendering is opt-in. If you turn it on with
speculation: 'prerender', check your other tags first: GA4 and Tag Manager wait until the page is shown, but your own scripts that count views or conversions on load should checkdocument.prerendering. Adddata-no-prerenderto links whose pages change something on load.
The upgrade guide has the details, and the helpers reference covers the new attributes and utilities.
Get it
npm create velocity-astro@latest