Skip to content

Commit 836e1f6

Browse files
committed
Make dialog container be correct width no matter box sizing; Simplify CSS
1 parent df75757 commit 836e1f6

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

code-input.css

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ code-input {
4040
grid-template-rows: 100%;
4141
}
4242

43-
44-
code-input:not(.code-input_loaded) {
45-
padding: var(--padding, 16px)!important;
43+
code-input * {
44+
box-sizing: content-box; /* Make height, width work consistently no matter the box-sizing of ancestors; dialogs can be styled as wanted so are excluded. */
4645
}
4746

4847
code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
@@ -52,7 +51,6 @@ code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, co
5251
border: 0;
5352
min-width: calc(100% - var(--padding, 16px) * 2);
5453
min-height: calc(100% - var(--padding, 16px) * 2);
55-
box-sizing: content-box; /* Make height, width work consistently no matter the box-sizing of ancestors; dialogs can be styled as wanted so are excluded. */
5654
overflow: hidden;
5755
resize: none;
5856
grid-row: 1;
@@ -138,37 +136,6 @@ code-input:has(textarea:focus):not(.code-input_mouse-focused) {
138136
outline: 2px solid currentColor;
139137
}
140138

141-
/* Before registering give a hint about how to register. */
142-
code-input:not(.code-input_registered) {
143-
overflow: hidden;
144-
display: block;
145-
box-sizing: border-box; /* Include padding in width/height */
146-
}
147-
148-
code-input:not(.code-input_registered)::after {
149-
/* Display message to register */
150-
content: "No highlighting. JavaScript support is disabled or insufficient, or codeInput.registerTemplate has not been called.";
151-
display: block;
152-
position: absolute;
153-
bottom: 0;
154-
left: var(--padding, 16px);
155-
width: calc(100% - 2 * var(--padding, 16px));
156-
overflow-x: auto;
157-
158-
border-top: 1px solid currentColor;
159-
outline-top: 0;
160-
background-color: inherit;
161-
color: inherit;
162-
163-
margin: 0;
164-
padding: 0;
165-
height: 2em;
166-
}
167-
168-
code-input:not(.code-input_loaded) pre, code-input:not(.code-input_loaded) textarea:not([data-code-input-fallback]) {
169-
opacity: 0;
170-
}
171-
172139
/* Contains dialog boxes that might appear as the result of a plugin.
173140
Sticks to the top of the code-input element */
174141

@@ -190,9 +157,6 @@ code-input .code-input_dialog-container {
190157
/* Dialog boxes' text is based on text-direction */
191158
text-align: inherit;
192159
}
193-
code-input.code-input_pre-element-styled .code-input_dialog-container {
194-
width: calc(100% + 2 * var(--padding, 16px));
195-
}
196160

197161
[dir=rtl] code-input .code-input_dialog-container, code-input[dir=rtl] .code-input_dialog-container {
198162
left: unset;
@@ -216,12 +180,12 @@ code-input .code-input_dialog-container .code-input_keyboard-navigation-instruct
216180
padding-right: var(--padding, 16px);
217181
margin: 0;
218182
text-wrap: balance;
219-
overflow: hidden;
220-
text-overflow: ellipsis;
183+
overflow-x: hidden;
184+
overflow-y: auto;
221185

222186
width: 100%;
223187
box-sizing: border-box;
224-
max-height: 3em;
188+
height: 3em;
225189
}
226190

227191
code-input:not(:has(textarea:not([data-code-input-fallback]):focus)) .code-input_dialog-container .code-input_keyboard-navigation-instructions,
@@ -239,6 +203,40 @@ code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(tex
239203
min-height: calc(100% - var(--padding, 16px) * 2 - 3em);
240204
}
241205

206+
/* Pre-loaded appearance */
207+
208+
code-input:not(.code-input_loaded) {
209+
padding: var(--padding, 16px)!important;
210+
overflow: hidden;
211+
display: block;
212+
box-sizing: border-box; /* Include padding in width/height */
213+
}
214+
215+
code-input:not(.code-input_loaded)::after {
216+
/* Display message to register */
217+
content: "No highlighting. JavaScript support is disabled or insufficient, or codeInput.registerTemplate has not been called.";
218+
display: block;
219+
position: absolute;
220+
bottom: 0;
221+
left: var(--padding, 16px);
222+
width: calc(100% - 2 * var(--padding, 1.6px));
223+
overflow-x: auto;
224+
225+
border-top: 1px solid currentColor;
226+
outline-top: 0;
227+
background-color: inherit;
228+
color: inherit;
229+
230+
margin: 0;
231+
padding: 0;
232+
height: 2em;
233+
}
234+
235+
236+
code-input:not(.code-input_loaded) pre, code-input:not(.code-input_loaded) textarea:not([data-code-input-fallback]) {
237+
opacity: 0;
238+
}
239+
242240
/* No JavaScript fallback - styles to override all previous */
243241

244242
code-input:has(textarea[data-code-input-fallback]) {

plugins/prism-line-numbers.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ code-input.line-numbers textarea, code-input.line-numbers.code-input_pre-element
1414
code-input.line-numbers, .line-numbers code-input {
1515
grid-template-columns: calc(100% - max(0em, calc(3.8em - var(--padding, 16px))));
1616
}
17+
/* Despite the above, keep dialog container full width */
18+
code-input.line-numbers .code-input_dialog-container, .line-numbers code-input .code-input_dialog-container {
19+
width: calc(100% + max(0em, calc(3.8em - var(--padding, 16px))));
20+
}
21+
1722

1823
/* Override Prism styles so there's no display:inline, relatively-positioned code element which breaks offsetTop, used in FindAndReplace, in Firefox. */
1924
code-input pre[class*=language-].line-numbers>code {

tests/i18n.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646

4747
</head>
4848
<body>
49+
<style>
50+
* {
51+
box-sizing: border-box;
52+
}
53+
</style>
4954
<textarea dir="rtl" placeholder="textarea rtl"></textarea>
5055
<textarea dir="ltr" placeholder="textarea ltr"></textarea>
5156
<code-input dir="rtl" template="prism" language="markdown"><textarea data-code-input-fallback placeholder="prism rtl"></textarea></code-input>

0 commit comments

Comments
 (0)