Skip to content
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

Sidebar useIsMobile doesn't change when slowly #156

Open
AuTa opened this issue Dec 14, 2024 · 2 comments
Open

Sidebar useIsMobile doesn't change when slowly #156

AuTa opened this issue Dec 14, 2024 · 2 comments

Comments

@AuTa
Copy link

AuTa commented Dec 14, 2024

When I expand the window slowly, the isMobile doesn't change to false.

Add console.log(window.innerWidth, e.matches) get 767 false, but MOBILE_BREAKPOINT is 768, so setIsMobile is true.

Use event.matches or mql.matches or <=?

I find a questions: html - Media query max-width not working inclusively - Stack Overflow. You can see: https://jsfiddle.net/e0hdyqc9/, the 767 is white.

Maybe with max-width when the number is even, media match includes the number; when the number is odd, media match doesn't include the number.

@stefan-karger
Copy link
Owner

stefan-karger commented Dec 16, 2024

useIsMobile is a direct port of the hook from shadcn:
https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/hooks/use-mobile.tsx

but it's weird that it doesn't trigger at 767 since there is 1px subtracted from the breakpoint width:
window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)

maybe also open an issue at shadcn/ui so it will stay consistent :)

@AuTa
Copy link
Author

AuTa commented Dec 19, 2024

shadcn-ui/ui#6123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants