Frontory

Open code, practice, and notes →

Download source with English comments · for reading

Motion · 13 Focus During Deletion

Series contents · Technology map

Stage: Layout and Presence · Editable example · Storage ID: motion-step-13

Goals and learning outcomes

Prerequisites

Prepare the results of the Visual connection and Separating regions exercises from Unit 12, “Sharing LayoutId”.

Key concepts and explanations

DOM lifetime

An element undergoing exit can remain on screen. Decide whether a card removed from the data should still allow interaction.

Focus restoration

Move focus from the deleted button to the next valid location. Waiting only for the animation to finish leaves a gap in interaction.

Practice setup

First check the execution scope guidance on the example screen. The following describes the environment needed to extend the assignment in a separate project. The existing motion-01·02·03 examples are limited examples based on Motion JS animate. For React layout, AnimatePresence, and hooks exercises, install motion in a separate local React project and import from motion/react. Do not assume JSX runs directly in the editor; preserve CSP and isolation.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. In src/day-13.tsx of a separate exercise project, add a ref to each delete button and move focus to the next card or the add button. Use the existing Unit 1·14·28 examples only as starting points.
  2. Input condition: Deleting the first, middle, and last cards. Baseline: Middle. Run under the baseline condition, then record observations and errors in notes/day-13.md.
  3. Variable to change: Deletion position; new value: Last. Run again with the same input path. Deliverable to save: A record of activeElement for each deletion position. Hypothesis to test: Focus moves to a remaining valid control. Compare it with the actual results and record whether they agree and the causes of any differences.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
Deletion positionMiddleLastFocus moves to a remaining valid control.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Which processing stage does DOM lifetime affect in this exercise? Input case: Deleting the first, middle, and last cards.
  2. Variable to change: Deletion position. Hypothesis to test: Focus moves to a remaining valid control. Did the actual results agree with the hypothesis? Explain your evidence in terms of Focus restoration.

Official references

Linked example and execution scope

Example source · Runtime environments and limits

The supplied example restores focus to the control after onExitComplete. Moving focus immediately to a valid target during exit is a separate assignment.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Sharing LayoutId · Next: Layout and Exit

Open code, practice, and notes →