File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,23 @@ export default class HTMLCodeBlockElement extends HTMLElement {
6969 } ;
7070 } ) ( ) ;
7171
72+ /**
73+ * True when rendered at least once.
74+ * The purpose of this flag is to available the operation the following usage.
75+ *
76+ * Specifically, this is the case where an element is rendered
77+ * on the screen without ever using the value property.
78+ *
79+ * ```js
80+ * const cb = document.createElement('code-block');
81+ *
82+ * cb.language = 'json';
83+ * cb.textContent = '{"a": 100}';
84+ * document.body.prepend(cb);
85+ * ```
86+ */
87+ #rendered = false ;
88+
7289 /** Pure DOM content */
7390 #a11yName: HTMLElement ;
7491
@@ -275,6 +292,14 @@ export default class HTMLCodeBlockElement extends HTMLElement {
275292 }
276293
277294 connectedCallback ( ) {
295+ if (
296+ this . #rendered === false &&
297+ this . #value === ''
298+ ) {
299+ this . #value = this . textContent || '' ;
300+ }
301+
302+ this . #rendered = true ;
278303 this . #render( ) ;
279304 }
280305
You can’t perform that action at this time.
0 commit comments