Skip to content

Commit e115d35

Browse files
committed
Make code-input sync size on focus state change
(so keyboard navigating to previously-mouse-focused no scroll element keeps no scroll)
1 parent 1b1a341 commit e115d35

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

code-input.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(tex
241241
code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(textarea:not([data-code-input-fallback]):focus):not(.code-input_mouse-focused):not(.code-input_pre-element-styled) pre code,
242242
code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(textarea:not([data-code-input-fallback]):focus):not(.code-input_mouse-focused).code-input_pre-element-styled pre {
243243
padding-top: calc(var(--padding, 16px) + 3em)!important;
244-
}
245-
code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(textarea:not([data-code-input-fallback]):focus):not(.code-input_mouse-focused) textarea, code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(textarea:not([data-code-input-fallback]):focus):not(.code-input_mouse-focused):not(.code-input_pre-element-styled) pre code, code-input:not(:has(.code-input_keyboard-navigation-instructions:empty)):has(textarea:not([data-code-input-fallback]):focus):not(.code-input_mouse-focused).code-input_pre-element-styled pre {
246244
min-height: calc(100% - var(--padding, 16px) * 2 - 3em);
247245
}
248246

code-input.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,23 @@ var codeInput = {
671671
// Accessibility - detect when mouse focus to remove focus outline + keyboard navigation guidance that could irritate users.
672672
this.addEventListener("mousedown", () => {
673673
this.classList.add("code-input_mouse-focused");
674+
// Wait for CSS to update padding
675+
window.setTimeout(() => {
676+
this.syncSize();
677+
}, 0);
674678
});
675679
textarea.addEventListener("blur", () => {
676680
this.classList.remove("code-input_mouse-focused");
681+
// Wait for CSS to update padding
682+
window.setTimeout(() => {
683+
this.syncSize();
684+
}, 0);
685+
});
686+
textarea.addEventListener("focus", () => {
687+
// Wait for CSS to update padding
688+
window.setTimeout(() => {
689+
this.syncSize();
690+
}, 0);
677691
});
678692

679693
this.innerHTML = ""; // Clear Content

0 commit comments

Comments
 (0)