-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude document.body
when morphing with ignoreActiveValue: true
#34
Exclude document.body
when morphing with ignoreActiveValue: true
#34
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.
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
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); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
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
* 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`
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)
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)
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
fromdocument.activeElement
when no other element has focus.This commit incorporates that condition into the
ignoreValueOfActiveElement()
predicate function.