탐색

v2.1.0
폼

스테퍼

좌석 수, 수량, 글자 크기처럼 양쪽 버튼으로 가운데 숫자를 조절하는 컴포넌트입니다.

이 페이지의 내용

스테퍼는 좌석 수, 수량, 글자 크기처럼 직접 입력하는 일보다 조금씩 조절하는 일이 더 잦은 작은 숫자에 사용합니다. 네이티브 <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>
버튼을 한 번 누르거나 길게 누르세요. 필드에 숫자를 직접 입력하거나 방향키를 사용할 수도 있습니다. 값이 1 또는 12에 도달하면 해당 방향의 버튼이 평평해집니다.

#필드의 기본 동작

숫자 입력 필드이므로 스크립트가 실행되기 전에도 플랫폼이 스테퍼 기능의 대부분을 제공합니다.

  • ↑와 ↓는 값을 step씩 조절하며 min과 max에서 멈춥니다.
  • 보조 기술은 필드를 스핀 버튼으로 안내하며 현재 값과 범위의 한계값을 함께 알립니다.
  • 휴대전화에서는 숫자 키패드가 표시됩니다.
  • 입력한 값이 범위를 벗어나면 :user-invalid 상태가 되고, 오목한 영역에 위험 상태의 윤곽선이 표시됩니다.

양쪽 버튼이 브라우저의 기본 스핀 버튼을 대신하므로 스타일시트에서 기본 버튼을 숨깁니다.

#동작

stepper 동작을 연결하면 양쪽 버튼으로 그 사이의 숫자를 조절할 수 있습니다. stepper 클래스가 있는 루트 요소와 서식이 적용된 숫자 및 드래그 조절에 사용할 옵션을 인수로 받으며, 호출하면 동작을 해제하는 함수를 반환합니다.

app.js
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도 전달합니다.

app.js
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>
Opacity 레이블이나 두 번째 필드 앞의 W를 옆으로 드래그해 보세요. 드래그하지 않고 누르기만 하면 필드에 포커스가 놓입니다.
  • 누르기가 아닌 드래그. 포인터가 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 문서에서 확인할 수 있습니다.

