-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search modal view transitions #1831
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredible. What an insanely nice yet simple interaction. Well done. 💯
src/utils/startViewTransition.js
Outdated
const motionSafe = | ||
typeof window !== 'undefined' | ||
? window.matchMedia('(prefers-reduced-motion: no-preference)') | ||
: undefined | ||
|
||
export function startViewTransition(cb) { | ||
if (motionSafe?.matches && typeof document?.startViewTransition === 'function') { | ||
document.startViewTransition(() => { | ||
flushSync(cb) | ||
}) | ||
} else cb() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this prevent the transition from animating when prefers-reduced-motion
is active, which will trigger the current non-animated behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup!
aa4af88
to
ac92181
Compare
7ffbf14
to
9fb27fa
Compare
83ba838
to
b7f6caf
Compare
This reverts part of commit b7f6caf.
af7a12f
to
072aa88
Compare
I have no idea if the team is interested in something like this, but I figured I'd propose it 🙂
Live demo: tailwind-search.barvian.me (the Vercel previews are choppy for me; I think it's the dev toolbar)
search.mp4
I've always thought the search bars on the site would look great if they smoothly transitioned to the modal. The View Transitions API makes this trivial to implement while gracefully falling back to existing behavior if the browser doesn't support it or if the user prefers reduced motion. Plus, there's no lag because the modal is fully active while it's transitioning, so you can start typing immediately without waiting for the animation to end. I used a
linear()
spring transition with a perceptual duration of250ms
to keep things feeling snappy. I made sure to support the small-screen version too:sm-search.mp4
The only noticeable difference from prod for browsers that support View Transitions is shown above 👆🏻: the "Quick search..." button on the homepage disappears whenever the search icon in the header is visible (on prod both are visible between
sm
andmd
breakpoints). This dramatically simplifies the view transition logic. Like everything else, though, it only applies if the user's browser supports view transitions and is "motion-safe".It even works with route transitions:
route-transitions.mp4
I'm curious to hear your thoughts, if any!