From 514f9b6379d01b87afde24b2b64ec026d6098e3d Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Sun, 1 Dec 2024 16:44:36 +0800 Subject: [PATCH 1/5] fix: accordion item focus effect input focus event --- packages/components/accordion/src/accordion-item.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/components/accordion/src/accordion-item.tsx b/packages/components/accordion/src/accordion-item.tsx index fcdea9b5e3..61b8c63ba5 100644 --- a/packages/components/accordion/src/accordion-item.tsx +++ b/packages/components/accordion/src/accordion-item.tsx @@ -90,6 +90,12 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => { initial="exit" style={{willChange}} variants={transitionVariants} + onClick={(e) => { + e.stopPropagation(); + }} + onFocus={(e) => { + e.stopPropagation(); + }} onKeyDown={(e) => { e.stopPropagation(); }} From fd0f585c3e905358a9dabab2e6f37ab465bdb452 Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Tue, 3 Dec 2024 13:56:28 +0800 Subject: [PATCH 2/5] test: input focus error in default expanded accordion item --- .../accordion/__tests__/accordion.test.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/components/accordion/__tests__/accordion.test.tsx b/packages/components/accordion/__tests__/accordion.test.tsx index 8a4d78df7e..a798a273c5 100644 --- a/packages/components/accordion/__tests__/accordion.test.tsx +++ b/packages/components/accordion/__tests__/accordion.test.tsx @@ -345,4 +345,24 @@ describe("Accordion", () => { expect(getByRole("separator")).toHaveClass("bg-rose-500"); }); + + it("should focus input inside default expanded accordion item correctly", async () => { + const wrapper = render( + + + + + , + ); + + await new Promise((resolve) => setTimeout(resolve, 100)); + + const input = wrapper.container.querySelector("input"); + + expect(input).not.toBeNull(); + + await user.click(input!); + + expect(input).toHaveFocus(); + }); }); From 40eaad168affce3b2fe1c4c481960872cc427109 Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Tue, 3 Dec 2024 14:15:35 +0800 Subject: [PATCH 3/5] chore: fix focus error changeset --- .changeset/short-bulldogs-divide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/short-bulldogs-divide.md diff --git a/.changeset/short-bulldogs-divide.md b/.changeset/short-bulldogs-divide.md new file mode 100644 index 0000000000..4e970f6671 --- /dev/null +++ b/.changeset/short-bulldogs-divide.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/accordion": patch +--- + +Fix input focus error in default expanded accordion item, add `onClick`, `onFocus` to `AccordionItem` content wrapper From 0e10eb99af52a340946fe1cc6d61a9a5ef9221ce Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Wed, 4 Dec 2024 14:46:10 +0800 Subject: [PATCH 4/5] test: accordion test --- packages/components/accordion/__tests__/accordion.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/components/accordion/__tests__/accordion.test.tsx b/packages/components/accordion/__tests__/accordion.test.tsx index a798a273c5..dfd2f824c7 100644 --- a/packages/components/accordion/__tests__/accordion.test.tsx +++ b/packages/components/accordion/__tests__/accordion.test.tsx @@ -348,15 +348,13 @@ describe("Accordion", () => { it("should focus input inside default expanded accordion item correctly", async () => { const wrapper = render( - + , ); - await new Promise((resolve) => setTimeout(resolve, 100)); - const input = wrapper.container.querySelector("input"); expect(input).not.toBeNull(); From 10f3e6a0e6fc01836bbef795fad2c45a5c406f68 Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Wed, 4 Dec 2024 14:46:59 +0800 Subject: [PATCH 5/5] fix: completed accordion item content event --- packages/components/accordion/src/accordion-item.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/components/accordion/src/accordion-item.tsx b/packages/components/accordion/src/accordion-item.tsx index 61b8c63ba5..be47c967d8 100644 --- a/packages/components/accordion/src/accordion-item.tsx +++ b/packages/components/accordion/src/accordion-item.tsx @@ -71,6 +71,12 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => { initial="exit" style={{willChange}} variants={transitionVariants} + onClick={(e) => { + e.stopPropagation(); + }} + onFocus={(e) => { + e.stopPropagation(); + }} onKeyDown={(e) => { e.stopPropagation(); }}