Skip to content

Commit

Permalink
fix(media-query): change logic of judging if break point values has s…
Browse files Browse the repository at this point in the history
…pecific break point key (#6308)
  • Loading branch information
n-harada committed Jul 13, 2022
1 parent fb3c093 commit 4beff94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/moody-planets-float.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/media-query": minor
---

fix getClosestValue to return nullable closest break point value
2 changes: 1 addition & 1 deletion packages/media-query/src/media-query.utils.ts
Expand Up @@ -16,7 +16,7 @@ export function getClosestValue<T = any>(
while (stopIndex >= 0) {
const key = breakpoints[stopIndex]

if (values[key] != null) {
if (values.hasOwnProperty(key)) {
index = stopIndex
break
}
Expand Down
6 changes: 6 additions & 0 deletions packages/media-query/tests/utils.test.ts
Expand Up @@ -8,6 +8,12 @@ test("should get the closest responsive value", () => {
expect(getClosestValue({ sm: "40px", md: "500px" }, "base")).toBe(undefined)
expect(getClosestValue({}, "")).toBe(undefined)
})
test("should get the closest responsive value even if values contains nullable value", () => {
expect(getClosestValue({ base: "40px", md: undefined }, "xl")).toBe(undefined)
expect(getClosestValue({ base: "40px", md: null }, "xl")).toBe(null)
expect(getClosestValue({ sm: "40px", md: undefined }, "xl")).toBe(undefined)
expect(getClosestValue({ sm: "40px", md: null }, "xl")).toBe(null)
})
test("should get the closest responsive value with custom breakpoints", () => {
const customBreakPoints = ["base", "sm", "md", "custom", "xl"]
expect(
Expand Down

1 comment on commit 4beff94

@vercel
Copy link

@vercel vercel bot commented on 4beff94 Jul 13, 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.