تمت إضافة أدوات جديدة! اكتشف الجديد

الرئيسية/المكونات/أكورديون

أكورديون examples

قائمة قابلة للطي مبنية من عنصري details وsummary الأصليين، دون الحاجة إلى JavaScript.

قائمة قابلة للطي مبنية من عنصري details وsummary الأصليين. التوسيع والطي ودعم لوحة المفاتيح والدلالات الصحيحة كلها تأتي من المتصفح، فيُشحن المكوّن دون أي JavaScript.

يدور السهم باستخدام متغير group-open، أي أن حالة الفتح تُنسَّق في CSS ولا تُتتبَّع في حالة.

Accordion with dividers

The default FAQ layout: rows separated by hairlines, with a chevron that rotates when a row opens. No JavaScript.

Preview
export default function Accordion() {
  return (
    <div className="mx-auto max-w-2xl divide-y divide-gray-200">
      <details className="group py-4" open>
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do I need to install anything?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">No. Every component is plain markup you copy into your project.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Can I use these commercially?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Yes. No attribution is required and there is no license fee.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do the components work without JavaScript?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Most do. Anything that needs state, like a menu or a dialog, uses a few lines of script.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Which frameworks are supported?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Every component comes as plain HTML and as a React component, both styled with Tailwind CSS.</p>
      </details>
    </div>
  );
}

Single-open accordion

Every details element shares one name attribute, so opening a row closes the others. The browser handles it, with no script.

Preview
export default function ExclusiveAccordion() {
  return (
    <div className="mx-auto max-w-2xl divide-y divide-gray-200">
      <details className="group py-4" name="faq" open>
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do I need to install anything?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">No. Every component is plain markup you copy into your project.</p>
      </details>

      <details className="group py-4" name="faq">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Can I use these commercially?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Yes. No attribution is required and there is no license fee.</p>
      </details>

      <details className="group py-4" name="faq">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do the components work without JavaScript?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Most do. Anything that needs state, like a menu or a dialog, uses a few lines of script.</p>
      </details>

      <details className="group py-4" name="faq">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Which frameworks are supported?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Every component comes as plain HTML and as a React component, both styled with Tailwind CSS.</p>
      </details>
    </div>
  );
}

Accordion with bordered cards

Each row is its own rounded card that tints when open. Reads better when the questions are unrelated rather than one continuous list.

Preview
export default function CardAccordion() {
  return (
    <div className="mx-auto max-w-2xl space-y-3">
      <details className="group rounded-lg border border-gray-200 px-4 py-3 open:bg-gray-50" open>
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do I need to install anything?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">No. Every component is plain markup you copy into your project.</p>
      </details>

      <details className="group rounded-lg border border-gray-200 px-4 py-3 open:bg-gray-50">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Can I use these commercially?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Yes. No attribution is required and there is no license fee.</p>
      </details>

      <details className="group rounded-lg border border-gray-200 px-4 py-3 open:bg-gray-50">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do the components work without JavaScript?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Most do. Anything that needs state, like a menu or a dialog, uses a few lines of script.</p>
      </details>

      <details className="group rounded-lg border border-gray-200 px-4 py-3 open:bg-gray-50">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Which frameworks are supported?
          <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Every component comes as plain HTML and as a React component, both styled with Tailwind CSS.</p>
      </details>
    </div>
  );
}

Accordion with plus and minus icons

A plus that becomes a minus using group-open. Clearer than a chevron when the open state needs to be obvious from a distance.

Preview
export default function PlusMinusAccordion() {
  return (
    <div className="mx-auto max-w-2xl divide-y divide-gray-200">
      <details className="group py-4" open>
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do I need to install anything?
          <svg className="h-5 w-5 shrink-0 text-gray-400 group-open:hidden" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>
          <svg className="hidden h-5 w-5 shrink-0 text-gray-400 group-open:block" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M19.5 12h-15" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">No. Every component is plain markup you copy into your project.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Can I use these commercially?
          <svg className="h-5 w-5 shrink-0 text-gray-400 group-open:hidden" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>
          <svg className="hidden h-5 w-5 shrink-0 text-gray-400 group-open:block" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M19.5 12h-15" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Yes. No attribution is required and there is no license fee.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Do the components work without JavaScript?
          <svg className="h-5 w-5 shrink-0 text-gray-400 group-open:hidden" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>
          <svg className="hidden h-5 w-5 shrink-0 text-gray-400 group-open:block" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M19.5 12h-15" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Most do. Anything that needs state, like a menu or a dialog, uses a few lines of script.</p>
      </details>

      <details className="group py-4">
        <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
          Which frameworks are supported?
          <svg className="h-5 w-5 shrink-0 text-gray-400 group-open:hidden" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>
          <svg className="hidden h-5 w-5 shrink-0 text-gray-400 group-open:block" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M19.5 12h-15" /></svg>
        </summary>
        <p className="mt-3 text-sm text-gray-600">Every component comes as plain HTML and as a React component, both styled with Tailwind CSS.</p>
      </details>
    </div>
  );
}

