Skip to content

Commit

Permalink
Omit ignoreActiveValue: true Morph option
Browse files Browse the repository at this point in the history
Closes [hotwired#1194][]
Rolls back [hotwired#1141][]

Don't pass the `ignoreActiveValue: true` option when Morphing. To
restore that behavior, applications can set `[data-turbo-permanent]`
when form control receives focus (through a `focusin` event listener),
then remove it if necessary when the form control loses focus (through a
`focusout` event listener).

[hotwired#1141]: hotwired#1141
[hotwired#1194]: hotwired#1194
  • Loading branch information
seanpdoyle committed Feb 21, 2024
1 parent fccb3a4 commit 37d2dd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/core/drive/morph_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class MorphRenderer extends PageRenderer {
this.isMorphingTurboFrame = this.#isFrameReloadedWithMorph(currentElement)

Idiomorph.morph(currentElement, newElement, {
ignoreActiveValue: true,
morphStyle: morphStyle,
callbacks: {
beforeNodeAdded: this.#shouldAddElement,
Expand Down
8 changes: 8 additions & 0 deletions src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

const application = Application.start()

addEventListener("focusin", ({ target }) => {
if (target instanceof HTMLInputElement && !target.hasAttribute("data-turbo-permanent")) {
target.toggleAttribute("data-turbo-permanent", true)

target.addEventListener("focusout", () => target.toggleAttribute("data-turbo-permanent", false), { once: true })
}
})

addEventListener("turbo:morph-element", ({ target }) => {
for (const { element, context } of application.controllers) {
if (element === target) {
Expand Down

0 comments on commit 37d2dd6

Please sign in to comment.