Fragments وPortals وفخ ترتيب DOM
حافظوا على تطابق الترتيب المعروض مع شجرة إمكانية الوصول
Fragments وPortals وفخ ترتيب DOM درس مجاني في Web Accessibility Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web Accessibility Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Source Order Is the Default Order
Screen readers and the keyboard follow the DOM order, the order elements appear in the document. CSS may move things visually, but reading order does not change.
Fragments Add No Extra Box
A React Fragment groups children without adding a wrapper div. That keeps your DOM clean and avoids breaking lists or tables with stray elements.
<>
<th>Name</th>
<th>Email</th>
</>Why a Wrapper div Can Hurt
An extra div inside a list or table can break the parent-child structure assistive tech expects. A Fragment avoids that invalid nesting entirely.
Portals Render Elsewhere
A Portal renders children into a different DOM node, often the document body. It is the standard way to mount modals above everything else.
createPortal(<Modal />, document.body);Portals Keep React Context
Even though the markup lands elsewhere, a portal stays in your component tree. State and context flow normally, so logic is unaffected.
The DOM Order Trap
A portal at the end of body can appear after unrelated content. Tabbing may jump to a far-off spot, so focus management becomes essential for portals.
Move Focus Into the Portal
When a portal opens, the keyboard does not follow automatically. Explicitly move focus into the modal so the user is where the new content is.
Trap and Return Focus
While a portal modal is open, keep Tab inside it. On close, return focus to the element that opened it, since DOM proximity will not do this for you.
Visual Order Versus Reading Order
CSS flexbox order or grid placement can rearrange the screen. The tab order still follows the source, so avoid reordering interactive content with CSS.
Keep Source Order Meaningful
Write your JSX so the source order matches the logical reading flow. Then both sighted and screen reader users encounter content in the same sensible sequence.
Test by Tabbing
Press Tab through your app and watch where focus goes. If it jumps somewhere unexpected, your DOM order or a portal needs attention.
Quick Check
You mount a modal with a portal into document.body. What new responsibility does that create?
Recap: Order and Portals
Use Fragments to avoid invalid wrappers, keep source order logical, and manage focus carefully whenever a portal renders content elsewhere. 🧩
الأسئلة الشائعة
هل درس «Fragments وPortals وفخ ترتيب DOM» مجاني؟
نعم — نص درس «Fragments وPortals وفخ ترتيب DOM» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web Accessibility Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.
ماذا ستتعلم في «Fragments وPortals وفخ ترتيب DOM»؟
حافظوا على تطابق الترتيب المعروض مع شجرة إمكانية الوصول تتمرن على Web Accessibility Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Web Accessibility Academy؟
لا تُشترط خبرة سابقة. Web Accessibility Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «Fragments وPortals وفخ ترتيب DOM»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Web Accessibility Academy هذا؟
نعم. كل درس في Web Accessibility Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تغيير المسارات دون إعادة تحميل الصفحات
- إدارة التركيز باستخدام Refs وuseEffect
- Fragments وPortals وفخ ترتيب DOM
- jsx-a11y وحواجز الأمان على مستوى المكوّنات