نقل التركيز إلى أول خطأ
وجّهوا المستخدمين مباشرةً إلى ما يجب إصلاحه
نقل التركيز إلى أول خطأ درس مجاني في Web Accessibility Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web Accessibility Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Lost After Submit
A user submits, the page shows errors at the top, but focus stays on the button. They have no idea anything failed. 😕
Send Focus to the Problem
On a failed submit, move focus to the first invalid field. The user lands exactly where the fix begins, no hunting required.
Use focus in JS
Find the first failing control and call focus() on it. Now both keyboard and screen reader users start at the right place.
const first = form.querySelector("[aria-invalid='true']");
if (first) first.focus();Read Name, Type, Error
When focus lands there, the screen reader announces the field's name, that it is invalid, and its described error all at once.
First, Not Random
Always target the first error in document order. Jumping to a later field skips problems the user must still address.
Do Not Just Scroll
Scrolling the error into view helps the mouse, but keyboard and screen reader users need real focus moved, not just pixels shifted.
A Summary Box Helps
For many errors, focus an error summary at the top first. List each problem as a link that jumps to its field.
<div tabindex="-1" id="errors">
3 errors found
</div>Make the Summary Focusable
A heading or div is not focusable by default. Add tabindex="-1" so your script can move focus to it programmatically.
Link Errors to Fields
Inside the summary, each item is a link to the field's id. Activating it sends focus straight to the broken input.
<a href="#email">Email is required</a>Avoid Stealing Focus Early
Only move focus in response to the user's submit, never on every keystroke. Yanking focus mid-typing is jarring and unwelcome.
Confirm the Recovery
After the user fixes everything and resubmits, move focus to a success message so they hear that it finally worked.
Quick Check
Where should focus go when a form submit fails?
Recap
On failure, move focus to the first invalid field or a focusable error summary, and to a success message once it passes. ✅
الأسئلة الشائعة
هل درس «نقل التركيز إلى أول خطأ» مجاني؟
نعم — نص درس «نقل التركيز إلى أول خطأ» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web Accessibility Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.
ماذا ستتعلم في «نقل التركيز إلى أول خطأ»؟
وجّهوا المستخدمين مباشرةً إلى ما يجب إصلاحه تتمرن على Web Accessibility Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Web Accessibility Academy؟
لا تُشترط خبرة سابقة. Web Accessibility Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «نقل التركيز إلى أول خطأ»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Web Accessibility Academy هذا؟
نعم. كل درس في Web Accessibility Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- ربط الأخطاء بالحقول باستخدام aria-describedby
- تحديد الحالة غير الصالحة باستخدام aria-invalid
- نقل التركيز إلى أول خطأ
- مضمّن، أو عند فقدان التركيز، أو عند الإرسال: التوقيت مهم