ui/stepper.tsx
'use client'import { useState, type ComponentProps } from 'react'import { stepper } from '@master/ui/behaviors/stepper.js'import { useBehavior } from './use-behavior'export interface StepperProps extends Omit<ComponentProps<'input'>, 'value' | 'defaultValue' | 'type'> {  /** The number; null while the field is empty. */  value?: number | null  defaultValue?: number | null  onValueChange?: (value: number | null) => void  /** The names of the two buttons, which show only an icon. */  decrementLabel: string  incrementLabel: string  /**   * Write the figure with `Intl.NumberFormat` while the field is not focused: a unit, a currency, grouping.   * The field keeps the plain number. Read when the stepper attaches, as `locale` is.   */  format?: Intl.NumberFormatOptions  /** The locale the figure is written in. The page's by default. */  locale?: string}/** * A number between two buttons. Name the field with `aria-label`, or give it an `id` a label points at; * `min`, `max`, `step` and every other prop of an input go to the field; `disabled` disables the buttons too. A * label with the `stepper-scrub` class steps the number as it is dragged sideways. */export function Stepper({ value, defaultValue, onValueChange, decrementLabel, incrementLabel, format, locale, disabled, className, ...field }: StepperProps) {  const ref = useBehavior(stepper, { format, locale }, { value, defaultValue, onValueChange })  const [first] = useState(value ?? defaultValue)  // The first figure is drawn into the first render, so the HTML a server sends shows it.  const [written] = useState(() => (format && typeof first === 'number' ? new Intl.NumberFormat(locale, format).format(first) : undefined))  const input = <input className="input-group-field stepper-field" type="number" defaultValue={first ?? undefined} aria-valuetext={written} disabled={disabled} {...field} />  return (    <div className={className ? `input-group stepper ${className}` : 'input-group stepper'} ref={ref}>      <button type="button" className="btn btn-square" value="-1" tabIndex={-1} aria-label={decrementLabel} disabled={disabled}>        <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3 8L13 8" /></svg>      </button>      {format        ? (            <span className="stepper-value">              {input}              <span className="stepper-display" aria-hidden="true">{written}</span>            </span>          )        : input}      <button type="button" className="btn btn-square" value="1" tabIndex={-1} aria-label={incrementLabel} disabled={disabled}>        <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3 8L13 8" /><path d="M8 3L8 13" /></svg>      </button>    </div>  )}
ui/Stepper.svelte
<script lang="ts" module>  import type { HTMLInputAttributes } from 'svelte/elements'  export interface StepperProps extends Omit<HTMLInputAttributes, 'value' | 'type' | 'children'> {    /** The number; null while the field is empty. Bind it, or leave it out. */    value?: number | null    onValueChange?: (value: number | null) => void    /** The names of the two buttons, which show only an icon. */    decrementLabel: string    incrementLabel: string    /**     * Write the figure with `Intl.NumberFormat` while the field is not focused: a unit, a currency, grouping.     * The field keeps the plain number. Read when the stepper attaches, as `locale` is.     */    format?: Intl.NumberFormatOptions    /** The locale the figure is written in. The page's by default. */    locale?: string  }</script><script lang="ts">  import { untrack } from 'svelte'  import { stepper } from '@master/ui/behaviors/stepper.js'  import { behavior } from './behavior.svelte.js'  let { value = $bindable(), onValueChange, decrementLabel, incrementLabel, format, locale, disabled, class: className, ...field }: StepperProps = $props()  const first = untrack(() => value)  // The first figure is drawn into the first render, so the HTML a server sends shows it.  const written = untrack(() => (format && typeof first === 'number' ? new Intl.NumberFormat(locale, format).format(first) : undefined))  const attach = behavior(stepper, () => ({ format, locale }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })</script><!--  @component  A number between two buttons. Name the field with `aria-label`, or give it an `id` a label points at;  `min`, `max`, `step` and every other prop of an input go to the field; `disabled` disables the buttons too. A  label with the `stepper-scrub` class steps the number as it is dragged sideways.--><div class={['input-group', 'stepper', className]} {@attach attach}>  <button type="button" class="btn btn-square" value="-1" tabindex={-1} aria-label={decrementLabel} {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>  {#if format}    <span class="stepper-value">      <input class="input-group-field stepper-field" type="number" value={first ?? undefined} aria-valuetext={written} {disabled} {...field} />      <span class="stepper-display" aria-hidden="true">{written}</span>    </span>  {:else}    <input class="input-group-field stepper-field" type="number" value={first ?? undefined} {disabled} {...field} />  {/if}  <button type="button" class="btn btn-square" value="1" tabindex={-1} aria-label={incrementLabel} {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>
ui/Stepper.vue
<script setup lang="ts">import { useAttrs, useTemplateRef } from 'vue'import { stepper } from '@master/ui/behaviors/stepper.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const props = defineProps<{  /** The names of the two buttons, which show only an icon. */  decrementLabel: string  incrementLabel: string  /**   * Write the figure with `Intl.NumberFormat` while the field is not focused: a unit, a currency, grouping.   * The field keeps the plain number. Read when the stepper attaches, as `locale` is.   */  format?: Intl.NumberFormatOptions  /** The locale the figure is written in. The page's by default. */  locale?: string  /** Disables the field and both buttons. */  disabled?: boolean}>()/** The number; null while the field is empty: `v-model`. */const model = defineModel<number | null>()/* * A number between two buttons. Name the field with `aria-label`, or give it an `id` a label points at; * `min`, `max`, `step` and every other attribute but the class go to the field; `disabled` disables the buttons * too. A label with the `stepper-scrub` class steps the number as it is dragged sideways. */const attrs = useAttrs()const field = () => {  const { class: _, ...rest } = attrs  return rest}// The first number is the field's default value, an attribute: what is typed after is not Vue's to write.const first = model.value// The first figure is drawn into the first render, so the HTML a server sends shows it.const written = props.format && typeof first === 'number' ? new Intl.NumberFormat(props.locale, props.format).format(first) : undefinedconst root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, stepper, () => ({ format: props.format, locale: props.locale }), model)</script><template>  <div class="input-group stepper" :class="$attrs.class" ref="root">    <button type="button" class="btn btn-square" value="-1" tabindex="-1" :aria-label="decrementLabel" :disabled="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>    <span v-if="format" class="stepper-value">      <input class="input-group-field stepper-field" type="number" :value.attr="first ?? undefined" :aria-valuetext="written" :disabled="disabled" v-bind="field()">      <span class="stepper-display" aria-hidden="true">{{ written }}</span>    </span>    <input v-else class="input-group-field stepper-field" type="number" :value.attr="first ?? undefined" :disabled="disabled" v-bind="field()">    <button type="button" class="btn btn-square" value="1" tabindex="-1" :aria-label="incrementLabel" :disabled="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></template>

#클래스

클래스설명
stepperinput-group에 적용합니다. 숫자 너비에 맞춘 오목한 영역의 양 끝에 버튼을 하나씩 배치합니다. 한계값에 도달해 비활성화된 버튼은 오목한 영역 안에서 평평하게 표시됩니다.
stepper-field그룹에서 네이티브 숫자 입력 요소인 input-group-field에 적용합니다. 고정폭 숫자를 가운데 정렬하고 값 조절 버튼을 숨깁니다.
stepper-value필드와 stepper-display를 감싸는 요소로, 둘 중 더 넓은 쪽의 너비를 가진 셀 하나를 이룹니다. 필드에 포커스가 없고 표시 요소에 숫자가 있는 동안에는 필드 자체의 숫자가 투명해집니다.
stepper-display필드 뒤의 stepper-value 안에 aria-hidden="true"를 지정해 둡니다. Intl.NumberFormat이 형식을 지정한 숫자를 필드에 포커스가 없는 동안 필드 자리에 표시합니다. 동작이 기록합니다.
stepper-scrub오목한 영역 안의 손잡이 또는 페이지 어디에든 있는 필드의 레이블로, 옆으로 끌면 숫자가 단계별로 바뀝니다. ew-resize 커서가 표시되고 텍스트는 선택되지 않습니다.

