Skip to content

Commit 55e5769

Browse files
committed
🐛 Fix the toggle calendar utility to properly close the datepicker
- Update click outside detection to use closest method for class matching. - Modified the click outside detection logic to utilize the `closest` method for checking ignored elements, ensuring compatibility with Element targets. - Updated the corresponding test case for clarity. Closes #6252
1 parent 548a1f3 commit 55e5769

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/click_outside_wrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const useDetectClickOutside = (
3333
if (
3434
!(
3535
ignoreClass &&
36-
target instanceof HTMLElement &&
37-
target.classList.contains(ignoreClass)
36+
target instanceof Element &&
37+
target.closest(`.${ignoreClass}`)
3838
)
3939
) {
4040
onClickOutsideRef.current?.(event);

src/test/click_outside_wrapper.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ describe("ClickOutsideWrapper", () => {
252252
addEventListenerSpy.mockRestore();
253253
});
254254

255-
it("does not treat non-HTMLElement targets as ignored elements", () => {
255+
it("does not treat non-Element targets as ignored elements", () => {
256256
const addEventListenerSpy = jest.spyOn(document, "addEventListener");
257257
render(
258258
<ClickOutsideWrapper

0 commit comments

Comments
 (0)