FAQ section with heading beside the accordion

A heading and support line on the left and the accordion on the right at lg, stacked on smaller screens. Suits a full FAQ section on a landing page.

Preview
export default function FaqSection() {
  return (
    <section className="mx-auto grid max-w-5xl gap-10 px-4 py-12 lg:grid-cols-3">
      <div className="bg-gray-900 p-4 rounded-lg">
        <h2 className="text-2xl font-bold text-gray-100">Frequently asked questions</h2>
        <p className="mt-3 text-sm text-white">Cannot find an answer? Email us and we will reply within a day.</p>
      </div>

      <div className="divide-y divide-gray-200 lg:col-span-2">
        <details className="group py-4" open>
          <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
            Do I need to install anything?
            <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
          </summary>
          <p className="mt-3 text-sm text-gray-600">No. Every component is plain markup you copy into your project.</p>
        </details>

        <details className="group py-4">
          <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
            Can I use these commercially?
            <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
          </summary>
          <p className="mt-3 text-sm text-gray-600">Yes. No attribution is required and there is no license fee.</p>
        </details>

        <details className="group py-4">
          <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
            Do the components work without JavaScript?
            <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
          </summary>
          <p className="mt-3 text-sm text-gray-600">Most do. Anything that needs state, like a menu or a dialog, uses a few lines of script.</p>
        </details>

        <details className="group py-4">
          <summary className="flex cursor-pointer list-none items-center justify-between gap-4 rounded-sm font-medium text-gray-900 outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
            Which frameworks are supported?
            <svg className="h-5 w-5 shrink-0 text-gray-400 transition group-open:rotate-180" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
          </summary>
          <p className="mt-3 text-sm text-gray-600">Every component comes as plain HTML and as a React component, both styled with Tailwind CSS.</p>
        </details>
      </div>
    </section>
  );
}

What is a أكورديون?

الأكورديون قائمة رأسية لكل صف فيها عنوان يمكنك النقر عليه لكشف محتواه. إنه أداة كثافة: يتيح للصفحة عرض عشرين عنوانًا في مساحة ثلاث فقرات، ويتيح للقرّاء فتح ما ينطبق عليهم فقط. أقسام الأسئلة الشائعة هي الاستخدام الأكثر شيوعًا، لكن النمط نفسه يخدم لوحات الإعدادات ومجموعات المرشحات وأي قائمة يريد معظم القرّاء معظمها مطويًا.

يُعاد بناء هذا النمط في JavaScript باستمرار، وهو غير ضروري في الغالب. ففي HTML عنصرا details وsummary يفعلان ذلك تمامًا: summary هو العنوان القابل للنقر، وكل ما عداه داخل details هو اللوحة، ويتولى المتصفح التبديل والتفعيل بلوحة المفاتيح وحالة التوسيع في شجرة إمكانية الوصول وقدرة بحث المتصفح داخل الصفحة على فتح قسم مطوي لإظهار تطابق. وأكورديون JavaScript عليه إعادة تنفيذ كل ذلك، وعادةً ما يعيد تنفيذ معظمه على نحو خاطئ.

الشيء الوحيد الذي لا يفعله details افتراضيًا هو إغلاق أشقائه حين يُفتح أحدها. هذا السلوك - الذي يُسمّى غالبًا الأكورديون الحصري - متاح الآن بمنح كل عنصر details سمة name نفسها، فتعاملها المتصفحات كمجموعة. وسواء أردته أم لا فهو سؤال تصميم حقيقي لا تقني: فالأكورديون الحصري يُبقي الصفحة قصيرة لكنه يجعل مقارنة صفين مستحيلة دون إعادة فتح أحدهما.

كان تنسيق details مرهقًا بسبب مثلث الإفصاح الافتراضي، وهو علامة قائمة على summary. وإزالته تتطلب marker:content-none في Tailwind، إضافة إلى المتغير الخاص بـ webkit في Safari الأقدم. وبمجرد إزالته يصبح summary حاوية flex عادية ويمكن وضع السهم المخصص حيث ينبغي.

Anatomy

الحاوية
الغلاف الذي يحمل الصفوف، ويحمل الفواصل والعرض الأقصى. قيّد العرض للقراءة - فإجابات الأسئلة الشائعة بالعرض الكامل صعبة التصفح.
Details
واحد لكل صف. فئة group هنا هي ما يتيح للسهم الاستجابة لحالة الفتح عبر متغير group-open.
Summary
العنوان القابل للنقر. قابل للتركيز والتفعيل بلوحة المفاتيح أصلًا، فلا يحتاج إلى role ولا tabindex ولا معالج مفاتيح.
المؤشر
السهم، يُدار بـ group-open. موسوم بـ aria-hidden لأن حالة التوسيع يعلنها العنصر نفسه أصلًا.
اللوحة
كل ما داخل details بعد summary. أي شيفرة تعمل هنا - فقرات أو قوائم أو نماذج أو مكوّنات أخرى.