#사용자 지정 속성

속성기본값설명
--stepper-min3ch숫자 입력 필드의 최소 너비
--stepper-max9chfield-sizing으로 늘어날 수 있는 최대 너비

#소스

@master/ui/components/stepper.css
/* * Stepper: a number between the two buttons that step it. * It is an input group around a native number input: the well holds a small raised button at each end, 4px in, * and the figure stands centered between them in tabular numerals. The field keeps what the platform gives a * number input: the arrow keys, min, max, step and the spinbutton role. The buttons call stepDown() and * stepUp() from a few lines of script; without it the field still types and steps from the keys. * The browser's own spin buttons are removed, since the two buttons replace them. * The well is as wide as its figure. Where field-sizing exists it follows the digits typed, between * --stepper-min and --stepper-max; elsewhere it keeps --stepper-min. * A figure written with a unit, a currency or grouping stands in a stepper-display over the field, shown while * the field is not focused; a stepper-scrub handle or label steps the number as it is dragged sideways. */@layer components.ui {  .stepper {    --stepper-min: 3ch;    --stepper-max: 9ch;    display: inline-flex;    max-width: 100%;    vertical-align: middle;    /* The buttons stand 4px from the figure's box, as they stand 4px from the well. */    gap: 4px;    cursor: default;    /* A step that has reached its limit lies flat in the well: no face, no edge, only its quiet glyph. */    .btn:disabled {      background: transparent;      box-shadow: none;    }  }  .stepper-field {    flex: 1 1 auto;    width: calc(var(--stepper-min) + 1rem);    padding-inline: .5rem;    font-weight: var(--font-weight-control);    font-variant-numeric: tabular-nums;    text-align: center;    appearance: textfield;    cursor: text;    /* Its own text cursor would otherwise stand over the group's not-allowed one. */    &:disabled {      cursor: not-allowed;    }    &::-webkit-inner-spin-button, &::-webkit-outer-spin-button {      display: none;    }    /*     * A unit after the field belongs to the figure: the digits stand at the field's end and the unit follows them     * at the gap, as one phrase.     */    &:has(+ .input-group-addon) {      padding-inline-end: 0;      text-align: end;    }    /*     * Sized by its digits, the field stops at --stepper-max even in a wider stepper. The room it leaves goes to     * either side of the figure, and of its unit when one follows, so the figure stays centered between the     * buttons and the buttons keep to the ends.     */    @supports (field-sizing: content) {      width: auto;      min-width: calc(var(--stepper-min) + 1rem);      max-width: calc(var(--stepper-max) + 1rem);      margin-inline: auto;      field-sizing: content;      &:has(+ .input-group-addon) {        margin-inline-end: 0;      }      + .input-group-addon {        margin-inline-end: auto;      }    }  }  /*   * A formatted figure: the field and its display stacked in one cell, as wide as the wider of the two. The   * field always fills the cell, so a press anywhere on the figure lands in it. While the field is not focused   * its own digits are clear and the display shows the formatted figure in the same place; while it is   * focused the display steps aside and the plain number is edited. Without the script the display is empty   * and the field shows its number as usual.   */  .stepper-value {    display: inline-grid;    flex: 1 1 auto;    align-self: stretch;    min-width: 0;    .stepper-field {      grid-area: 1 / 1;      min-width: 100%;    }    &:not(:focus-within):has(.stepper-display:not(:empty)) .stepper-field {      color: transparent;    }    &:focus-within .stepper-display {      visibility: hidden;    }    &:has(.stepper-field:disabled) .stepper-display {      color: var(--color-text-disabled);    }    /*     * Forced colors would repaint the clear digits in the field's text color, over the display's. The field     * keeps its own colors there while the display stands in for it.     */    @media (forced-colors: active) {      &:not(:focus-within):has(.stepper-display:not(:empty)) .stepper-field {        forced-color-adjust: none;      }    }  }  /* A unit stands as far from the button after it as the figure stands from the button before. */  .stepper .input-group-addon {    padding-inline-end: .5rem;  }  .stepper-display {    grid-area: 1 / 1;    align-self: center;    min-width: calc(var(--stepper-min) + 1rem);    max-width: calc(var(--stepper-max) + 1rem);    padding-inline: .5rem;    overflow: hidden;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    font-variant-numeric: tabular-nums;    text-align: center;    text-overflow: ellipsis;    white-space: nowrap;    pointer-events: none;    user-select: none;    -webkit-user-select: none;  }  /*   * A scrub handle: a handle in the well, or a label of the field anywhere in the page. Dragged sideways it   * steps the number. It keeps a vertical swipe for the page and takes the sideways one.   */  .stepper-scrub {    cursor: ew-resize;    touch-action: pan-y;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;  }  /* A field that is disabled or read-only steps nothing, so a handle in its well no longer offers to drag. */  .stepper:has(.stepper-field:is(:disabled, [readonly])) .stepper-scrub {    cursor: inherit;  }}