-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fix useAriaHidden deps * docs: add changeset * test: add tests for useAriaHidden Co-authored-by: Segun Adebayo <joseshegs@gmail.com>
- Loading branch information
1 parent
99c92df
commit 5aa79f8
Showing
3 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@chakra-ui/modal": patch | ||
--- | ||
|
||
Fix `useAriaHidden` hook dependency to make it work as expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { renderHook } from "@testing-library/react-hooks" | ||
import { hideOthers } from "aria-hidden" | ||
import { MutableRefObject } from "react" | ||
import { useAriaHidden } from "../src" | ||
|
||
jest.mock("aria-hidden") | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe("useAriaHidden", () => { | ||
it("should be triggered if ref.current is changed", () => { | ||
const ref: MutableRefObject<null | HTMLElement> = { current: null } | ||
|
||
renderHook(() => useAriaHidden(ref, true)) | ||
expect(hideOthers).not.toBeCalled() | ||
|
||
ref.current = document.createElement("div") | ||
|
||
renderHook(() => useAriaHidden(ref, true)) | ||
expect(hideOthers).toBeCalledWith(ref.current) | ||
}) | ||
|
||
it("shouldn't be triggered if `shouldHide` is `false`", () => { | ||
const ref: MutableRefObject<null | HTMLElement> = { current: null } | ||
|
||
renderHook(() => useAriaHidden(ref, true)) | ||
expect(hideOthers).not.toBeCalled() | ||
|
||
ref.current = document.createElement("div") | ||
|
||
renderHook(() => useAriaHidden(ref, false)) | ||
expect(hideOthers).not.toBeCalled() | ||
}) | ||
}) |