0Pricing
Web Accessibility Academy · درس

لوحات الأكورديون باستخدام Button وaria-expanded

أنشئوا عنصراً قابلاً للكشف يعلن حالتي الفتح والإغلاق

لوحات الأكورديون باستخدام Button وaria-expanded درس مجاني في Web Accessibility Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web Accessibility Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What an Accordion Does

An accordion is a stack of headings that expand and collapse to reveal content. Each section can open on its own, unlike tabs.

The Header Is a Button

Make every accordion header a real button. Buttons are focusable, work with Enter and Space, and announce themselves to screen readers for free.

<button>Shipping details</button>

A div Header Fails

Watch out for a clickable div as a header. It is not focusable, ignores the keyboard, and tells assistive tech nothing about its job.

<div onclick="toggle()">Shipping details</div>

aria-expanded Is the Key

Add aria-expanded to the button so screen readers announce collapsed or expanded. This single state is what makes an accordion accessible.

<button aria-expanded="false">Shipping details</button>

Toggle the State on Click

When the user activates the button, flip aria-expanded between true and false. Keep it in sync with whether the panel is actually showing.

btn.setAttribute("aria-expanded", String(open));

Point at the Region

Use aria-controls on the button, set to the id of the panel it opens. Users learn which content this header reveals.

<button aria-controls="sec1" aria-expanded="false">More</button>

Hide the Collapsed Panel

When a section is closed, give its panel the hidden attribute. That removes it from the page and from the accessibility tree until reopened.

<div id="sec1" hidden>Panel content</div>

Wrap Headers in Real Headings

Place each button inside a real heading like h3. Screen reader users can then jump section to section using heading navigation.

<h3><button aria-expanded="false">FAQ</button></h3>

No ARIA on Single Disclosures

A lone show-and-hide is a disclosure, not a tab set. It needs only a button with aria-expanded, no tablist or tab roles at all.

Keep Focus on the Button

After toggling, leave focus on the button the user pressed. Do not steal focus into the panel; that surprises keyboard users.

Why aria-expanded Wins

Because the button carries its own state, a screen reader says expanded or collapsed every time. Users always know what activating it will do.

Quick Check

You are building an accordion header that opens and closes a section. Which attribute makes its state accessible?

Recap: Accessible Accordions

You learned an accordion header is a button with aria-expanded, wrapped in a heading. Toggle the state, point at the panel, and hide it when closed.

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

هل درس «لوحات الأكورديون باستخدام Button وaria-expanded» مجاني؟

نعم — نص درس «لوحات الأكورديون باستخدام Button وaria-expanded» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web Accessibility Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.

ماذا ستتعلم في «لوحات الأكورديون باستخدام Button وaria-expanded»؟

أنشئوا عنصراً قابلاً للكشف يعلن حالتي الفتح والإغلاق تتمرن على Web Accessibility Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Web Accessibility Academy؟

لا تُشترط خبرة سابقة. Web Accessibility Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «لوحات الأكورديون باستخدام Button وaria-expanded»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Web Accessibility Academy هذا؟

نعم. كل درس في Web Accessibility Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. نمط علامات التبويب: tablist وtab وtabpanel
  2. التنقل بين علامات التبويب بمفاتيح الأسهم
  3. لوحات الأكورديون باستخدام Button وaria-expanded
  4. العنصر القابل للكشف أم علامات التبويب: اختاروا الأنسب
← العودة إلى Web Accessibility Academy