-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve EditableField error handling (#374)
* Improve EditableField error handling * Revert out-of-scope change * Add test
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Ember from "ember"; | ||
|
||
/** | ||
* Blinks an element twice by toggling its visibility. | ||
* Used for emphasis, such as to reiterate an | ||
* already-visible form error. | ||
*/ | ||
const DURATION = Ember.testing ? 0 : 100; | ||
|
||
export default function blinkElement(element?: Element | null) { | ||
if (!element) { | ||
return; | ||
} | ||
|
||
for (let i = 0; i < 4; i++) { | ||
// Alternate between hidden and visible | ||
let visibility = i % 2 === 0 ? "hidden" : "visible"; | ||
|
||
setTimeout(() => { | ||
if (element) { | ||
element.setAttribute("style", `visibility: ${visibility}`); | ||
} | ||
}, i * DURATION); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { waitUntil } from "@ember/test-helpers"; | ||
import blinkElement from "hermes/utils/blink-element"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Unit | Utility | blink-element", function () { | ||
test("it blinks an element", async function (assert) { | ||
assert.expect(0); | ||
|
||
const div = document.createElement("div"); | ||
|
||
blinkElement(div); | ||
|
||
await waitUntil(() => div.style.visibility === "hidden"); | ||
await waitUntil(() => div.style.visibility === "visible"); | ||
await waitUntil(() => div.style.visibility === "hidden"); | ||
await waitUntil(() => div.style.visibility === "visible"); | ||
}); | ||
}); |