You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code-input.css
+27-7Lines changed: 27 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,14 @@ code-input {
20
20
top:0;
21
21
left:0;
22
22
23
-
color: black;
23
+
/* CSS variables rather than inline styles used for values synced from JavaScript
24
+
to keep low precedence and thus overridability
25
+
The variable names may change and are for internal use. */
26
+
/* --code-input_highlight-text-color: Set by JS to be base text color of pre code element */
27
+
/* --code-input_no-override-color: Set by JS for very short time to get whether color has been overriden */
28
+
color:var(--code-input_no-override-color, black);
29
+
/* --code-input_default-caret-color: Set by JS to be same as color property - currentColor won't work because it's lazily evaluated so gives transparent for the textarea */
stylesheetI: 0,// Increments to give different classes to each code-input element so they can have custom styles synchronised internally without affecting the inline style
156
+
155
157
/**
156
158
* Please see `codeInput.templates.prism` or `codeInput.templates.hljs`.
157
159
* Templates are used in `<code-input>` elements and once registered with
@@ -445,6 +447,16 @@ var codeInput = {
445
447
*/
446
448
dialogContainerElement=null;
447
449
450
+
/**
451
+
* Like style attribute, but with a specificity of 1
452
+
* element, 1 class. Present so styles can be set on only
453
+
* this element while giving other code freedom of use of
* Show some instructions to the user only if they are using keyboard navigation - for example, a prompt on how to navigate with the keyboard if Tab is repurposed.
551
616
* @param {string} instructions The instructions to display only if keyboard navigation is being used. If it's blank, no instructions will be shown.
Copy file name to clipboardExpand all lines: docs/interface/css/_index.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,3 +10,6 @@ title = 'Styling `code-input` elements with CSS'
10
10
* The CSS variable `--padding` should be used rather than the property `padding` (e.g. `<code-input style="--padding: 10px;">...`), or `--padding-left`, `--padding-right`, `--padding-top` and `--padding-bottom` instead of the CSS properties of the same names. For technical reasons, the value must have a unit (i.e. `0px`, not `0`).
11
11
* Background colours set on `code-input` elements will not work with highlighters that set background colours themselves - use `(code-input's selector) pre[class*="language-"]` for Prism.js or `.hljs` for highlight.js to target the highlighted element with higher specificity than the highlighter's theme. You may also set the `background-color` of the code-input element for its appearance when its template is unregistered / there is no JavaScript.
12
12
* For now, elements on top of `code-input` elements should have a CSS `z-index` at least 3 greater than the `code-input` element.
13
+
* The caret and placeholder colour by default follow and give good contrast with the highlighted theme. Setting a CSS rule (with a specificity higher than one element and one class, for good backwards compatibility) for `color` and/or `caret-color` properties on the code-input element will override this behaviour.
14
+
15
+
Please do **not** use `className` in JavaScript referring to code-input elements, because the code-input library needs to add its own classes to code-input elements for easier progressive enhancement. You can, however, use `classList` and `style` as much as you want - it will make your code cleaner anyway.
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js" data-manual></script><!--Remove data-manual if also using Prism normally-->
testAssertion("Core","Dark theme Caret/Placeholder Color Correct",confirm("Are the caret and placeholder near-white? (OK=Yes)"),"user-judged");
402
+
403
+
codeInputElement.style.color="red";
404
+
awaitwaitAsync(200);// Wait for colours to update
405
+
testAssertion("Core","Overriden color Caret/Placeholder Color Correct",confirm("Are the caret and placeholder (for Firefox) or just caret (for Chromium/WebKit, for consistency with textareas) red? (OK=Yes)"),"user-judged");
406
+
407
+
codeInputElement.style.removeProperty("color");
408
+
codeInputElement.style.caretColor="red";
409
+
awaitwaitAsync(200);// Wait for colours to update
410
+
testAssertion("Core","Overriden caret-color Caret/Placeholder Color Correct",confirm("Is the caret red and placeholder near-white? (OK=Yes)"),"user-judged");
0 commit comments