You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Methods that target children (such as `addEventListener`, `observeUsing`, and `getClientRects`) operate on *first-level host (DOM) children* of the Fragment. They do not directly target children nested inside another DOM element.
246
-
* When host children are dynamically added or removed, the `FragmentInstance` automatically updates. New children receive any previously added event listeners and active observers.
247
246
*`focus` and `focusLast` search nested children depth-first for focusable elements, unlike event and observer methods which only target first-level host children.
248
247
*`observeUsing` does not work on text nodes. React logs a warning in development if the Fragment contains only text children.
249
-
*`focus`, `focusLast`, and `blur` have no effect when the Fragment contains only text children.
250
248
* React does not apply event listeners added via `addEventListener` to hidden [`<Activity>`](/reference/react/Activity) trees. When an `Activity` boundary switches from hidden to visible, listeners are applied automatically.
251
249
* Each first-level DOM child of a Fragment with a `ref` gets a `reactFragments` property—a `Set<FragmentInstance>` containing all Fragment instances that own the element. This enables [caching a shared observer](#caching-global-intersection-observer) across multiple Fragments.
252
250
@@ -430,7 +428,7 @@ function PostBody({ body }) {
430
428
431
429
Fragment `ref`s let you add event listeners to a group of elements without adding a wrapper DOM node. Use a [ref callback](/reference/react-dom/components/common#ref-callback) to attach and clean up listeners:
432
430
433
-
```js {4-7}
431
+
```js
434
432
import { Fragment } from'react';
435
433
436
434
functionClickableGroup({ children, onClick }) {
@@ -473,35 +471,6 @@ Methods like `addEventListener`, `observeUsing`, and `getClientRects` operate on
473
471
474
472
---
475
473
476
-
### <CanaryBadge /> Observing visibility without a wrapper element {/*observing-visibility-without-wrapper*/}
477
-
478
-
Use `observeUsing` to attach an `IntersectionObserver` to all first-level DOM children of a Fragment. This lets you track visibility without requiring child components to expose `ref`s or adding a wrapper element:
### <CanaryBadge /> Managing focus across a group of elements {/*managing-focus-across-elements*/}
506
475
507
476
Fragment `ref`s provide `focus`, `focusLast`, and `blur` methods that operate across all DOM nodes within the Fragment:
@@ -541,6 +510,36 @@ function App() {
541
510
542
511
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.
543
512
513
+
514
+
---
515
+
516
+
### <CanaryBadge /> Observing visibility without a wrapper element {/*observing-visibility-without-wrapper*/}
517
+
518
+
Use `observeUsing` to attach an `IntersectionObserver` to all first-level DOM children of a Fragment. This lets you track visibility without requiring child components to expose `ref`s or adding a wrapper element:
0 commit comments