Skip to content

Commit 17a95fa

Browse files
committed
Add mobile keyboard viewport resize handling
Resize terminal when mobile keyboard shows/hides using visualViewport API.
1 parent 09de762 commit 17a95fa

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

demo/bin/demo.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,33 @@ const HTML_TEMPLATE = `<!doctype html>
286286
window.addEventListener('resize', () => {
287287
fitAddon.fit();
288288
});
289+
290+
// Handle mobile keyboard showing/hiding using visualViewport API
291+
if (window.visualViewport) {
292+
const terminalContent = document.querySelector('.terminal-content');
293+
const terminalWindow = document.querySelector('.terminal-window');
294+
const originalHeight = terminalContent.style.height;
295+
const body = document.body;
296+
297+
window.visualViewport.addEventListener('resize', () => {
298+
const keyboardHeight = window.innerHeight - window.visualViewport.height;
299+
if (keyboardHeight > 100) {
300+
body.style.padding = '0';
301+
body.style.alignItems = 'flex-start';
302+
terminalWindow.style.borderRadius = '0';
303+
terminalWindow.style.maxWidth = '100%';
304+
terminalContent.style.height = (window.visualViewport.height - 60) + 'px';
305+
window.scrollTo(0, 0);
306+
} else {
307+
body.style.padding = '40px 20px';
308+
body.style.alignItems = 'center';
309+
terminalWindow.style.borderRadius = '12px';
310+
terminalWindow.style.maxWidth = '1000px';
311+
terminalContent.style.height = originalHeight || '600px';
312+
}
313+
fitAddon.fit();
314+
});
315+
}
289316
</script>
290317
</body>
291318
</html>`;

0 commit comments

Comments
 (0)