How to Use

  1. 1

    انسخ الشيفرة

    خذ أيًا من النسختين. نسخة React مكوّن دالة عادي دون حالة ودون توجيه use client، فتعمل كمكوّن خادم في Next.js App Router.

  2. 2

    استبدل الصفوف

    عدّل مصفوفة items، أو كرّر كتلة details في نسخة HTML. تقبل اللوحات أي شيفرة لا فقرة فقط.

  3. 3

    قرر ما يبدأ مفتوحًا

    أضف سمة open إلى الصف الذي ينبغي أن يكون موسّعًا عند التحميل. فتح الأول يوضح أن الصفوف تفاعلية.

  4. 4

    اختر حصريًا أم لا

    امنح كل details سمة name نفسها إن كان فتح أحدها ينبغي أن يغلق الباقي. واترك السمة إن كان القرّاء قد يريدون مقارنة الصفوف.

  5. 5

    نسّق summary

    أزل العلامة الافتراضية بـ marker:content-none، ثم عامل summary كحاوية flex عادية للتسمية والمؤشر.

Features

بلا JavaScript

يتولى المتصفح التبديل والتفعيل بلوحة المفاتيح والحالة، فيعمل المكوّن قبل التهيئة ويستمر في العمل إن تعذّر تحميل السكربتات.

دلالات صحيحة افتراضيًا

تُكشف حالة التوسيع للتقنيات المساعدة تلقائيًا، دون aria-expanded لضبطه أو إبقائه متزامنًا.

قابل للعثور عليه وهو مطوي

يستطيع بحث المتصفح داخل الصفحة فتح لوحة مطوية لإظهار تطابق، وهو ما لا يستطيعه أكورديون JavaScript مبني من divs.

مؤشر يديره CSS

يأتي دوران السهم من متغير group-open، فتتحكم حالة الفتح في التنسيق مباشرة لا عبر متغير حالة.

وضع حصري دون شيفرة

سمة name مشتركة تجعل المجموعة تتصرف كأكورديون يفتح صفًا واحدًا في كل مرة، ويتولاها المتصفح كليًا.

ملائم لمكوّنات الخادم

دون حالة ودون تأثيرات جانبية، تُعرض نسخة React على الخادم في Next.js App Router دون توجيه use client.

Common Uses

أقسام الأسئلة الشائعة

الاستخدام الأكثر شيوعًا. عشرون سؤالًا تتسع في عناوين بمساحة شاشة واحدة، ويفتح القرّاء السؤالين اللذين ينطبقان عليهم فقط.

مجموعات المرشحات

مجموعات فئات وأسعار وسمات قابلة للطي في شريط جانبي لمنتجات، لتبقى مجموعة مرشحات طويلة قابلة للتصفح على شاشة قصيرة.

لوحات الإعدادات

تجميع الخيارات المتقدمة خلف صف مطوي يُبقي صفحة الإعدادات ودودة دون إخفاء الخيارات كليًا.

تفاصيل التوثيق

إخفاء جداول API الكاملة أو رسائل الأخطاء الطويلة أو خطوات الإعداد الاختيارية خلف عنصر إفصاح ليبقى التدفق الرئيسي مقروءًا.

Accessibility

Customization

Props

PropTypeDefaultDescription
items *{ question: string; answer: string }[]-صفوف الأكورديون. اجعلها اثني عشر أو أقل؛ وما زاد على ذلك يخدم القرّاء فيه أكثر قائمة قابلة للبحث أو مجموعة صفحات منفصلة.
defaultOpenIndexnumber0الصف الذي يبدأ موسّعًا. فتح الأول يشير إلى أن الصفوف تفاعلية؛ وترك كل شيء مغلقًا قد يُقرأ كقائمة ثابتة من العناوين.

Why Use These أكورديونs?

إنه النسخة الأقل عرضة للخلل. لا حالة ولا اعتماد ولا تهيئة ولا ARIA لإبقائه متزامنًا، وسلوك يعمل قبل تحميل JavaScript وبعد فشله.

يبقى قابلًا للعثور عليه. المحتوى داخل details مطوي يمكن أن يظهره بحث المتصفح داخل الصفحة، وهي الطريقة التي يتنقل بها كثير من القرّاء في صفحة أسئلة شائعة طويلة - أما أكورديون مبني من divs فيخفي ذلك المحتوى عن البحث بصمت.

لا تحتاج نسخة React إلى توجيه use client، فتُعرض على الخادم. معظم مكوّنات الأكورديون المتداولة مكوّنات عميل لا لشيء إلا لأنها تتتبع حالة فتح كان المتصفح يتتبعها أصلًا.

Tips

Frequently Asked Questions

Related Components