0Pricing
Web Accessibility Academy · レッスン

アクション後にフォーカスを移動する

次にユーザーが必要とする場所へフォーカスを移します。

「アクション後にフォーカスを移動する」はCoddyKit上の無料Web Accessibility Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb Accessibility Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web Accessibility Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. ✨

よくある質問

「アクション後にフォーカスを移動する」レッスンは無料ですか?

はい。「アクション後にフォーカスを移動する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web Accessibility Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web Accessibility Academyコースには全4レッスンが含まれています。

「アクション後にフォーカスを移動する」で何を学びますか?

次にユーザーが必要とする場所へフォーカスを移します。 ブラウザで直接実行するハンズオンコードでWeb Accessibility Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web Accessibility Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb Accessibility Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「アクション後にフォーカスを移動する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb Accessibility Academyレッスンでコードを書いて実行できますか?

はい。すべてのWeb Accessibility Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. tabindex 0、-1、そして正の値は使わない
  2. アクション後にフォーカスを移動する
  3. レイヤーを閉じたときにフォーカスを戻す
  4. ウィジェットでroving tabindexを管理する
← Web Accessibility Academyに戻る