-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
core: add 0 case to responsive props #101440
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,29 +43,43 @@ export function rc<T>( | |
| if (first) { | ||
| first = false; | ||
| return css` | ||
| @media (min-width: ${theme.breakpoints[breakpoint]}), | ||
| (max-width: ${theme.breakpoints[breakpoint]}) { | ||
| @media (min-width: ${getBreakpoint(breakpoint, theme)}), | ||
| (max-width: ${getBreakpoint(breakpoint, theme)}) { | ||
| ${property}: ${resolver ? resolver(v, breakpoint, theme) : (v as string)}; | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| return css` | ||
| @media (min-width: ${theme.breakpoints[breakpoint]}) { | ||
| @media (min-width: ${getBreakpoint(breakpoint, theme)}) { | ||
| ${property}: ${resolver ? resolver(v, breakpoint, theme) : (v as string)}; | ||
| } | ||
| `; | ||
| }).filter(Boolean)} | ||
| `; | ||
| } | ||
|
|
||
| const BREAKPOINT_ORDER: readonly Breakpoint[] = ['xs', 'sm', 'md', 'lg', 'xl']; | ||
| function getBreakpoint(breakpoint: Breakpoint, theme: Theme) { | ||
| if (breakpoint === '0') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: not sure if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you expect the behavior of In the current case with a 0, it means But a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Valid point. After a second thought, when I first used it I actually thought
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the biggest confusion might come from the fact that we’re trying to express ranges with a single value. Usually, But on responsive props, I also couldn’t find good documentation on this topic; there is a bit on That said, I also find
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, this has been a tradeoff in allowing the min breakpoints to be specified as opposed to having to specify all. Regardless, we would have always probably had this issue in one way or another where we would need to capture > max or < min.
An alternative could also be to define a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return '0px'; | ||
| } | ||
| return theme.breakpoints[breakpoint]; | ||
| } | ||
|
|
||
| const BREAKPOINT_ORDER: ReadonlyArray<Breakpoint | '0'> = [ | ||
| '0', | ||
| 'xs', | ||
| 'sm', | ||
| 'md', | ||
| 'lg', | ||
| 'xl', | ||
| ]; | ||
|
|
||
| // We alias None -> 0 to make it slighly more terse and easier to read. | ||
| export type RadiusSize = keyof DO_NOT_USE_ChonkTheme['radius']; | ||
| export type SpacingSize = keyof Theme['space']; | ||
| export type Border = keyof Theme['tokens']['border']; | ||
| export type Breakpoint = keyof Theme['breakpoints']; | ||
| export type Breakpoint = keyof Theme['breakpoints'] | '0'; | ||
|
|
||
| /** | ||
| * Prefer using padding or gap instead. | ||
|
|
@@ -257,12 +271,12 @@ export function useActiveBreakpoint(): Breakpoint { | |
|
|
||
| queries.push({ | ||
| breakpoint: bp, | ||
| query: window.matchMedia(`(min-width: ${theme.breakpoints[bp]})`), | ||
| query: window.matchMedia(`(min-width: ${getBreakpoint(bp, theme)})`), | ||
| }); | ||
| } | ||
|
|
||
| return queries; | ||
| }, [theme.breakpoints]); | ||
| }, [theme]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Breakpoint Zero Bug and useMemo Dependency IssueThe '0' breakpoint now generates a |
||
|
|
||
| const subscribe = useCallback( | ||
| (onStoreChange: () => void) => { | ||
JonasBa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -303,7 +317,7 @@ function findLargestBreakpoint( | |
| return query.breakpoint; | ||
| } | ||
|
|
||
| // Since we use min width, the only remaining breakpoint that we might have missed is <xs, | ||
| // in which case we return xs, which is in line with behavior of rc() function. | ||
| return 'xs'; | ||
| // Since we use min width, the only remaining breakpoint that we might have missed is <0, | ||
| // in which case we return 0, which is in line with behavior of rc() function. | ||
| return '0'; | ||
| } | ||
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.
Bug: Zero Breakpoint Generates Invalid Media Query
When '0' is the first breakpoint in a responsive value, the generated media query includes
(max-width: 0). This incorrectly limits the styles to only apply at exactly 0px width, preventing the '0' breakpoint from covering the intended range of small screen sizes.