diff --git a/fixtures/dom/src/components/fixtures/fragment-refs/CompareDocumentPositionCase.js b/fixtures/dom/src/components/fixtures/fragment-refs/CompareDocumentPositionCase.js
new file mode 100644
index 000000000000..aada4e33fa4e
--- /dev/null
+++ b/fixtures/dom/src/components/fixtures/fragment-refs/CompareDocumentPositionCase.js
@@ -0,0 +1,53 @@
+import TestCase from '../../TestCase';
+import Fixture from '../../Fixture';
+import CompareDocumentPositionFragmentContainer from './CompareDocumentPositionFragmentContainer';
+
+const React = window.React;
+
+export default function CompareDocumentPositionCase() {
+ return (
+
+
+
Click the "Compare All Positions" button
+
+
+ The compareDocumentPosition method compares the position of the fragment
+ relative to other elements in the DOM. The "Before Element" should be
+ PRECEDING the fragment, and the "After Element" should be FOLLOWING.
+ Elements inside the fragment should be CONTAINED_BY.
+
+
+
+
+
Remove the event listeners, click a child, observe no alert
-
Add the event listeners back, click a child, observe the alert
+
+ Click "Add event listener" to attach a click handler to the fragment
+
+
Click "Dispatch click event" to dispatch a click event
+
Observe the event log showing the event fired
+
Add a new child, dispatch again to see it still works
+
+ Click "Remove event listener" and dispatch again to see no event fires
+
Fragment refs can manage event listeners on the first level of host
- children. This page loads with an effect that sets up click event
- hanndlers on each child card. Clicking on a card will show an alert
- with the card's text.
+ children. The event log shows when events are dispatched and handled.
New child nodes will also have event listeners applied. Removed nodes
@@ -50,28 +39,17 @@ export default function EventListenerCase() {
-
Target count: {extraChildCount + 3}
-
-
-
-
-
-
+
+ Target count: {extraChildCount + 3}
+
+
+
Child A
@@ -88,8 +66,8 @@ export default function EventListenerCase() {
+
+ );
+}
diff --git a/fixtures/dom/src/components/fixtures/fragment-refs/TextNodesCase.js b/fixtures/dom/src/components/fixtures/fragment-refs/TextNodesCase.js
index 4141e069eec1..c6a359ac8878 100644
--- a/fixtures/dom/src/components/fixtures/fragment-refs/TextNodesCase.js
+++ b/fixtures/dom/src/components/fixtures/fragment-refs/TextNodesCase.js
@@ -1,6 +1,9 @@
import TestCase from '../../TestCase';
import Fixture from '../../Fixture';
import PrintRectsFragmentContainer from './PrintRectsFragmentContainer';
+import CompareDocumentPositionFragmentContainer from './CompareDocumentPositionFragmentContainer';
+import EventFragmentContainer from './EventFragmentContainer';
+import GetRootNodeFragmentContainer from './GetRootNodeFragmentContainer';
const React = window.React;
const {Fragment, useRef, useState} = React;
@@ -242,6 +245,28 @@ function ScrollIntoViewMixed() {
);
}
+function CompareDocumentPositionTextNodes() {
+ return (
+
+
+
Click the "Compare All Positions" button
+
+
+ compareDocumentPosition should work correctly even when the fragment
+ contains only text nodes. The "Before" element should be PRECEDING the
+ fragment, and the "After" element should be FOLLOWING.
+
+
+
+
+ This is text-only content inside the fragment.
+
+
+
+
+ );
+}
+
function ObserveTextOnlyWarning() {
const fragmentRef = useRef(null);
const [message, setMessage] = useState('');
@@ -287,6 +312,126 @@ function ObserveTextOnlyWarning() {
);
}
+function EventTextOnly() {
+ return (
+
+
+
+ Click "Add event listener" to attach a click handler to the fragment
+
+
Click "Dispatch click event" to dispatch a click event
+
Observe that the fragment's event listener fires
+
Click "Remove event listener" and dispatch again
+
+
+ Event operations (addEventListener, removeEventListener, dispatchEvent)
+ work on fragments with text-only content. The event is dispatched on the
+ fragment's parent element since text nodes cannot be event targets.
+
+
+
+
+ This fragment contains only text. Events are handled via the parent.
+
+
+
+
+ );
+}
+
+function EventMixed() {
+ return (
+
+
+
+ Click "Add event listener" to attach a click handler to the fragment
+
+
Click "Dispatch click event" to dispatch a click event
+
Observe that the fragment's event listener fires
+
Click directly on the element or text content to see bubbling
+
+
+ Event operations work on fragments with mixed text and element content.
+ dispatchEvent forwards to the parent element. Clicks on child elements
+ or text bubble up through the DOM as normal.
+
+
+
+
+ Text node before element.
+
+ Element
+
+ Text node after element.
+
+
+
+
+ );
+}
+
+function GetRootNodeTextOnly() {
+ return (
+
+
+
Click the "Get Root Node" button
+
+
+ getRootNode should return the root of the DOM tree containing the
+ fragment's text content. For a fragment in the main document, this
+ should return the Document node.
+
+
+
+
+ This fragment contains only text. getRootNode returns the document.
+
+
+
+
+ );
+}
+
+function GetRootNodeMixed() {
+ return (
+
+
+
Click the "Get Root Node" button
+
+
+ getRootNode should return the root of the DOM tree for fragments with
+ mixed text and element content. The result is the same whether checking
+ from text nodes or element nodes within the fragment.
+
+
+
+
+ Text before element.
+
+ Element
+
+ Text after element.
+
+
+
+
+ );
+}
+
export default function TextNodesCase() {
return (
@@ -297,7 +442,8 @@ export default function TextNodesCase() {