Ver Fonte

added x-trap entangle test (#2017)

Co-Authored-By: Simone Todaro <simo.todaro@gmail.com>

Co-authored-by: Simone Todaro <simo.todaro@gmail.com>
Dede Muzaffer há 3 anos atrás
pai
commit
f2455e8a0a

+ 1 - 1
packages/trap/src/index.js

@@ -44,7 +44,7 @@ function crawlSiblingsUp(el, callback) {
     Array.from(el.parentNode.children).forEach(sibling => {
         if (! sibling.isSameNode(el)) callback(sibling)
 
-        crawlSiblingsUp(el.parentNode, callback) 
+        crawlSiblingsUp(el.parentNode, callback)
     })
 }
 

+ 28 - 0
tests/cypress/integration/plugins/trap.spec.js

@@ -28,3 +28,31 @@ test('can trap focus',
         get('#2').should(haveFocus())
     },
 )
+
+test('works with clone',
+    [html`
+        <div id="foo" x-data="{
+            open: false,
+            triggerClone() {
+                var original = document.getElementById('foo');
+                var copy = original.cloneNode(true);
+                Alpine.clone(original, copy);
+                var p = document.createElement('p');
+                p.textContent = 'bar';
+                copy.appendChild(p);
+                original.parentNode.replaceChild(copy, original);
+            }
+        }">
+            <button id="one" @click="open = true">Trap</button>
+            <div x-trap="open">
+                <input type="text">
+                <button id="two" @click="triggerClone()">Test</button>
+            </div>
+        </div>
+    `],
+    ({ get, wait }, reload) => {
+        get('#one').click()
+        get('#two').click()
+        get('p').should(haveText('bar'))
+    }
+)