-
Notifications
You must be signed in to change notification settings - Fork 674
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
Media match breakpoint index #1346
Media match breakpoint index #1346
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/systemui/theme-ui/49159k1yo [Deployment for cf19ba6 canceled] |
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.
Looks good! Is this breaking? Do we need to update any docs?
its is breaking for users who relying on the buggy implementation before - hopefully not that many. IN normal use, it is not breaking, butin any case I marked it now as BREAKING in CHANGELOG |
Wait, I don't get it. Given 3 breakpoints, there are 4 possible responsive values, right?
How does this change affect usage of |
Is this bug still a problem/do we want this PR now? |
Closing as stale, but we can totally re-open! |
hi there 👋 I believe there's a mismatch in terminology here and consequently, in the implementation. As stated in the first comment,
In the implementation:
Consider this example: const breakpoints = ['640px', '1240px'];
const bpIndex = useBreakpointIndex(); // Can be one of: `0 | 1 | 2` because the hook returns the *number* of matched breakpoints
const bpIndex2 = useBreakpointIndex({ defaultIndex : 2 }); // throws an error because defaultIndex, in this implementation, tracks the index of the breakpoint (not their number). Basically, what Quick fixIf believe an easy fix for this is simply allowing // /match-media/src/index.ts
if (typeof defaultIndex !== 'number') {
// ...
} else if (defaultIndex < 0 || defaultIndex > breakpoints.length) { // Not: breakpoints.length - 1
// ...
} |
issue: #1191
useBreakpointIndex was returning the number of breakpoints matched, while the default value (defaultIndex) and the name of the hook were implying that the returned values is an index into the array of breakpoints.
The tests were also not correct (adjusted to the wrong implementation) and had to be changed - unfortunately now this can break existing code that would have been relying on the previous code. Usually in only happens if you provided more values than breakpoints are available
For example this used to work
Now an exception will be generated if more values are used than the number of available breakpoints