File tree 2 files changed +25
-10
lines changed
2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -26,17 +26,19 @@ function beforeNodeRemoved(node) {
26
26
}
27
27
28
28
function beforeNodeMorphed ( target , newElement ) {
29
- if ( target instanceof HTMLElement && ! target . hasAttribute ( "data-turbo-permanent" ) ) {
30
- const event = dispatch ( "turbo:before-morph-element" , {
31
- cancelable : true ,
32
- target,
33
- detail : {
34
- newElement
35
- }
36
- } )
37
- return ! event . defaultPrevented
29
+ if ( target instanceof HTMLElement ) {
30
+ if ( ! target . hasAttribute ( "data-turbo-permanent" ) ) {
31
+ const event = dispatch ( "turbo:before-morph-element" , {
32
+ cancelable : true ,
33
+ target,
34
+ detail : {
35
+ newElement
36
+ }
37
+ } )
38
+ return ! event . defaultPrevented
39
+ }
40
+ return false
38
41
}
39
- return false
40
42
}
41
43
42
44
function beforeAttributeUpdated ( attributeName , target , mutationType ) {
Original file line number Diff line number Diff line change @@ -210,6 +210,19 @@ test("action=morph", async () => {
210
210
assert . equal ( subject . find ( "h1#hello" ) ?. textContent , "Hello Turbo Morphed" )
211
211
} )
212
212
213
+ test ( "action=morph with text content change" , async ( ) => {
214
+ const templateElement = createTemplateElement ( `<div id="hello">Hello Turbo Morphed</div>` )
215
+ const element = createStreamElement ( "morph" , "hello" , templateElement )
216
+
217
+ assert . equal ( subject . find ( "div#hello" ) ?. textContent , "Hello Turbo" )
218
+
219
+ subject . append ( element )
220
+ await nextAnimationFrame ( )
221
+
222
+ assert . ok ( subject . find ( "div#hello" ) )
223
+ assert . equal ( subject . find ( "div#hello" ) ?. textContent , "Hello Turbo Morphed" )
224
+ } )
225
+
213
226
test ( "action=morph children-only" , async ( ) => {
214
227
const templateElement = createTemplateElement ( `<h1 id="hello-child-element">Hello Turbo Morphed</h1>` )
215
228
const element = createStreamElement ( "morph" , "hello" , templateElement )
You can’t perform that action at this time.
0 commit comments