04입력창 확대 잠금 — 포커스를 줘도 화면이 확대되지 않는 입력 필드
입력 필드를 눌러 포커스를 줘도 글자 크기 기준값이 문턱을 넘겨 화면 전체가 확대되지 않고 그대로 유지됩니다.
쓰임모바일 검색창, 로그인 폼 입력 필드
LOCK_FONT_PXfont-sizezoomScaleFor

<main class="stage">
<div class="wrap is-demo" id="wrap">
<div class="row">
<label class="field">
<span class="fieldLabel">작은 글자판</span>
<input class="input is-small" id="inputSmall" type="text" value="검색어">
</label>
<label class="field">
<span class="fieldLabel">잠금 글자판</span>
<input class="input is-lock" id="inputLock" type="text" value="검색어">
</label>
</div>
<div class="foot">
<span class="modeLabel" id="modeLabel">확대 잠금 켜짐</span>
<button class="simToggle" id="simToggle" type="button" aria-pressed="false">폴백 흉내내기</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹은 index.html 의 zoomScaleFor() 에 있다 — 실제 computed font-size 에서 배율을 구하고
// getBoundingClientRect() 중심으로 transform-origin 을 놓는다. 여기는 두 입력판의 바탕 크기와
// 전환 곡선만 맡는다.
@include stage($stage-orange);
.wrap {
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-4;
}
.row {
display: flex;
gap: $sp-5;
}
.field {
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-2;
}
.fieldLabel {
color: $subject-ink;
font-size: 10px;
font-weight: 700;
}
.input {
width: 96px;
padding: $sp-2 $sp-3;
border: none;
border-radius: $r-control;
background: $subject-cream;
color: $subject-ink;
text-align: center;
transition: transform $dur-base $ease-spring;
transform: scale(1);
&.is-small { font-size: 12px; }
&.is-lock { font-size: 16px; }
&:focus-visible {
outline: 2px solid $subject-blue-light;
outline-offset: 2px;
}
}
// 시뮬레이션: 표준 잠금 기법을 강제로 무시하고 잠금판도 확대되게 한다(실제 UA 감지가 아니라
// 값을 억지로 12px 로 되돌리는 CSS 오버라이드) — 폴백 없는 환경을 그대로 보여준다
.force-fallback .input.is-lock { font-size: 12px; }
.foot {
display: flex;
align-items: center;
gap: $sp-2;
}
.modeLabel {
color: $subject-ink;
font-size: 10px;
font-weight: 700;
background: rgba($stage-paper, .6);
padding: $sp-1 $sp-2;
border-radius: $r-xs;
}
.simToggle {
appearance: none;
border: none;
border-radius: $r-pill;
background: rgba($subject-ink, .82);
color: $subject-cream;
padding: $sp-1 $sp-3;
font-size: 10px;
font-weight: 600;
cursor: pointer;
transition: transform $dur-instant $ease-out;
&:active { transform: scale(.96); }
&[aria-pressed="true"] { background: $subject-orange-deep; }
&:focus-visible { outline: 2px solid $subject-blue-light; outline-offset: 2px; }
}
@media (max-width: 340px) {
.row { gap: $sp-3; }
.input { width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
.input { transition: none; }
.simToggle { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.wrap {
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.row {
display: flex;
gap: 20px;
}
.field {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.fieldLabel {
color: #17141a;
font-size: 10px;
font-weight: 700;
}
.input {
width: 96px;
padding: 8px 12px;
border: none;
border-radius: 12px;
background: #fff7e6;
color: #17141a;
text-align: center;
transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
transform: scale(1);
}
.input.is-small {
font-size: 12px;
}
.input.is-lock {
font-size: 16px;
}
.input:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
.force-fallback .input.is-lock {
font-size: 12px;
}
.foot {
display: flex;
align-items: center;
gap: 8px;
}
.modeLabel {
color: #17141a;
font-size: 10px;
font-weight: 700;
background: rgba(255, 255, 255, 0.6);
padding: 4px 8px;
border-radius: 4px;
}
.simToggle {
appearance: none;
border: none;
border-radius: 999px;
background: rgba(23, 20, 26, 0.82);
color: #fff7e6;
padding: 4px 12px;
font-size: 10px;
font-weight: 600;
cursor: pointer;
transition: transform 140ms ease-out;
}
.simToggle:active {
transform: scale(0.96);
}
.simToggle[aria-pressed=true] {
background: #c93000;
}
.simToggle:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
@media (max-width: 340px) {
.row {
gap: 12px;
}
.input {
width: 80px;
}
}
@media (prefers-reduced-motion: reduce) {
.input {
transition: none;
}
.simToggle {
transition: none;
}
}(function () {
var LOCK_FONT_PX = 16; // 이 값 이상이면 초점 확대가 걸리지 않는다 — 잠금판의 목표 크기
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var wrap = document.getElementById('wrap');
var inputSmall = document.getElementById('inputSmall');
var inputLock = document.getElementById('inputLock');
var simToggle = document.getElementById('simToggle');
var modeLabel = document.getElementById('modeLabel');
var isDemo = true;
function human() { if (isDemo) { wrap.classList.remove('is-demo'); isDemo = false; } }
// 실제 요소 크기에서 확대 배율을 구한다 — 하드코딩 배율이 아니라 현재 폰트 크기 기준
function zoomScaleFor(el) {
var css = getComputedStyle(el);
var current = parseFloat(css.fontSize) || LOCK_FONT_PX;
return Math.max(1, LOCK_FONT_PX / current);
}
function applyFocusZoom(el, on) {
if (on) {
var rect = el.getBoundingClientRect();
var originX = rect.width / 2;
var originY = rect.height / 2;
el.style.transformOrigin = originX + 'px ' + originY + 'px';
el.style.transform = 'scale(' + zoomScaleFor(el) + ')';
} else {
el.style.transform = 'scale(1)';
}
}
inputSmall.addEventListener('focus', function () { human(); applyFocusZoom(inputSmall, true); });
inputSmall.addEventListener('blur', function () { applyFocusZoom(inputSmall, false); });
// 잠금판: 실제 font-size 가 이미 LOCK_FONT_PX 이므로 zoomScaleFor 가 1을 반환 — 확대가 걸리지 않는다
inputLock.addEventListener('focus', function () { human(); applyFocusZoom(inputLock, true); });
inputLock.addEventListener('blur', function () { applyFocusZoom(inputLock, false); });
var simOn = false;
function setSim(on) {
simOn = on;
wrap.classList.toggle('force-fallback', on);
simToggle.setAttribute('aria-pressed', String(on));
modeLabel.textContent = on ? '확대 잠금 꺼짐' : '확대 잠금 켜짐';
}
simToggle.addEventListener('click', function () { human(); setSim(!simOn); });
var last = 0;
var STEP_MS = 680;
var phase = 0;
function loop(ts) {
if (!last) last = ts;
if (isDemo && !reduce && ts - last >= STEP_MS) {
last = ts;
phase = (phase + 1) % 4;
if (phase === 1) { applyFocusZoom(inputSmall, true); applyFocusZoom(inputLock, true); }
else if (phase === 3) { applyFocusZoom(inputSmall, false); applyFocusZoom(inputLock, false); }
else if (phase === 0) { setSim(!simOn); }
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
})();// InputFocusZoomLock — vanilla 판(run/375/demo/04-compat-input-focus-zoom-lock/index.html) 의 React 포트.
// 작은 글자판은 초점을 얻으면 확대되고, 잠금 글자판은 font-size 16px 기법 때문에 배율이 1로 고정된다.
import { useEffect, useRef } from "react";
import styles from "./InputFocusZoomLock.module.scss";
type Box<T> = { current: T };
const LOCK_FONT_PX = 16; // 이 값 이상이면 초점 확대가 걸리지 않는다 — 잠금판의 목표 크기
const STEP_MS = 680;
export default function InputFocusZoomLock() {
const rootRef = useRef(null) as unknown as Box<HTMLDivElement>;
const inputSmallRef = useRef(null) as unknown as Box<HTMLInputElement>;
const inputLockRef = useRef(null) as unknown as Box<HTMLInputElement>;
const simToggleRef = useRef(null) as unknown as Box<HTMLButtonElement>;
const modeLabelRef = useRef(null) as unknown as Box<HTMLSpanElement>;
const rafRef = useRef(0) as unknown as Box<number>;
useEffect(() => {
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const wrap = rootRef.current;
const inputSmall = inputSmallRef.current;
const inputLock = inputLockRef.current;
const simToggle = simToggleRef.current;
const modeLabel = modeLabelRef.current;
if (!wrap || !inputSmall || !inputLock || !simToggle || !modeLabel) return;
let isDemo = true;
function human() { if (isDemo) { wrap!.classList.remove(styles.isDemo); isDemo = false; } }
// 실제 요소 크기에서 확대 배율을 구한다 — 하드코딩 배율이 아니라 현재 폰트 크기 기준
function zoomScaleFor(el: HTMLInputElement) {
const css = window.getComputedStyle(el);
const current = parseFloat(css.fontSize) || LOCK_FONT_PX;
return Math.max(1, LOCK_FONT_PX / current);
}
function applyFocusZoom(el: HTMLInputElement, on: boolean) {
if (on) {
const rect = el.getBoundingClientRect();
const originX = rect.width / 2;
const originY = rect.height / 2;
el.style.transformOrigin = originX + "px " + originY + "px";
el.style.transform = "scale(" + zoomScaleFor(el) + ")";
} else {
el.style.transform = "scale(1)";
}
}
function onSmallFocus() { human(); applyFocusZoom(inputSmall!, true); }
function onSmallBlur() { applyFocusZoom(inputSmall!, false); }
inputSmall.addEventListener("focus", onSmallFocus);
inputSmall.addEventListener("blur", onSmallBlur);
// 잠금판: 실제 font-size 가 이미 LOCK_FONT_PX 이므로 zoomScaleFor 가 1을 반환 — 확대가 걸리지 않는다
function onLockFocus() { human(); applyFocusZoom(inputLock!, true); }
function onLockBlur() { applyFocusZoom(inputLock!, false); }
inputLock.addEventListener("focus", onLockFocus);
inputLock.addEventListener("blur", onLockBlur);
let simOn = false;
function setSim(on: boolean) {
simOn = on;
wrap!.classList.toggle(styles.forceFallback, on);
simToggle!.setAttribute("aria-pressed", String(on));
modeLabel!.textContent = on ? "확대 잠금 꺼짐" : "확대 잠금 켜짐";
}
function onSimClick() { human(); setSim(!simOn); }
simToggle.addEventListener("click", onSimClick);
let last = 0;
let phase = 0;
function loop(ts: number) {
if (!last) last = ts;
if (isDemo && !reduce && ts - last >= STEP_MS) {
last = ts;
phase = (phase + 1) % 4;
if (phase === 1) { applyFocusZoom(inputSmall!, true); applyFocusZoom(inputLock!, true); }
else if (phase === 3) { applyFocusZoom(inputSmall!, false); applyFocusZoom(inputLock!, false); }
else if (phase === 0) { setSim(!simOn); }
}
rafRef.current = requestAnimationFrame(loop);
}
rafRef.current = requestAnimationFrame(loop);
return () => {
inputSmall!.removeEventListener("focus", onSmallFocus);
inputSmall!.removeEventListener("blur", onSmallBlur);
inputLock!.removeEventListener("focus", onLockFocus);
inputLock!.removeEventListener("blur", onLockBlur);
simToggle!.removeEventListener("click", onSimClick);
cancelAnimationFrame(rafRef.current);
};
}, []);
return (
<main className={styles.stage}>
<div className={styles.wrap + " " + styles.isDemo} ref={rootRef}>
<div className={styles.row}>
<label className={styles.field}>
<span className={styles.fieldLabel}>작은 글자판</span>
<input className={styles.input + " " + styles.isSmall} ref={inputSmallRef} type="text" defaultValue="검색어" />
</label>
<label className={styles.field}>
<span className={styles.fieldLabel}>잠금 글자판</span>
<input className={styles.input + " " + styles.isLock} ref={inputLockRef} type="text" defaultValue="검색어" />
</label>
</div>
<div className={styles.foot}>
<span className={styles.modeLabel} ref={modeLabelRef}>확대 잠금 켜짐</span>
<button className={styles.simToggle} ref={simToggleRef} type="button" aria-pressed="false">폴백 흉내내기</button>
</div>
</div>
</main>
);
}04 입력창 확대 잠금 — 포커스를 줘도 화면이 확대되지 않는 입력 필드 — 측정 누적면적 5.458% · 움직인 프레임 8/23GODRICH 원작 · zip 에 SCSS·React 포함 · css 브라우저 호환 9종 — 실제로 쓰는 폴백 트릭 모음
이 데모가 속한 글
css 브라우저 호환 9종 — 실제로 쓰는 폴백 트릭 모음아홉 개의 css 브라우저 호환 트릭 중 하나는 주소창이 접히고 펼쳐질 때마다 전체 화면 높이 값이 다시 계산되고, 하나는 입력 필드에 포커스를 줘도 화면이 확대되지 않게 잠그고, 하나는 목록을 끝까지 당겨도 뒤 배 이 글의 데모 전부 보기


