Skip to content

Commit

Permalink
fix(utils): breakpoint calculation (#6301)
Browse files Browse the repository at this point in the history
* fix: breakpoint calculation

* docs: changeset
  • Loading branch information
effectivetom committed Jul 11, 2022
1 parent a57b659 commit c11743b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/selfish-bees-kneel.md
@@ -0,0 +1,7 @@
---
"@chakra-ui/styled-system": patch
"@chakra-ui/utils": patch
---

Fix incorrect breakpoint calculation which excluded some viewport widths from
media query coverage
10 changes: 5 additions & 5 deletions packages/styled-system/tests/style-config.test.ts
Expand Up @@ -4,7 +4,7 @@ test("should handle single variant", () => {
expect(recipe({ theme, variant: "solid", size: ["sm", "md"] }))
.toMatchInlineSnapshot(`
Object {
"@media screen and (min-width: 0px) and (max-width: 39.9365em)": Object {
"@media screen and (min-width: 0px) and (max-width: 39.9375em)": Object {
"fontSize": "sm",
"h": 8,
"minW": 8,
Expand All @@ -27,7 +27,7 @@ test("should handle single variant", () => {
expect(recipe({ theme, variant: "solid", size: { base: "sm", sm: "md" } }))
.toMatchInlineSnapshot(`
Object {
"@media screen and (min-width: 0px) and (max-width: 39.9365em)": Object {
"@media screen and (min-width: 0px) and (max-width: 39.9375em)": Object {
"fontSize": "sm",
"h": 8,
"minW": 8,
Expand All @@ -50,7 +50,7 @@ test("should handle single variant", () => {
expect(recipe({ theme, variant: "solid", size: { base: "sm", lg: "md" } }))
.toMatchInlineSnapshot(`
Object {
"@media screen and (min-width: 0px) and (max-width: 63.9365em)": Object {
"@media screen and (min-width: 0px) and (max-width: 63.9375em)": Object {
"fontSize": "sm",
"h": 8,
"minW": 8,
Expand Down Expand Up @@ -80,7 +80,7 @@ test("should work with distant breakpoint", () => {
}),
).toMatchInlineSnapshot(`
Object {
"@media screen and (min-width: 0px) and (max-width: 63.9365em)": Object {
"@media screen and (min-width: 0px) and (max-width: 63.9375em)": Object {
"fontSize": "sm",
"h": 8,
"minW": 8,
Expand Down Expand Up @@ -108,7 +108,7 @@ test("should work with distant breakpoint", () => {
}),
).toMatchInlineSnapshot(`
Object {
"@media screen and (min-width: 0px) and (max-width: 63.9365em)": Object {
"@media screen and (min-width: 0px) and (max-width: 63.9375em)": Object {
"fontSize": "sm",
"h": 8,
"minW": 8,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/breakpoint.ts
Expand Up @@ -37,7 +37,7 @@ function subtract(value: string) {
const factor = value.endsWith("px")
? -1
: // the equivalent of 1px in em using a 16px base
-0.0635
-0.0625
return isNumber(value)
? `${value + factor}`
: value.replace(/(\d+\.?\d*)/u, (m) => `${parseFloat(m) + factor}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/tests/responsive.test.ts
Expand Up @@ -142,7 +142,7 @@ test("should work with createBreakpoint output", () => {
).toMatchInlineSnapshot(`
Array [
Object {
"_minW": "-0.0635em",
"_minW": "-0.0625em",
"breakpoint": "base",
"maxW": "319px",
"maxWQuery": "@media screen and (max-width: 319px)",
Expand Down

1 comment on commit c11743b

@vercel
Copy link

@vercel vercel bot commented on c11743b Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.