Skip to content

Commit 8b39ceb

Browse files
committed
Expand focus example to show search
1 parent eab977f commit 8b39ceb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/content/reference/react/Fragment.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,23 @@ function FormFields({ children }) {
523523
</>
524524
);
525525
}
526+
527+
// Even though the inputs are deeply nested,
528+
// focus() searches depth-first to find them.
529+
function App() {
530+
return (
531+
<FormFields>
532+
<fieldset>
533+
<legend>Shipping</legend>
534+
<label>Street: <input name="street" /></label>
535+
<label>City: <input name="city" /></label>
536+
</fieldset>
537+
</FormFields>
538+
);
539+
}
526540
```
527541
528-
`focus()` finds the first focusable element by searching depth-first through all nested children. `focusLast()` does the same in reverse. `blur()` removes focus if the currently focused element is within the Fragment.
542+
Calling `focusFirst()` focuses the `street` input—even though it is nested inside a `<fieldset>` and `<label>`. `focus()` searches depth-first through all nested children, not just direct children of the Fragment. `focusLast()` does the same in reverse, and `blur()` removes focus if the currently focused element is within the Fragment.
529543
530544
---
531545

0 commit comments

Comments
 (0)