스테퍼
좌석 수, 수량, 글자 크기처럼 양쪽 버튼으로 가운데 숫자를 조절하는 컴포넌트입니다.
이 페이지의 내용
스테퍼는 좌석 수, 수량, 글자 크기처럼 직접 입력하는 일보다 조금씩 조절하는 일이 더 잦은 작은 숫자에 사용합니다. 네이티브 <input type="number"> 요소를 감싸는 입력 그룹으로, 오목한 영역 양쪽 끝에 버튼이 하나씩 있습니다. 그룹에는 stepper를, 필드에는 stepper-field를 추가합니다.
스테퍼
<div class="sheet flex items-center gap-lg p-md pl-lg"> <label class="text-sm fg-text-strong" for="seats">Seats</label> <div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer seats"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" id="seats" type="number" min="1" max="12" value="4"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More seats"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button> </div></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-react/native/16/soft/minus'import PlusIcon from '@master/icons-react/native/16/soft/plus'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="sheet flex items-center gap-lg p-md pl-lg"> <label className="text-sm fg-text-strong" htmlFor="seats">Seats</label> <div className="input-group stepper"> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Fewer seats"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" id="seats" type="number" min="1" max="12" defaultValue="4" /> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="More seats"> <PlusIcon className="icon" /> </button> </div> </div> )}<script> import { attach } from '@master/ui/behaviors' import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><div class="sheet flex items-center gap-lg p-md pl-lg" {@attach attach}> <label class="text-sm fg-text-strong" for="seats">Seats</label> <div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer seats"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" id="seats" type="number" min="1" max="12" value="4"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More seats"> <PlusIcon class="icon" /> </button> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import PlusIcon from '@master/icons-vue/native/16/soft/plus'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="sheet flex items-center gap-lg p-md pl-lg"> <label class="text-sm fg-text-strong" for="seats">Seats</label> <div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer seats"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" id="seats" type="number" min="1" max="12" value="4"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More seats"> <PlusIcon class="icon" /> </button> </div> </div></template>#필드의 기본 동작
숫자 입력 필드이므로 스크립트가 실행되기 전에도 플랫폼이 스테퍼 기능의 대부분을 제공합니다.
- ↑와 ↓는 값을
step씩 조절하며min과max에서 멈춥니다. - 보조 기술은 필드를 스핀 버튼으로 안내하며 현재 값과 범위의 한계값을 함께 알립니다.
- 휴대전화에서는 숫자 키패드가 표시됩니다.
- 입력한 값이 범위를 벗어나면
:user-invalid상태가 되고, 오목한 영역에 위험 상태의 윤곽선이 표시됩니다.
양쪽 버튼이 브라우저의 기본 스핀 버튼을 대신하므로 스타일시트에서 기본 버튼을 숨깁니다.
#동작
stepper 동작을 연결하면 양쪽 버튼으로 그 사이의 숫자를 조절할 수 있습니다. stepper 클래스가 있는 루트 요소와 서식이 적용된 숫자 및 드래그 조절에 사용할 옵션을 인수로 받으며, 호출하면 동작을 해제하는 함수를 반환합니다.
import { stepper } from '@master/ui/behaviors/stepper.js'const root = document.querySelector('.stepper')stepper(root)root.addEventListener('change', (event) => console.log(event.target.value))- 값 조절. 버튼은 방향키와 동일하게 필드의
stepDown()또는stepUp()메서드를 호출합니다. 따라서min,max,step은 필드에 한 번만 지정하면 됩니다. - 범위 제한. 값이 버튼이 조절하는 방향의 한계에 도달해 있는 동안 해당 버튼은
disabled상태가 됩니다. 비활성화된 버튼은 오목한 영역 안에서 평평하게 표시됩니다. 빈 필드는 어느 쪽 한계에도 도달하지 않은 상태입니다. 동작을 해제하면 버튼의disabled상태가 연결 전으로 돌아갑니다. - 길게 누르기. 버튼을 길게 누르면 잠시 후부터 값이 반복해서 바뀝니다. 누르기를 끝내거나 포인터가 버튼을 벗어나거나 포인터 입력이 취소되거나 값이 한계에 도달하면 멈춥니다.
- 조절 방향. 각 버튼의
value가 조절 방향을 정합니다. 음수이면 값이 줄어듭니다. 이를 지정하지 않으면 필드 앞의 버튼은 값을 줄이고 뒤의 버튼은 값을 늘립니다. - 이벤트. 버튼으로 숫자가 바뀌면 직접 입력할 때와 마찬가지로 필드가
input,change순서로 이벤트를 발생시킵니다. 값은 필드의value입니다.
버튼에는 tabindex="-1"을 지정합니다. Tab 키로 이동할 때는 필드에만 포커스가 가며, 필드의 방향키로 버튼과 같은 조작을 할 수 있습니다. 동작을 연결하지 않아도 필드는 플랫폼이 제공하는 기능을 그대로 수행하며, 버튼은 작동하지 않습니다.
#크기
스테퍼는 입력 그룹의 크기를 따릅니다. input-group-sm은 32px, input-group-lg는 44px이며 같은 크기의 버튼과 높이가 같습니다. 양쪽 버튼은 오목한 영역보다 각각 8px 낮고, 모서리의 곡선은 오목한 영역의 모서리와 중심을 공유합니다.
크기
<div class="input-group input-group-sm stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" value="2" aria-label="Small"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" value="16" aria-label="Medium"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><div class="input-group input-group-lg stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" value="128" aria-label="Large"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-react/native/16/soft/minus'import PlusIcon from '@master/icons-react/native/16/soft/plus'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <div className="input-group input-group-sm stepper"> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Decrease"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" defaultValue="2" aria-label="Small" /> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="Increase"> <PlusIcon className="icon" /> </button> </div> <div className="input-group stepper"> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Decrease"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" defaultValue="16" aria-label="Medium" /> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="Increase"> <PlusIcon className="icon" /> </button> </div> <div className="input-group input-group-lg stepper"> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Decrease"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" defaultValue="128" aria-label="Large" /> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="Increase"> <PlusIcon className="icon" /> </button> </div> </div> )}<script> import { attach } from '@master/ui/behaviors' import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><div {@attach attach}> <div class="input-group input-group-sm stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="2" aria-label="Small"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div> <div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="16" aria-label="Medium"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div> <div class="input-group input-group-lg stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="128" aria-label="Large"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import PlusIcon from '@master/icons-vue/native/16/soft/plus'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <div class="input-group input-group-sm stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="2" aria-label="Small"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div> <div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="16" aria-label="Medium"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div> <div class="input-group input-group-lg stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Decrease"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="128" aria-label="Large"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Increase"> <PlusIcon class="icon" /> </button> </div> </div></template>#너비
오목한 영역의 너비는 숫자 길이에 맞춰집니다. 브라우저에서 field-sizing: content를 지원하면 필드 너비는 입력한 자릿수에 맞춰 3자리 너비에서 9자리 너비 사이로 바뀝니다. 지원하지 않는 브라우저에서는 3자리 너비를 유지합니다. 다른 자릿수에 맞추려면 --stepper-min과 --stepper-max를 설정합니다. 또는 스테퍼에 너비를 지정하면 버튼은 양 끝에 붙고 숫자는 그 사이 가운데에 놓입니다.
단위는 필드 뒤에 input-group-addon으로 표시합니다. step을 크게 설정하면 한 번에 바뀌는 값의 폭도 커집니다.
단위와 조절 간격
<div class="input-group stepper" style="--stepper-min: 5ch"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Lower the budget"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" min="0" step="250" value="1250" aria-label="Monthly budget"> <span class="input-group-addon">USD</span> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Raise the budget"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><div class="input-group stepper w(280)"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer replicas"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" min="1" max="64" value="8" aria-label="Replicas"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More replicas"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-react/native/16/soft/minus'import PlusIcon from '@master/icons-react/native/16/soft/plus'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <div className="input-group stepper" style={{ '--stepper-min': '5ch' } as React.CSSProperties}> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Lower the budget"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" min="0" step="250" defaultValue="1250" aria-label="Monthly budget" /> <span className="input-group-addon">USD</span> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="Raise the budget"> <PlusIcon className="icon" /> </button> </div> <div className="input-group stepper w(280)"> <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label="Fewer replicas"> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" min="1" max="64" defaultValue="8" aria-label="Replicas" /> <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label="More replicas"> <PlusIcon className="icon" /> </button> </div> </div> )}<script> import { attach } from '@master/ui/behaviors' import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><div {@attach attach}> <div class="input-group stepper" style="--stepper-min: 5ch"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Lower the budget"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" min="0" step="250" value="1250" aria-label="Monthly budget"> <span class="input-group-addon">USD</span> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Raise the budget"> <PlusIcon class="icon" /> </button> </div> <div class="input-group stepper w(280)"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer replicas"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" min="1" max="64" value="8" aria-label="Replicas"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More replicas"> <PlusIcon class="icon" /> </button> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import PlusIcon from '@master/icons-vue/native/16/soft/plus'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <div class="input-group stepper" style="--stepper-min: 5ch"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Lower the budget"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" min="0" step="250" value="1250" aria-label="Monthly budget"> <span class="input-group-addon">USD</span> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Raise the budget"> <PlusIcon class="icon" /> </button> </div> <div class="input-group stepper w(280)"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer replicas"> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" min="1" max="64" value="8" aria-label="Replicas"> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More replicas"> <PlusIcon class="icon" /> </button> </div> </div></template>#서식이 적용된 숫자
가격, 백분율, 큰 수는 $1,250, 12%, 1,250,000처럼 서식을 적용해 표시하면 읽기 쉽습니다. 필드와 stepper-display를 stepper-value 안에 넣고, 동작에 Intl.NumberFormat의 옵션인 format을 전달하세요. 페이지의 로캘과 다른 로캘로 표시하려면 locale도 전달합니다.
stepper(root, { format: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }, locale: 'en-US' })서식이 적용된 숫자
<div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Lower the budget"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <span class="stepper-value"> <input class="input-group-field stepper-field" type="number" min="0" step="250" value="1250" aria-label="Monthly budget"> <span class="stepper-display" aria-hidden="true"></span> </span> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="Raise the budget"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><div class="input-group stepper"> <button type="button" class="btn btn-square" value="-1" tabindex="-1" aria-label="Fewer requests"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <span class="stepper-value"> <input class="input-group-field stepper-field" type="number" min="0" step="50000" value="1250000" aria-label="Requests a month"> <span class="stepper-display" aria-hidden="true"></span> </span> <button type="button" class="btn btn-square" value="1" tabindex="-1" aria-label="More requests"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div><script>addEventListener('DOMContentLoaded', function () {const [budget, requests] = document.querySelectorAll('.stepper')MasterUI.stepper(budget, { format: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }, locale: 'en-US' })MasterUI.stepper(requests, { locale: 'en-US' })})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>attach()는 옵션을 전달하지 않으므로 이 미리 보기에서는 attach()가 실행된 뒤 stepper를 직접 호출합니다. 같은 루트에 두 번째로 호출하면 첫 번째 호출을 대체합니다. MasterUI는 미리 보기가 불러오는 번들입니다. 프로젝트에서는 동작 섹션에 나온 대로 stepper를 가져오세요.
- 숫자는 필드에 그대로 둡니다. 필드에 포커스가 없는 동안에는 표시 요소가 필드 자리에 놓이고, 필드 자체의 숫자는 투명하게 처리됩니다. 필드에 포커스를 두면 표시 요소가 비켜나므로, 사용자는
$1,250이 아니라1250을 편집합니다. 방향키,min,max,step, 유효성 검사, 폼이 전송하는 값은 이전과 같이 숫자 입력 필드가 처리합니다. - 읽어 주는 텍스트. 버튼, 키 입력, 직접 입력, 외부에서 설정한 값 등으로 값이 바뀌면 동작이 서식을 적용한 숫자를 표시 요소와 필드의
aria-valuetext에 기록합니다. 따라서 스크린 리더도 "$1,250"으로 읽습니다. 표시 요소에는aria-hidden="true"가 지정되어 있습니다. - 서식이 없을 때.
stepper-display가 있고format이 없는 스테퍼는 로캘에 따라 자릿수를 구분합니다.Intl.NumberFormat으로 구현할 수 없는 표시 형식이 필요하면format에 숫자를 받는 함수를 지정할 수도 있습니다. - 너비. 숫자 영역의 너비는 필드와 표시 요소 중 더 넓은 쪽에 맞춰지며,
--stepper-min과--stepper-max사이로 제한됩니다. 따라서 필드에 포커스를 두어도 버튼이 움직이지 않습니다. - 스크립트가 없으면 표시 요소는 비어 있고, 필드는 평소대로 숫자를 표시합니다.
#드래그로 조절하기
디자인 도구에서는 숫자의 레이블을 드래그해 값을 바꾸는 경우가 많습니다. 페이지 어디에 있든 필드의 <label>이나 오목한 영역 안의 손잡이에 stepper-scrub 클래스를 지정하세요. 옆으로 드래그하면 4px마다 한 단계씩 숫자가 바뀌며, 줄의 끝 방향으로 드래그하면 값이 커집니다. Shift 키를 누른 채로 드래그하면 한 번에 열 단계씩 바뀝니다.
드래그로 조절하기
<div class="flex items-center gap-md"> <label class="stepper-scrub text-sm fg-text-strong" for="opacity">Opacity</label> <div class="input-group input-group-sm stepper"> <input class="input-group-field stepper-field" id="opacity" type="number" min="0" max="100" step="1" value="64"> <span class="input-group-addon">%</span> </div></div><div class="input-group input-group-sm stepper" style="--stepper-min: 4ch"> <span class="input-group-addon stepper-scrub" aria-hidden="true">W</span> <input class="input-group-field stepper-field" type="number" min="1" max="4096" value="320" aria-label="Width"> <span class="input-group-addon">px</span></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <div className="flex items-center gap-md"> <label className="stepper-scrub text-sm fg-text-strong" htmlFor="opacity">Opacity</label> <div className="input-group input-group-sm stepper"> <input className="input-group-field stepper-field" id="opacity" type="number" min="0" max="100" step="1" defaultValue="64" /> <span className="input-group-addon">%</span> </div> </div> <div className="input-group input-group-sm stepper" style={{ '--stepper-min': '4ch' } as React.CSSProperties}> <span className="input-group-addon stepper-scrub" aria-hidden="true">W</span> <input className="input-group-field stepper-field" type="number" min="1" max="4096" defaultValue="320" aria-label="Width" /> <span className="input-group-addon">px</span> </div> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div {@attach attach}> <div class="flex items-center gap-md"> <label class="stepper-scrub text-sm fg-text-strong" for="opacity">Opacity</label> <div class="input-group input-group-sm stepper"> <input class="input-group-field stepper-field" id="opacity" type="number" min="0" max="100" step="1" value="64"> <span class="input-group-addon">%</span> </div> </div> <div class="input-group input-group-sm stepper" style="--stepper-min: 4ch"> <span class="input-group-addon stepper-scrub" aria-hidden="true">W</span> <input class="input-group-field stepper-field" type="number" min="1" max="4096" value="320" aria-label="Width"> <span class="input-group-addon">px</span> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <div class="flex items-center gap-md"> <label class="stepper-scrub text-sm fg-text-strong" for="opacity">Opacity</label> <div class="input-group input-group-sm stepper"> <input class="input-group-field stepper-field" id="opacity" type="number" min="0" max="100" step="1" value="64"> <span class="input-group-addon">%</span> </div> </div> <div class="input-group input-group-sm stepper" style="--stepper-min: 4ch"> <span class="input-group-addon stepper-scrub" aria-hidden="true">W</span> <input class="input-group-field stepper-field" type="number" min="1" max="4096" value="320" aria-label="Width"> <span class="input-group-addon">px</span> </div> </div></template>- 누르기가 아닌 드래그. 포인터가 3px 이상 움직여야 드래그가 시작되므로, 레이블을 누르기만 하면 여전히 필드에 포커스가 놓입니다. 드래그가 끝날 때 발생하는 클릭은 무시됩니다.
- 포인터 잠금. 마우스를 사용할 때는 브라우저가 지원하면 드래그하는 동안 포인터를 잠급니다. 따라서 길게 드래그해도 화면 가장자리에 걸리지 않으며, 드래그가 끝나면 포인터가 원래 위치로 돌아옵니다. 펜이나 손가락은 대신 손잡이가 포인터를 캡처하며, 터치 화면에서 세로로 스와이프하면 여전히 페이지가 스크롤됩니다.
- 이벤트. 필드는 단계마다
input을 발생시키고, 드래그가 끝나면change를 한 번 발생시킵니다. - 방향. 오른쪽에서 왼쪽으로 쓰는 페이지에서는 줄의 시작 방향, 즉 왼쪽으로 드래그하면 값이 커집니다.
- 드래그 조절은 포인터 사용자를 위한 편의 기능입니다. 키보드, 버튼, 직접 입력으로 같은 작업을 모두 할 수 있으므로 별도의 키가 필요 없으며, 손잡이는 Tab 키의 포커스 이동 순서에서 제외됩니다.
#비활성화
필드와 양쪽 버튼을 모두 비활성화하세요. 오목한 영역은 제자리를 유지하고 숫자에는 비활성화 상태의 글자색이 적용됩니다. 필드가 비활성 상태이거나 읽기 전용이면 버튼이나 드래그로 값을 조절할 수 없습니다. 이 미리보기는 스크립트 없이 마크업만 사용합니다.
비활성화
<div class="input-group stepper"> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Decrease" disabled> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg> </button> <input class="input-group-field stepper-field" type="number" value="3" aria-label="Seats included in your plan" disabled> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Increase" disabled> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button></div>import MinusIcon from '@master/icons-react/native/16/soft/minus'import PlusIcon from '@master/icons-react/native/16/soft/plus'<div className="input-group stepper"> <button type="button" className="btn btn-square" tabIndex={-1} aria-label="Decrease" disabled> <MinusIcon className="icon" /> </button> <input className="input-group-field stepper-field" type="number" defaultValue="3" aria-label="Seats included in your plan" disabled /> <button type="button" className="btn btn-square" tabIndex={-1} aria-label="Increase" disabled> <PlusIcon className="icon" /> </button></div><script> import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><div class="input-group stepper"> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Decrease" disabled> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="3" aria-label="Seats included in your plan" disabled> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Increase" disabled> <PlusIcon class="icon" /> </button></div><script setup>import MinusIcon from '@master/icons-vue/native/16/soft/minus'import PlusIcon from '@master/icons-vue/native/16/soft/plus'</script><template> <div class="input-group stepper"> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Decrease" disabled> <MinusIcon class="icon" /> </button> <input class="input-group-field stepper-field" type="number" value="3" aria-label="Seats included in your plan" disabled> <button type="button" class="btn btn-square" tabindex="-1" aria-label="Increase" disabled> <PlusIcon class="icon" /> </button> </div></template>#다른 컴포넌트의 사용 기준
- 포트 번호나 가격처럼 한 번 입력하고 거의 조절하지 않는 숫자에는
type="number"를 지정한 기본 입력 컴포넌트를 사용합니다. - 범위가 넓고 정확한 숫자보다 범위 내에서 대략 어느 지점인지가 중요하다면 슬라이더를 사용하세요.
- 이름이 붙은 몇 가지 수량 중 하나를 선택할 때는 세그먼트 컨트롤을 사용하세요.
#키보드
숫자 입력 필드의 기본 키보드 조작을 그대로 사용하며, 동작을 연결해도 추가되는 키는 없습니다. Shift 키는 드래그 조절에만 영향을 줍니다.
| 키 | 동작 |
|---|---|
| ArrowUp, ArrowDown | 숫자 입력 필드처럼 step 단위로 값을 조절하며 min과 max에서 멈춥니다. |
| Shift (while scrubbing) | 드래그가 한 단계 움직일 때마다 10단계씩 바꿉니다. |
#접근성
<label>, 필드 또는aria-label로 입력 필드에 레이블을 지정하세요. 각 버튼에는 어떤 값을 바꾸는지 드러나는 이름이 필요합니다. 예를 들어 ‘더하기’보다 ‘좌석 수 늘리기’가 적합합니다.min,max,step은 필드에 지정합니다. 키보드 조작, 버튼 동작, 보조 기술이 모두 이 값을 참조합니다.- 버튼은 Tab 키의 포커스 이동 순서에서 제외됩니다. 키보드 사용자는 필드에서 방향키로 값을 조절합니다. 포인터로 누르는 영역은 30px이며, 손가락으로 누를 때는 같은 30px 버튼 둘레로 44px의 조작 영역이 생깁니다.
- 서식이 적용된 숫자는 필드의
aria-valuetext로 전달되며, 이를 표시하는 요소는 보조 기술에서 숨겨집니다. 오목한 영역 안의 드래그 손잡이도 키보드로 할 수 있는 조작을 반복할 뿐이므로 숨겨집니다.
#React, Svelte, Vue
stepper 컴포넌트는 동작을 연결하고 숫자 값을 주고받습니다. 서식이 적용된 숫자를 표시하려면 format과 필요한 경우 locale을 전달하세요. 컴포넌트는 첫 숫자를 이미 기록한 상태로 stepper-value와 표시 요소를 렌더링하므로, 서버가 보내는 HTML에도 서식이 적용된 숫자가 표시됩니다. 필드의 레이블에 stepper-scrub 클래스를 지정하면 프레임워크 없이 사용할 때와 마찬가지로 드래그해 값을 조절할 수 있습니다. npx master-ui add stepper로 프로젝트에 복사하세요. 컴포넌트의 구성과 사용법은 React, Svelte, Vue 문서에서 확인할 수 있습니다.
#클래스
| 클래스 | 설명 |
|---|---|
stepper | input-group에 적용합니다. 숫자 너비에 맞춘 오목한 영역의 양 끝에 버튼을 하나씩 배치합니다. 한계값에 도달해 비활성화된 버튼은 오목한 영역 안에서 평평하게 표시됩니다. |
stepper-field | 그룹에서 네이티브 숫자 입력 요소인 input-group-field에 적용합니다. 고정폭 숫자를 가운데 정렬하고 값 조절 버튼을 숨깁니다. |
stepper-value | 필드와 stepper-display를 감싸는 요소로, 둘 중 더 넓은 쪽의 너비를 가진 셀 하나를 이룹니다. 필드에 포커스가 없고 표시 요소에 숫자가 있는 동안에는 필드 자체의 숫자가 투명해집니다. |
stepper-display | 필드 뒤의 stepper-value 안에 aria-hidden="true"를 지정해 둡니다. Intl.NumberFormat이 형식을 지정한 숫자를 필드에 포커스가 없는 동안 필드 자리에 표시합니다. 동작이 기록합니다. |
stepper-scrub | 오목한 영역 안의 손잡이 또는 페이지 어디에든 있는 필드의 레이블로, 옆으로 끌면 숫자가 단계별로 바뀝니다. ew-resize 커서가 표시되고 텍스트는 선택되지 않습니다. |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--stepper-min | 3ch | 숫자 입력 필드의 최소 너비 |
--stepper-max | 9ch | field-sizing으로 늘어날 수 있는 최대 너비 |
#관련 항목
- 입력 필드표면을 파낸 듯한 텍스트 입력 필드와 레이블, 힌트, 오류, 입력 그룹.
- 슬라이더얇은 오목한 영역에 진주빛 손잡이를 배치한 네이티브 범위 입력 요소입니다.
- 버튼표면 위로 살짝 돌출되어 있으며, 포인터를 올리면 떠오르고 누르면 가라앉는 버튼입니다.