From ebb35a08333865800e8033ce7701b955e0b21dd4 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Fri, 23 Oct 2020 19:40:07 +0530 Subject: [PATCH] Accordion - focus on note container instead instead of summary tag --- components/Accordion.jsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/Accordion.jsx b/components/Accordion.jsx index 860c449..493818f 100644 --- a/components/Accordion.jsx +++ b/components/Accordion.jsx @@ -2,7 +2,6 @@ import React, { useRef, useEffect } from "react"; const Accordion = ({ children, title = "More" }) => { const detailsRef = useRef(null); - const summaryRef = useRef(null); function openAccordionOnHash() { const hash = location.hash.substring(1); @@ -17,18 +16,16 @@ const Accordion = ({ children, title = "More" }) => { // 1. If target is within current details element const detailsElement = detailsRef.current; - const summaryElement = summaryRef.current; if ( detailsElement !== null && - summaryElement.current !== null && detailsElement.contains(targetElement) ) { // 2. and it is not open, if (!detailsElement.open) { // 3. Then open it detailsElement.open = true; - // 4. and scroll into view, focus on summary - summaryElement.focus(); + // 4. and scroll into view and focus + targetElement.focus(); targetElement.scrollIntoView({ behavior: "smooth", block: "center" }); } } @@ -48,7 +45,7 @@ const Accordion = ({ children, title = "More" }) => { return (
- {title} + {title} {children}
);