آکورڈین examples
نیٹیو details اور summary عناصر سے بنا ایک ایسا گرنے اور پھیلنے والا لسٹ کمپوننٹ، جس کے لیے کسی JavaScript کی ضرورت نہیں ہوتی۔
نیٹیو details اور summary عناصر سے بنی ایک طویلہ لسٹ۔ پھیلنا اور سمٹنا، کی بورڈ سپورٹ، اور درست سیمنٹکس سب براؤزر کی طرف سے فراہم کیے جاتے ہیں، اس لیے یہ کمپوننٹ بالکل بھی JavaScript کے بغیر کام کرتا ہے۔
شیور (chevron) 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 آکورڈین?
آکورڈین ایک عمودی فہرست ہے جہاں ہر قطار میں ایک سرخی ہوتی ہے جسے آپ اس کا مواد ظاہر کرنے کے لیے کلک کر سکتے ہیں۔ یہ ڈینسٹی کا ایک ٹول ہے: یہ ایک صفحے کو تین پیراگراف کی جگہ میں بیس سرخیاں دکھانے کی اجازت دیتا ہے، اور قارئین کو صرف وہی کھولنے کی اجازت دیتا ہے جو ان سے متعلق ہوں۔ FAQ سیکشنز سب سے عام استعمال ہیں، لیکن یہی پیٹرن سیٹنگز پینلز، فلٹر گروپس، اور کسی بھی ایسی فہرست کے لیے کام کرتا ہے جہاں زیادہ تر قارئین زیادہ تر مواد کو سمٹا ہوا دیکھنا چاہتے ہیں۔
اس پیٹرن کو JavaScript میں مسلسل دوبارہ بنایا جاتا ہے، جو کہ تقریباً ہمیشہ غیر ضروری ہوتا ہے۔ HTML میں details اور summary عناصر موجود ہیں جو بالکل یہی کام کرتے ہیں: summary کلک کرنے کے قابل سرخی ہے، details کے اندر موجود ہر دوسری چیز پینل ہے، اور براؤزر ٹوگل کرنے، کی بورڈ سے ایکٹیویشن، ایکسیسبیلٹی ٹ্রি میں پھیلی ہوئی حالت، اور براؤزر کے find-in-page کو کسی سمٹے ہوئے سیکشن کو کھول کر میچ دکھانے کی صلاحیت کو خود سنبھالتا ہے۔ JavaScript آکورڈین کو ان سب چیزوں کو دوبارہ لاگو کرنا پڑتا ہے، اور عام طور پر یہ اس کا زیادہ تر حصہ غلط طریقے سے دوبارہ بناتا ہے۔
صرف ایک چیز جو details ڈیفالٹ کے طور پر نہیں کرتا وہ یہ ہے کہ جب ایک کھلتا ہے تو اس کے بہن بھائی (siblings) بند نہیں ہوتے۔ اس رویے کو - جسے اکثر ایکسکلوسیو آکورڈین کہا جاتا ہے - اب ہر details عنصر کو ایک ہی name ایٹریبیوٹ دے کر حاصل کیا جا سکتا ہے، جسے براؤزرز ایک گروپ کے طور پر برتتے ہیں۔ آپ کو اس کی ضرورت ہے یا نہیں یہ تکنیکی سے زیادہ ایک حقیقی ڈیزائن کا سوال ہے: ایکسکلوسیو آکورڈین صفحے کو چھوٹا رکھتے ہیں لیکن ان میں سے کسی ایک کو دوبارہ کھولے بغیر دو قطاروں کا موازنہ کرنا ناممکن بنا دیتے ہیں۔
details کی اسٹائلنگ پہلے مشکل ہوتی تھی کیونکہ اس کا ڈیفالٹ ڈسکلوزر ٹرائی اینڈگل summary پر ایک لسٹ مارکر ہوتا ہے۔ اسے ہٹانے کے لیے Tailwind میں marker:content-none کی ضرورت ہوتی ہے، ساتھ ہی پرانے سفاری پر webkit سے متعلقہ ویریئنٹ کی بھی۔ ایک بار جب یہ ہٹ جاتا ہے، تو summary ایک عام flex کنٹینر بن جاتا ہے اور کسٹم شیور کو جہاں چاہیں پوزیشن کیا جا سکتا ہے۔
Anatomy
- کنٹینر
- وہ ریپّر جو قطاروں کو سنبھالتا ہے، جس میں ڈیوائیڈرز اور زیادہ سے زیادہ چوڑائی (max width) ہوتی ہے۔ پڑھنے کی آسانی کے لیے چوڑائی کو محدود رکھیں - پورے صفحے پر پھیلے ہوئے FAQ کے جوابات کو اسکین کرنا مشکل ہوتا ہے۔
- Details
- ہر قطار کے لیے ایک۔ یہاں group کلاس وہ چیز ہے جو شیور کو group-open ویریئنٹ کے ذریعے کھلی ہوئی حالت کا جواب دینے کی اجازت دیتی ہے۔
- Summary
- کلک کرنے کے قابل سرخی۔ پہلے سے فوکس کے قابل اور کی بورڈ سے ایکٹیویٹ ہونے کے قابل، اس لیے اسے کسی role، tabindex، یا key handler کی ضرورت نہیں ہے۔
- انڈیکیٹر
- شیور، جو group-open کے ساتھ گھومتا ہے۔ اسے aria-hidden کے طور پر نشان زد کیا گیا ہے کیونکہ پھیلی ہوئی حالت کا اعلان پہلے ہی خود عنصر کی طرف سے کیا جا چکا ہے۔
- پینل
- summary کے بعد details کے اندر موجود ہر چیز۔ یہاں کوئی بھی مارک اپ کام کرتا ہے - پیراگراف، فہرستیں، فارمز، دیگر کمپوننٹس۔
How to Use
- 1
مارک اپ کاپی کریں
کوئی سا بھی ورژن لیں۔ React والا ایک سادہ فنکشن کمپوننٹ ہے جس میں کوئی اسٹیٹ اور کوئی use client ڈائریکٹو نہیں ہے، اس لیے یہ Next.js App Router میں سرور کمپوننٹ کے طور پر کام کرتا ہے۔
- 2
قطاریں تبدیل کریں
items ارے میں ترمیم کریں، یا HTML ورژن میں details بلاک کو ڈپلیکیٹ کریں۔ پینلز میں کوئی بھی مارک اپ کام کرتا ہے، صرف پیراگراف نہیں۔
- 3
فیصلہ کریں کہ کیا چیز کھلی ہوئی شروع ہو
جس قطار کو لوڈ ہونے پر پھیلایا جانا چاہیے اس میں open ایٹریبیوٹ شامل کریں۔ پہلے والے کو کھولنے سے یہ واضح ہو جاتا ہے کہ قطاریں انٹرایکٹیو ہیں۔
- 4
انتخاب کریں کہ ایکسکلوسیو ہو یا نہیں
اگر ایک کو کھولنے سے دوسرے بند ہونے چاہئیں تو ہر details کو ایک ہی name ایٹریبیوٹ دیں۔ اگر قارئین قطاروں کا موازنہ کرنا چاہیں تو اس ایٹریبیوٹ کو چھوڑ دیں۔
- 5
summary کی اسٹائلنگ کریں
marker:content-none کے ساتھ ڈیفالٹ مارکر کو ہٹائیں، پھر summary کو لیبل اور انڈیکیٹر کے لیے ایک نارمل flex کنٹینر کے طور پر برتیں۔
Features
کوئی JavaScript نہیں
براؤزر ٹگلنگ، کی بورڈ ایکٹیویشن، اور اسٹیٹ کو خود سنبھالتا ہے، اس لیے کمپوننٹ ہائیڈریشن سے پہلے بھی کام کرتا ہے اور اسکرپٹس فیل ہونے کی صورت میں بھی کام کرتا رہتا ہے۔
باضابطہ طور پر درست سیمینٹکس
ایکسپینڈڈ اسٹیٹ خود بخود اسسٹو ٹیکنالوجی کو مل جاتی ہے، اس میں کوئی aria-expanded سیٹ کرنے یا سنک میں رکھنے کی ضرورت نہیں ہوتی۔
کولپس ہونے کے باوجود تلاش کے قابل
براؤزر کا find-in-page فیچر کولپس شدہ پینل کو کھول کر میچ تلاش کر سکتا ہے، جو کہ divs سے بنے ہوئے JavaScript ایکارڈین کے بس کی بات نہیں۔
CSS سے چلنے والا انڈیکیٹر
شیورون کی گھماؤ والی حرکت (rotation) group-open ویریئنٹ سے آتی ہے، لہٰذا اوپن اسٹیٹ کسی اسٹیٹ ویری ایبل کے بجائے براہ راست اسٹائلنگ کو کنٹرول کرتی ہے۔
بغیر کوڈ کے ایکسکلوسیو موڈ
ایک جیسا name ایٹریبیوٹ پورے گروپ کو ایک وقت میں ایک کھولنے والے ایکارڈین کی طرح برتاؤ کرنے پر مجبور کرتا ہے، جسے مکمل طور پر براؤزر سنبھالتا ہے۔
سرور کمپوننٹ کے لیے موزوں
بغیر کسی اسٹیٹ اور ایفیکٹس کے، React ورژن Next.js App Router میں بغیر کسی use client ڈائریکٹو کے سرور پر رینڈر ہوتا ہے۔
Common Uses
FAQ سیکشنز
سب سے عام استعمال۔ ایک اسکرین پر بیس سوالات کی ہیڈنگز آ جاتی ہیں، اور قاری صرف وہی دو کھولتا ہے جو اس کے کام کے ہوں۔
فلٹر گروپس
پروڈکٹ سائیڈ بار میں کولپس ہونے والے کیٹیگری، پرائس، اور ایٹریبیوٹ گروپس، تاکہ چھوٹی اسکرین پر بھی فلٹرز کا طویل سیٹ آسانی سے نیویگیٹ کیا جا سکے۔
سیٹنگز پینلز
کولپس شدہ رو کے پیچھے ایڈوانسڈ آپشنز کو گروپ کرنا سیٹنگز کے صفحے کو سمجھنے میں آسان بناتا ہے بغیر اس کے کہ آپشنز کو مکمل طور پر چھپایا جائے۔
ڈاکومنٹیشن کی تفصیلات
مکمل API ٹیبلز، طویل ایرر میسجز، یا اختیاری سیٹ اپ اسٹیپس کو ڈسکلوزر کے پیچھے چھپانا تاکہ بنیادی مواد آسانی سے پڑھا جا سکے۔
Accessibility
- Summary فوکس ہو سکتا ہے اور پہلے سے Enter اور Space کے ذریعے ایکٹیویٹ ہوتا ہے، اس کے لیے کسی tabindex یا کی ہینڈلر کی ضرورت نہیں ہوتی۔
- ایکسپینڈڈ اور کولپسڈ اسٹیٹ خود عنصر (element) کے ذریعے اسسٹو ٹیکنالوجی کو ظاہر ہوتی ہے، لہٰذا برقرار رکھنے کے لیے کوئی aria-expanded موجود نہیں ہے۔
- شیورون کو aria-hidden کے طور پر نشان زد کیا گیا ہے کیونکہ یہ اس اسٹیٹ کی نقل کرتا ہے جو پہلے ہی بتائی جا چکی ہے؛ اس کے بغیر، اسکرین ریڈر استعمال کرنے والوں کو ہر رو پر ایک بے معنی گرافک سنائی دے گا۔
- کولپسڈ مواد ڈاکومنٹ میں رہتا ہے اور براؤزر کی تلاش سے مل جاتا ہے، یہی وہ طریقہ ہے جس سے بہت سے لوگ طویل FAQ کے صفحے پر مواد تلاش کرتے ہیں۔
- اگر کسی رو کی ہیڈنگ کو ڈاکومنٹ کی ہیڈنگ بھی بنانا ہو، تو details کے باہر رکھنے کے بجائے summary کے اندر ہیڈنگ کا عنصر رکھیں - الٹ نیسٹنگ غلط ہے۔
- اسٹائلنگ کرتے وقت summary پر ڈیفالٹ فوکس رنگ اکثر غلطی سے ہٹ جاتا ہے۔ فوکس دکھانے والا (focus-visible) اسٹائل برقرار رکھیں، ورنہ کی بورڈ استعمال کرنے والے بھول جائیں گے کہ وہ کس رو پر ہیں۔
Customization
- marker:content-none کے ساتھ ڈیفالٹ مثلث کو ہٹا دیں، اور اگر آپ پرانے Safari ورژنز کو سپورٹ کرتے ہیں تو webkit details-marker ویریئنٹ شامل کریں۔
- ہر details کو اس کے اپنے بارڈر والے اور گول کونوں والے کنٹینر میں لپیٹ کر ڈیوائیڈرز کو بارڈر والے کارڈز سے بدل دیں۔
- دونوں آئکنز کو رینڈر کرکے اور group-open کے ذریعے ان کی ویزیبلٹی ٹگل کرکے شیورون کو پلس اور مائنس میں تبدیل کریں، جو دور سے زیادہ واضح دکھائی دیتا ہے۔
- پینل کی اونچائی کو متحرک (animate) کرنا اب بھی مشکل ہے کیونکہ 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 کے اندر کا مواد اب بھی براؤزر کے find-in-page کے ذریعے سامنے آ سکتا ہے، جو کہ بہت سے قارئین طویل FAQ کو نیویگیٹ کرنے کے لیے استعمال کرتے ہیں - div پر مبنی ایکارڈین اس مواد کو تلاش سے خاموشی سے چھپا دیتا ہے۔
React ورژن کو کسی use client ڈائریکٹو کی ضرورت نہیں ہوتی، اس لیے یہ سرور پر رینڈر ہوتا ہے۔ گردش کرنے والے زیادہ تر ایکارڈین کمپونینٹس صرف اس لیے کلائنٹ کمپونینٹس ہیں کیونکہ وہ اس اوپن اسٹیٹ کو ٹریک کرتے ہیں جسے براؤزر پہلے ہی ٹریک کر رہا تھا۔
Tips
- پہلی رو کو ڈیفالٹ کے طور پر کھولیں۔ بند ہیڈنگز کا کالم ایک جامد (static) فہرست کی طرح لگ سکتا ہے، اور قاری ہمیشہ کسی ایک پر کلک کرنے کی کوشش نہیں کرے گا۔
- پینلز کو چھوٹا رکھیں۔ اگر کوئی جواب چند پیراگراف سے طویل ہو جائے، تو مکمل صفحے کا لنک دے دیں - طویل پینلز اگلی قطار کو بہت نیچے دھکیل دیتے ہیں اور فہرست کو اسکین کرنا مشکل بنا دیتے ہیں۔
- خصوصی برتاؤ کے لیے JavaScript کی بجائے مشترکہ name attribute استعمال کریں۔ یہ ایک ہی attribute ہے اور براؤزر باقی کام خود سنبھالتا ہے۔
- خلاصہ (summary) کو اس سوال کی طرح لکھیں جو کوئی قاری اصل میں ٹائپ کرے گا۔ FAQ کی قطاریں اکثر کسی صفحے کا وہ حصہ ہوتی ہیں جو تلاش کے نتائج میں ظاہر ہوتا ہے، اور الفاظ کا یہی انتخاب فیصلہ کرتا ہے کہ آیا ایسا ہوگا۔
- details کے گرد کوئی heading element نیسٹ (nest) نہ کریں۔ اگر آپ چاہتے ہیں کہ سوال دستاویز کی سرخی (document heading) بنے، تو سرخی کو summary کے اندر رکھیں۔
- فوکس رنگ پر نظر رکھیں۔ summary کو اسٹائل کرتے وقت اسے ہٹانا آسان ہے، اور اس کے بغیر کی بورڈ استعمال کرنے والے یہ نہیں جان سکتے کہ وہ کس قطار پر ہیں۔