أكورديون 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.
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.
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.
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.
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.
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
انسخ الشيفرة
خذ أيًا من النسختين. نسخة React مكوّن دالة عادي دون حالة ودون توجيه use client، فتعمل كمكوّن خادم في Next.js App Router.
- 2
استبدل الصفوف
عدّل مصفوفة items، أو كرّر كتلة details في نسخة HTML. تقبل اللوحات أي شيفرة لا فقرة فقط.
- 3
قرر ما يبدأ مفتوحًا
أضف سمة open إلى الصف الذي ينبغي أن يكون موسّعًا عند التحميل. فتح الأول يوضح أن الصفوف تفاعلية.
- 4
اختر حصريًا أم لا
امنح كل details سمة name نفسها إن كان فتح أحدها ينبغي أن يغلق الباقي. واترك السمة إن كان القرّاء قد يريدون مقارنة الصفوف.
- 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
- عنصر summary قابل للتركيز ويُفعَّل بـ Enter والمسافة افتراضيًا، دون حاجة إلى tabindex أو معالج مفاتيح.
- تُكشف حالتا التوسيع والطي للتقنيات المساعدة بالعنصر نفسه، فلا aria-expanded للمحافظة عليه.
- السهم موسوم بـ aria-hidden لأنه يكرر حالة معلنة أصلًا؛ ودون ذلك يسمع مستخدمو قارئات الشاشة رسمًا بلا معنى في كل صف.
- يبقى المحتوى المطوي في المستند وقابلًا للعثور عليه ببحث المتصفح، وهي الطريقة التي يجد بها كثيرون المحتوى في صفحة أسئلة شائعة طويلة.
- إن كان ينبغي لعنوان صف أن يكون أيضًا عنوان مستند فضع عنصر عنوان داخل summary لا حول details - فالتعشيش العكسي غير صالح.
- كثيرًا ما تُزال حلقة التركيز الافتراضية على summary عن غير قصد أثناء التنسيق. أبقِ نمط focus-visible مرئيًا وإلا فقد مستخدمو لوحة المفاتيح تتبع الصف الذي هم فيه.
Customization
- أزل المثلث الافتراضي بـ marker:content-none، وأضف متغير webkit details-marker إن كنت تدعم إصدارات Safari الأقدم.
- استبدل الفواصل ببطاقات ذات حدود بتغليف كل details في حاويته المستديرة الخاصة بحدودها.
- غيّر السهم إلى علامتي زائد وناقص بعرض الأيقونتين وتبديل ظهورهما بـ group-open، وهو أوضح من بعيد.
- لا يزال تحريك ارتفاع اللوحة مرهقًا لأن details يتبدل فورًا. نهج interpolate-size وcalc-size يعمل في Chrome الحالي؛ فعامل الحركة كتحسين لا كمتطلب.
- أضف خلفية خفيفة على الصف المفتوح بـ group-open على الحاوية، وهذا يفيد حين تكون عدة صفوف مفتوحة في آن واحد.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items * | { question: string; answer: string }[] | - | صفوف الأكورديون. اجعلها اثني عشر أو أقل؛ وما زاد على ذلك يخدم القرّاء فيه أكثر قائمة قابلة للبحث أو مجموعة صفحات منفصلة. |
| defaultOpenIndex | number | 0 | الصف الذي يبدأ موسّعًا. فتح الأول يشير إلى أن الصفوف تفاعلية؛ وترك كل شيء مغلقًا قد يُقرأ كقائمة ثابتة من العناوين. |
Why Use These أكورديونs?
إنه النسخة الأقل عرضة للخلل. لا حالة ولا اعتماد ولا تهيئة ولا ARIA لإبقائه متزامنًا، وسلوك يعمل قبل تحميل JavaScript وبعد فشله.
يبقى قابلًا للعثور عليه. المحتوى داخل details مطوي يمكن أن يظهره بحث المتصفح داخل الصفحة، وهي الطريقة التي يتنقل بها كثير من القرّاء في صفحة أسئلة شائعة طويلة - أما أكورديون مبني من divs فيخفي ذلك المحتوى عن البحث بصمت.
لا تحتاج نسخة React إلى توجيه use client، فتُعرض على الخادم. معظم مكوّنات الأكورديون المتداولة مكوّنات عميل لا لشيء إلا لأنها تتتبع حالة فتح كان المتصفح يتتبعها أصلًا.
Tips
- افتح الصف الأول افتراضيًا. فعمود من العناوين المغلقة قد يُقرأ كقائمة ثابتة، ولن يجرّب القرّاء النقر على أحدها دائمًا.
- اجعل اللوحات قصيرة. فإن امتدت إجابة إلى ما بعد بضع فقرات فاربطها بصفحة كاملة - فاللوحات الطويلة تدفع الصفوف التالية بعيدًا وتجعل القائمة صعبة التصفح.
- للسلوك الحصري استخدم سمة name المشتركة لا JavaScript. إنها سمة واحدة ويتولى المتصفح الباقي.
- اكتب summary كالسؤال الذي كان القارئ سيكتبه فعلًا. فصفوف الأسئلة الشائعة كثيرًا ما تكون الجزء الذي يظهر في نتائج البحث، والصياغة هي ما يقرر ذلك.
- لا تغلّف details بعنصر عنوان. وإن أردت أن يكون السؤال عنوان مستند فضع العنوان داخل summary بدلًا من ذلك.
- راقب حلقة التركيز. من السهل إزالتها أثناء تنسيق summary، ودونها لا يستطيع مستخدمو لوحة المفاتيح معرفة أي صف هم فيه.