0Pricing
Web Accessibility Academy · บทเรียน

คืนโฟกัสเมื่อเลเยอร์ปิดลง

คืนผู้ใช้ไปยังจุดที่หยุดไว้

คืนโฟกัสเมื่อเลเยอร์ปิดลง เป็นบทเรียน Web Accessibility Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web Accessibility Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web Accessibility Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Layers Borrow Focus

When a modal, menu, or drawer opens, focus moves inside it. When it closes, you are responsible for returning focus to where the user was.

The Lost-Focus Problem

If a closed layer leaves focus on a removed element, it falls back to the page body. The user is stranded with no sense of place.

Remember the Trigger

The fix starts before opening: save a reference to the element that triggered the layer, usually document.activeElement.

const trigger = document.activeElement;

Restore on Close

When the layer closes, call focus() on that saved trigger so the user lands right back where they started.

trigger.focus();

The Full Round Trip

Open: store the trigger and focus the layer. Close: hide it and restore the trigger. That loop is the focus contract of any dismissible layer. 🔁

Native dialog Helps

The browser's dialog element restores focus to the opener automatically when you call close(), saving you the manual bookkeeping.

myDialog.close();

Handle Every Exit Path

Restore focus no matter how the layer closes: a Close button, the Escape key, or a click on the backdrop should all return the user.

When the Trigger Is Gone

If the trigger was removed while the layer was open, send focus to a sensible nearby element instead, never to nowhere.

Why This Matters So Much

Sighted mouse users barely notice, but for keyboard and screen reader users a missed focus return can make a feature unusable.

Test It Keyboard-Only

Open the layer with Enter, close it with Escape, and confirm the focus ring reappears on the button that opened it.

Make It a Habit

Treat focus return as part of building any overlay, not an afterthought. Wire it the moment you add open and close logic.

Quick Check

A custom modal closes. What is the correct destination for focus?

Recap

You can now close the loop: save the trigger on open, restore focus to it on every close path, and lean on native dialog when you can. 🎯

คำถามที่พบบ่อย

บทเรียน “คืนโฟกัสเมื่อเลเยอร์ปิดลง” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “คืนโฟกัสเมื่อเลเยอร์ปิดลง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web Accessibility Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web Accessibility Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “คืนโฟกัสเมื่อเลเยอร์ปิดลง”

คืนผู้ใช้ไปยังจุดที่หยุดไว้ คุณปฏิบัติ Web Accessibility Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web Accessibility Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web Accessibility Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “คืนโฟกัสเมื่อเลเยอร์ปิดลง” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Web Accessibility Academy นี้ได้ไหม

ได้ บทเรียน Web Accessibility Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. tabindex 0, -1 และห้ามใช้ค่าบวก
  2. ย้ายโฟกัสหลังการดำเนินการ
  3. คืนโฟกัสเมื่อเลเยอร์ปิดลง
  4. จัดการ tabindex แบบเลื่อนตำแหน่งในวิดเจ็ต
← กลับไปที่ Web Accessibility Academy