Number Input
Import
<link rel="stylesheet" href="/guide/css/base/index.css" /> <link rel="stylesheet" href="/guide/css/components/number-input.css" />
Live
수량 선택에 사용하는 숫자 입력 컴포넌트입니다. − / + 버튼으로 값을 증가·감소하거나 직접 입력할 수 있습니다.
Small
Medium
Large
States
Default
Hover
Focus
Disabled
Sizes
Small — 32px
Medium — 40px (default)
Large — 48px
Specs
| 속성 | Small | Medium | Large |
|---|---|---|---|
| Height | 32px | 40px | 48px |
| Width | 160px (고정) | ||
| Button width | 40px | ||
| Border | 1px solid gray-200 | ||
| Border Radius | radius-md (8px) | ||
| Border — Focus | color-accent-main (red-600) | ||
| Button bg | gray-50 | ||
| Button bg — Hover | gray-200 | ||
| Font | Pretendard Regular 16px | ||
| Icon size | 12 × 2px (minus) / 12 × 12px (plus) | ||
Code
HTML
<!-- Medium (default) --> <div class="number-input"> <button class="number-input__btn number-input__btn--minus" type="button" aria-label="감소"> <svg width="12" height="2" viewBox="0 0 12 2" fill="none" aria-hidden="true"> <rect width="12" height="2" rx="1" fill="currentColor"/> </svg> </button> <input class="number-input__field" type="number" value="1" min="0" max="99" aria-label="수량" /> <button class="number-input__btn number-input__btn--plus" type="button" aria-label="증가"> <svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"> <rect x="0" y="5" width="12" height="2" rx="1" fill="currentColor"/> <rect x="5" y="0" width="2" height="12" rx="1" fill="currentColor"/> </svg> </button> </div> <!-- Small --> <div class="number-input number-input--sm">...</div> <!-- Large --> <div class="number-input number-input--lg">...</div> <!-- Disabled --> <div class="number-input"> <button class="number-input__btn" type="button" aria-label="감소" disabled>...</button> <input class="number-input__field" type="number" value="1" aria-label="수량" disabled /> <button class="number-input__btn" type="button" aria-label="증가" disabled>...</button> </div>
JavaScript
document.querySelectorAll('.number-input').forEach(function (wrap) {
var input = wrap.querySelector('.number-input__field');
if (!input) return;
wrap.querySelectorAll('.number-input__btn').forEach(function (btn) {
btn.addEventListener('click', function () {
var step = Number(input.step) || 1;
var min = input.min !== '' ? Number(input.min) : -Infinity;
var max = input.max !== '' ? Number(input.max) : Infinity;
var val = Number(input.value) || 0;
if (btn.classList.contains('number-input__btn--minus')) {
input.value = Math.max(min, val - step);
} else {
input.value = Math.min(max, val + step);
}
input.dispatchEvent(new Event('change', { bubbles: true }));
});
});
});
Classes
| 클래스 | 태그 | 설명 |
|---|---|---|
.number-input |
루트 | 래퍼 — border, flex, 160px × 40px |
.number-input--sm |
수정자 | 높이 32px |
.number-input--lg |
수정자 | 높이 48px |
.number-input__btn |
요소 | − / + 버튼 (40px, gray-50 배경) |
.number-input__btn--minus |
수정자 | 감소 버튼 식별자 (JS 참조용) |
.number-input__btn--plus |
수정자 | 증가 버튼 식별자 (JS 참조용) |
.number-input__field |
요소 | 숫자 input (flex-1, 중앙 정렬, 스피너 제거) |