0Pricing
Web Accessibility Academy · Lección

Mover el foco después de una acción

Envíe el foco al lugar que el usuario necesita a continuación.

Mover el foco después de una acción es una lección gratuita de Web Accessibility Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Web Accessibility Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Web Accessibility Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Focus Is the User's Cursor

For keyboard and screen reader users, focus is where they are on the page. After an action, you decide where that point lands next.

Why Move Focus at All

When a button reveals new content, focus often stays put and the user never learns anything changed. Moving focus brings them to the result.

The focus Method

You move focus in JavaScript by calling element.focus() on the target you want the user to land on next.

document.getElementById('results').focus();

Make the Target Focusable First

A plain div will not accept focus, so give the destination tabindex="-1" so your script can move focus to it.

<div id="results" tabindex="-1">3 matches found</div>

Example: Reveal and Focus

After loading new content, show it and then send focus there so the screen reader starts reading the new region. 🔎

panel.hidden = false;
panel.focus();

Focus the Heading, Not the Whole Region

Pointing focus at the new section's heading often reads best, giving the user a clear title for where they just arrived.

Deleting an Item

When the user removes a row, focus would otherwise be lost. Move it to the next item or a nearby control so they can keep going.

Avoid the Focus-to-Top Jolt

Letting focus snap back to the page top after every action is jarring. Aim it at the relevant spot instead so context is preserved.

Do Not Steal Focus Randomly

Only move focus in response to a user action. Grabbing it during background updates yanks people out of whatever they were doing.

Confirm It Worked

Test by triggering the action with the keyboard and watching the focus ring land where you intended, every single time.

One Move Per Action

Each meaningful action should result in exactly one deliberate focus move. Predictable beats clever every time.

Quick Check

You want to move focus to a freshly shown div after a button click. What must the div have?

Recap

You learned to move focus on purpose: make the target focusable with tabindex="-1", call focus() after the action, and aim for the most useful spot. ✨

Preguntas frecuentes

¿La lección «Mover el foco después de una acción» es gratis?

Sí — el texto completo de «Mover el foco después de una acción» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Web Accessibility Academy, actualiza a CoddyKit PRO. El curso de Web Accessibility Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Mover el foco después de una acción»?

Envíe el foco al lugar que el usuario necesita a continuación. Practicas Web Accessibility Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Web Accessibility Academy?

No se requiere experiencia previa. Web Accessibility Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Mover el foco después de una acción»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Web Accessibility Academy?

Sí. Cada lección de Web Accessibility Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. tabindex 0, -1 y nunca positivo
  2. Mover el foco después de una acción
  3. Devolver el foco al cerrar una capa
  4. Gestionar tabindex dinámico en widgets
← Volver a Web Accessibility Academy