Skip to content

Commit b76ea47

Browse files
committed
Make color/caret-color work when transition set on code-input element, and transitionend event be called as expected
1 parent 2c0aef7 commit b76ea47

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

code-input.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ code-input {
2424
to keep low precedence and thus overridability
2525
The variable names may change and are for internal use. */
2626
/* --code-input_highlight-text-color: Set by JS to be base text color of pre code element */
27-
--code-input_no-override-color: inherit; /* Set by JS for very short time to get whether color has been overriden */
28-
color: var(--code-input_no-override-color, inherit);
27+
--code-input_no-override-color: revert; /* Set by JS for very short time to get whether color has been overriden */
28+
color: var(--code-input_no-override-color, revert);
2929
/* --code-input_default-caret-color: Set by JS to be same as color property */
30-
caret-color: var(--code-input_default-caret-color, black); /* Set by JS to be equal to color property */
30+
caret-color: var(--code-input_default-caret-color, black); /* Set by JS to be equal to color property - currentColor won't work because it's lazily evaluated so gives transparent for the textarea */
3131
background-color: white;
3232

3333
/* Normal inline styles */

code-input.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,26 @@ var codeInput = {
556556
* return false.
557557
*/
558558
isColorOverridenSyncIfNot() {
559+
const oldTransition = this.style.transition;
560+
this.style.transition = "unset";
559561
this.style.setProperty("--code-input_no-override-color", "rgb(0, 0, 0)");
560562
if(getComputedStyle(this).color == "rgb(0, 0, 0)") {
561563
// May not be overriden
562564
this.style.setProperty("--code-input_no-override-color", "rgb(255, 255, 255)");
563565
if(getComputedStyle(this).color == "rgb(255, 255, 255)") {
564566
// Definitely not overriden
565567
this.style.removeProperty("--code-input_no-override-color");
568+
this.style.transition = oldTransition;
566569

567-
this.style.setProperty("--code-input_highlight-text-color", getComputedStyle(this.getStyledHighlightingElement()).color);
568-
this.style.setProperty("--code-input_default-caret-color", getComputedStyle(this.getStyledHighlightingElement()).color);
570+
const highlightedTextColor = getComputedStyle(this.getStyledHighlightingElement()).color;
571+
572+
this.style.setProperty("--code-input_highlight-text-color", highlightedTextColor);
573+
this.style.setProperty("--code-input_default-caret-color", highlightedTextColor);
569574
return false;
570575
}
571576
}
572577
this.style.removeProperty("--code-input_no-override-color");
578+
this.style.transition = oldTransition;
573579

574580
return true;
575581
}
@@ -836,11 +842,20 @@ var codeInput = {
836842
if(evt.propertyName == "color") {
837843
this.syncColorCompletely();
838844
}
845+
if(evt.target == this.dialogContainerElement) {
846+
evt.stopPropagation();
847+
// Prevent bubbling because code-input
848+
// transitionend is separate
849+
}
839850
};
840-
// Not on this element so CSS transition property which must be set for
851+
// Not on this element so CSS transition property does not override publicly-visible one
841852
this.dialogContainerElement.addEventListener("transitionend", thisColorChangeCallback);
842853
this.dialogContainerElement.addEventListener("-webkit-transitionend", thisColorChangeCallback);
843854

855+
// For when this code-input element has an externally-defined, different-duration transition
856+
this.addEventListener("transitionend", thisColorChangeCallback);
857+
this.addEventListener("-webkit-transitionend", thisColorChangeCallback);
858+
844859
this.syncColorCompletely();
845860

846861
this.classList.add("code-input_loaded");

0 commit comments

Comments
 (0)