Exclude document.body when morphing with ignoreActiveValue: true#34
Merged
1cg merged 1 commit intobigskysoftware:mainfrom Jan 29, 2024
Merged
Conversation
When morphing with `ignoreActiveValue: true`, the `<body>` element and its children (that is, the entire document) can be preserved if no other element has focus. Its common in some browsers (for example, Safari) to return `document.body` from `document.activeElement` when no other element has focus. This commit incorporates that condition into the `ignoreValueOfActiveElement()` predicate function.
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Jan 25, 2024
Morph with the [ignoreActiveValue: true][] option to morph the currently focused element's attributes, but preserve its value. This behavior can be extremely helpful when paired with an auto-submitting `<form>` element, like a typeahead `[role="combobox"]`, or an auto-submitting [`<input type="search">`][search]. This commit depends on a fork of `idiomorph` that [fixes a bug related to `ignoreActiveValue: true`][bigskysoftware/idiomorph#34]. [ignoreActiveValue: true]: https://github.com/bigskysoftware/idiomorph#options [search]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search [bigskysoftware/idiomorph#34]: bigskysoftware/idiomorph#34
seanpdoyle
commented
Jan 25, 2024
Comment on lines
+244
to
+265
| it('does not ignore body when ignoreActiveValue is true and no element has focus', function() | ||
| { | ||
| let parent = make("<div><input value='foo'></div>"); | ||
| document.body.append(parent); | ||
|
|
||
| let initial = parent.querySelector("input"); | ||
|
|
||
| // morph | ||
| let finalSrc = '<input value="bar">'; | ||
| Idiomorph.morph(initial, finalSrc, {morphStyle:'outerHTML'}); | ||
| initial.outerHTML.should.equal('<input value="bar">'); | ||
|
|
||
| document.activeElement.should.equal(initial); | ||
|
|
||
| let finalSrc2 = '<input class="foo" value="doh">'; | ||
| Idiomorph.morph(initial, finalSrc2, {morphStyle:'outerHTML', ignoreActiveValue: true}); | ||
| initial.value.should.equal('doh'); | ||
| initial.classList.value.should.equal('foo'); | ||
|
|
||
| document.body.removeChild(parent); | ||
| }); | ||
|
|
Contributor
Author
There was a problem hiding this comment.
@1cg I wasn't able to execute the test suite locally. I've copied this test body from the one that precedes it, and have removed the call to .focus(). Does that feel sufficient?
I noticed that this project doesn't have CI. Are you able to execute this test in your working test harness?
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Jan 29, 2024
Morph with the [ignoreActiveValue: true][] option to morph the currently focused element's attributes, but preserve its value. This behavior can be extremely helpful when paired with an auto-submitting `<form>` element, like a typeahead `[role="combobox"]`, or an auto-submitting [`<input type="search">`][search]. This commit depends on a fork of `idiomorph` that [fixes a bug related to `ignoreActiveValue: true`][bigskysoftware/idiomorph#34]. [ignoreActiveValue: true]: https://github.com/bigskysoftware/idiomorph#options [search]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search [bigskysoftware/idiomorph#34]: bigskysoftware/idiomorph#34
afcapel
pushed a commit
to hotwired/turbo
that referenced
this pull request
Jan 30, 2024
* Morph with `ignoreActiveValue: true` Morph with the [ignoreActiveValue: true][] option to morph the currently focused element's attributes, but preserve its value. This behavior can be extremely helpful when paired with an auto-submitting `<form>` element, like a typeahead `[role="combobox"]`, or an auto-submitting [`<input type="search">`][search]. This commit depends on a fork of `idiomorph` that [fixes a bug related to `ignoreActiveValue: true`][bigskysoftware/idiomorph#34]. [ignoreActiveValue: true]: https://github.com/bigskysoftware/idiomorph#options [search]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search [bigskysoftware/idiomorph#34]: bigskysoftware/idiomorph#34 * Depend on latest `idiomorph`
seanpdoyle
added a commit
to seanpdoyle/idiomorph
that referenced
this pull request
Apr 12, 2024
Follow-up to [bigskysoftware#34][] As mentioned in a [comment on bigskysoftware#34][], the test suite wasn't executed when the code was initially contributed. When opening `test/index.html` locally in a browser, there is a single test failure: ``` does not ignore body when ignoreActiveValue is true and no element has focus ‣ AssertionError: expected <body …(1)>…(28)</body> to equal <input value="bar"></input>@[native code] ``` This commit resolves that failure by changing the test to more accurately exercise the desired behavior. [bigskysoftware#34]: bigskysoftware#34 [comment on bigskysoftware#34]: bigskysoftware#34 (comment)
seanpdoyle
added a commit
to seanpdoyle/idiomorph
that referenced
this pull request
Apr 12, 2024
Follow-up to [bigskysoftware#34][] As mentioned in a [comment on bigskysoftware#34][], the test suite wasn't executed when the code was initially contributed. When opening `test/index.html` locally in a browser, there is a single test failure: ``` does not ignore body when ignoreActiveValue is true and no element has focus ‣ AssertionError: expected <body …(1)>…(28)</body> to equal <input value="bar"></input>@[native code] ``` This commit resolves that failure by changing the test to more accurately exercise the desired behavior. [bigskysoftware#34]: bigskysoftware#34 [comment on bigskysoftware#34]: bigskysoftware#34 (comment)
Merged
Challenge-Guy
pushed a commit
to Challenge-Guy/turbo-cfm1
that referenced
this pull request
Mar 8, 2025
* Morph with `ignoreActiveValue: true` Morph with the [ignoreActiveValue: true][] option to morph the currently focused element's attributes, but preserve its value. This behavior can be extremely helpful when paired with an auto-submitting `<form>` element, like a typeahead `[role="combobox"]`, or an auto-submitting [`<input type="search">`][search]. This commit depends on a fork of `idiomorph` that [fixes a bug related to `ignoreActiveValue: true`][bigskysoftware/idiomorph#34]. [ignoreActiveValue: true]: https://github.com/bigskysoftware/idiomorph#options [search]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search [bigskysoftware/idiomorph#34]: bigskysoftware/idiomorph#34 * Depend on latest `idiomorph`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When morphing with
ignoreActiveValue: true, the<body>element and its children (that is, the entire document) can be preserved if no other element has focus.Its common in some browsers (for example, Safari) to return
document.bodyfromdocument.activeElementwhen no other element has focus.This commit incorporates that condition into the
ignoreValueOfActiveElement()predicate function.