본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Number Field

원문 보기 위키 갱신

품질이 높고 비스타일(unstyled)인 React 숫자 필드 컴포넌트로, 증가·감소 버튼과 스크럽 영역(scrub area)을 제공해요.

출처: Base UI Number Field

본문

Demo

Tailwind

이 예시는 Tailwind CSS를 사용해 컴포넌트를 구현하는 방법을 보여줄게요.

/* index.tsx */
import * as React from 'react';
import { NumberField } from '@base-ui/react/number-field';

const stepperClasses =
  'flex h-full w-8 items-center justify-center border border-neutral-950 bg-white bg-clip-padding text-neutral-950 outline-0 select-none dark:border-white dark:bg-neutral-950 dark:text-white hover:not-data-disabled:bg-neutral-100 dark:hover:not-data-disabled:bg-neutral-800 active:not-data-disabled:bg-neutral-200 dark:active:not-data-disabled:bg-neutral-700 data-disabled:border-neutral-500 data-disabled:text-neutral-500 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400';

export default function ExampleNumberField() {
  const id = React.useId();
  return (
    <NumberField.Root id={id} defaultValue={100} className="flex flex-col items-start gap-1">
      <NumberField.ScrubArea className="cursor-ew-resize font-bold select-none">
        <label
          htmlFor={id}
          className="cursor-ew-resize text-sm font-bold text-neutral-950 dark:text-white"
        >
          Amount
        </label>
        <NumberField.ScrubAreaCursor className="drop-shadow-[0_1px_1px_#0008] filter">
          <CursorGrowIcon />
        </NumberField.ScrubAreaCursor>
      </NumberField.ScrubArea>

      <NumberField.Group className="flex h-8">
        <NumberField.Decrement className={`${stepperClasses} border-r-0`}>
          <MinusIcon />
        </NumberField.Decrement>
        <NumberField.Input className="h-full w-[7ch] border border-neutral-950 bg-white px-2 text-left text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base dark:border-white dark:bg-neutral-950 dark:text-white focus:z-1 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white" />
        <NumberField.Increment className={`${stepperClasses} border-l-0`}>
          <PlusIcon />
        </NumberField.Increment>
      </NumberField.Group>
    </NumberField.Root>
  );
}

function CursorGrowIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="26"
      height="14"
      viewBox="0 0 24 14"
      fill="black"
      stroke="white"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M19.5 5.5L6.49737 5.51844V2L1 6.9999L6.5 12L6.49737 8.5L19.5 8.5V12L25 6.9999L19.5 2V5.5Z" />
    </svg>
  );
}

function PlusIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeLinecap="square"
      strokeLinejoin="round"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M1.5 8h13M8 14.5v-13" />
    </svg>
  );
}

function MinusIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeLinecap="square"
      strokeLinejoin="round"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M1.5 8h13" />
    </svg>
  );
}

CSS Modules

이 예시는 CSS Modules를 사용해 컴포넌트를 구현하는 방법을 보여줄게요.

/* index.module.css */
.Field {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: 0.25rem;
}

.ScrubArea {
  cursor: ew-resize;
  font-weight: 700;
  -webkit-user-select: none;
  user-select: none;
}

.ScrubAreaCursor {
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 50%));
}

.Label {
  cursor: ew-resize;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Group {
  display: flex;
  height: 2rem;
}

.Input {
  box-sizing: border-box;
  margin: 0;
  padding: 0 0.5rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  width: 7ch;
  height: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
  background-color: white;
  color: oklch(14.5% 0 0deg);

  text-align: left;
  font-variant-numeric: tabular-nums;

  @media (any-pointer: coarse) {
    font-size: 1rem;
    line-height: 1.5rem;
  }

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  &:focus {
    z-index: 1;
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Decrement,
.Increment {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 100%;
  margin: 0;
  outline: 0;
  padding: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  background-clip: padding-box;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not([data-disabled]) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not([data-disabled]) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-disabled] {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }
}

.Decrement {
  border-right: 0;
}

.Increment {
  border-left: 0;
}
/* index.tsx */
import * as React from 'react';
import { NumberField } from '@base-ui/react/number-field';
import styles from './index.module.css';

export default function ExampleNumberField() {
  const id = React.useId();
  return (
    <NumberField.Root id={id} defaultValue={100} className={styles.Field}>
      <NumberField.ScrubArea className={styles.ScrubArea}>
        <label htmlFor={id} className={styles.Label}>
          Amount
        </label>
        <NumberField.ScrubAreaCursor className={styles.ScrubAreaCursor}>
          <CursorGrowIcon />
        </NumberField.ScrubAreaCursor>
      </NumberField.ScrubArea>

      <NumberField.Group className={styles.Group}>
        <NumberField.Decrement className={styles.Decrement}>
          <MinusIcon />
        </NumberField.Decrement>
        <NumberField.Input className={styles.Input} />
        <NumberField.Increment className={styles.Increment}>
          <PlusIcon />
        </NumberField.Increment>
      </NumberField.Group>
    </NumberField.Root>
  );
}

function CursorGrowIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="26"
      height="14"
      viewBox="0 0 24 14"
      fill="black"
      stroke="white"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M19.5 5.5L6.49737 5.51844V2L1 6.9999L6.5 12L6.49737 8.5L19.5 8.5V12L25 6.9999L19.5 2V5.5Z" />
    </svg>
  );
}

function PlusIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeLinecap="square"
      strokeLinejoin="round"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M1.5 8h13M8 14.5v-13" />
    </svg>
  );
}

function MinusIcon(props: React.ComponentProps<'svg'>) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeLinecap="square"
      strokeLinejoin="round"
      {...props}
      style={{ display: 'block', ...props.style }}
    >
      <path d="M1.5 8h13" />
    </svg>
  );
}

Usage guidelines

  • 폼 컨트롤에는 접근 가능한 이름이 있어야 해요: <label> 요소나 Field 컴포넌트로 만들 수 있어요. forms 가이드를 참고하세요.

Anatomy

컴포넌트를 불러와서 각 부분을 조립해요:

import { NumberField } from '@base-ui/react/number-field';

<NumberField.Root>
  <NumberField.ScrubArea>
    <NumberField.ScrubAreaCursor />
  </NumberField.ScrubArea>
  <NumberField.Group>
    <NumberField.Decrement />
    <NumberField.Input />
    <NumberField.Increment />
  </NumberField.Group>
</NumberField.Root>;

API reference

Root

숫자 필드의 모든 부분을 그룹으로 묶고 상태를 관리해요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
name string - Identifies the field when a form is submitted.
defaultValue number - The uncontrolled value of the field when it's initially rendered. To render a controlled number field, use the value prop instead.
value number | null - The raw numeric value of the field.
onValueChange ((value: number | null, eventDetails: NumberField.Root.ChangeEventDetails) => void) - Callback fired when the number value changes. The eventDetails.reason indicates what triggered the change: 'input-change' for parseable typing or programmatic text updates'input-clear' when the field becomes empty'input-blur' when formatting (and clamping, if enabled) occurs on blur'input-paste' for paste interactions'keyboard' for arrow-key/Home/End stepping (typing digits uses 'input-change'/'input-clear')'increment-press' / 'decrement-press' for button presses on the increment and decrement controls'wheel' for wheel-based scrubbing'scrub' for scrub area drags
onValueCommitted ((value: number | null, eventDetails: NumberField.Root.CommitEventDetails) => void) - Callback function that is fired when the value is committed. It runs later than onValueChange, when: The input is blurred after typing a value.The pointer is released after scrubbing or pressing the increment/decrement buttons. It runs simultaneously with onValueChange when interacting with the keyboard or the mouse wheel. Warning: This is a generic event not a change event.
allowOutOfRange boolean false When true, direct text entry may be outside the min/max range without clamping, so native range underflow/overflow validation can occur. Step-based interactions (keyboard arrows, buttons, wheel, scrub) still clamp.
form string - Identifies the form that owns the hidden input. Useful when the number field is rendered outside the form.
locale Intl.LocalesArgument - The locale of the input element. Defaults to the user's runtime locale.
snapOnStep boolean false Whether the value should snap to the nearest step when incrementing or decrementing.
step number | 'any' 1 Amount to increment and decrement with the buttons and arrow keys, or to scrub with pointer movement in the scrub area. To always enable step validation on form submission, specify the min prop explicitly in conjunction with this prop. Specify step="any" to always disable step validation; interactive stepping then uses a base amount of 1, while the alt and shift keys still step by smallStep and largeStep.
smallStep number 0.1 The small step value of the input element when incrementing while the alt key is held. Snaps to multiples of this value when snapOnStep is enabled.
largeStep number 10 The large step value of the input element when incrementing while the shift key is held. Snaps to multiples of this value when snapOnStep is enabled.
min number - The minimum value of the input element.
max number - The maximum value of the input element.
allowWheelScrub boolean false Whether to allow the user to scrub the input value with the mouse wheel while focused and hovering over the input.
format Intl.NumberFormatOptions - Options to format the input value.
disabled boolean false Whether the component should ignore user interaction.
readOnly boolean false Whether the user should be unable to change the field value.
required boolean false Whether the user must enter a value before submitting a form.
inputRef React.Ref<HTMLInputElement> - A ref to access the hidden input element.
id string - The id of the input element.
className string | ((state: NumberField.Root.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.Root.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.Root.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Root Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

Root.Props

Root props의 재-export예요.

Root.State

type NumberFieldRootState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Root.ChangeEventReason

type NumberFieldRootChangeEventReason =
  | 'input-change'
  | 'input-clear'
  | 'input-blur'
  | 'input-paste'
  | 'keyboard'
  | 'increment-press'
  | 'decrement-press'
  | 'wheel'
  | 'scrub'
  | 'none';

Root.ChangeEventDetails

type NumberFieldRootChangeEventDetails = (
  | { reason: 'input-change'; event: InputEvent | Event }
  | { reason: 'input-clear'; event: InputEvent | Event | FocusEvent }
  | { reason: 'input-blur'; event: FocusEvent }
  | { reason: 'input-paste'; event: ClipboardEvent }
  | { reason: 'keyboard'; event: KeyboardEvent }
  | { reason: 'increment-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'decrement-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'wheel'; event: WheelEvent }
  | { reason: 'scrub'; event: PointerEvent }
  | { reason: 'none'; event: Event }
) & {
  /** Cancels Base UI from handling the event. */
  cancel: () => void;
  /** Allows the event to propagate in cases where Base UI will stop the propagation. */
  allowPropagation: () => void;
  /** Indicates whether the event has been canceled. */
  isCanceled: boolean;
  /** Indicates whether the event is allowed to propagate. */
  isPropagationAllowed: boolean;
  /** The element that triggered the event, if applicable. */
  trigger: Element | undefined;
  direction?: Direction;
};

Root.CommitEventReason

type NumberFieldRootCommitEventReason =
  | 'input-blur'
  | 'input-clear'
  | 'keyboard'
  | 'increment-press'
  | 'decrement-press'
  | 'wheel'
  | 'scrub'
  | 'none';

Root.CommitEventDetails

type NumberFieldRootCommitEventDetails =
  | { reason: 'input-clear'; event: InputEvent | Event | FocusEvent }
  | { reason: 'input-blur'; event: FocusEvent }
  | { reason: 'keyboard'; event: KeyboardEvent }
  | { reason: 'increment-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'decrement-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'wheel'; event: WheelEvent }
  | { reason: 'scrub'; event: PointerEvent }
  | { reason: 'none'; event: Event };

Input

숫자 필드 안의 네이티브 입력 컨트롤이에요. <input> 요소를 렌더링해요.

Input Props:

Prop Type Default Description
aria-roledescription string 'Number field' A user-friendly description of the input's role for assistive tech. This is a role description, not an accessible name — use Field.Label or aria-label to name the control.
className string | ((state: NumberField.Input.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.Input.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, state: NumberField.Input.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Input Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

Input.Props

Input props의 재-export예요.

Input.State

type NumberFieldInputState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Group

입력을 증가·감소 버튼과 함께 묶어줘요. <div> 요소를 렌더링해요.

Group Props:

Prop Type Default Description
className string | ((state: NumberField.Group.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.Group.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.Group.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Group Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

Group.Props

Group props의 재-export예요.

Group.State

type NumberFieldGroupState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

ScrubArea

사용자가 클릭하고 드래그해서 필드 값을 바꿀 수 있는 상호작용 영역이에요. <span> 요소를 렌더링해요.

ScrubArea Props:

Prop Type Default Description
direction 'horizontal' | 'vertical' 'horizontal' Cursor movement direction in the scrub area.
pixelSensitivity number 2 Determines how many pixels the cursor must move before the value changes. A higher value will make scrubbing less sensitive.
teleportDistance number - If specified, determines the distance that the cursor may move from the center of the scrub area before it will loop back around.
className string | ((state: NumberField.ScrubArea.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.ScrubArea.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.ScrubArea.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

ScrubArea Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

ScrubArea.Props

ScrubArea props의 재-export예요.

ScrubArea.State

type NumberFieldScrubAreaState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

ScrubAreaCursor

스크럽 영역을 사용하는 동안 네이티브 커서 대신 표시할 커스텀 요소예요. <span> 요소를 렌더링해요.

이 컴포넌트는 Pointer Lock API를 사용하는데, 브라우저가 관련 알림을 표시하도록 요청할 수 있어요. Safari에서는 이 알림 때문에 발생하는 레이아웃 이동(layout shift)을 피하기 위해 비활성화돼요.

ScrubAreaCursor Props:

Prop Type Default Description
className string | ((state: NumberField.ScrubAreaCursor.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.ScrubAreaCursor.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.ScrubAreaCursor.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

ScrubAreaCursor Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

ScrubAreaCursor.Props

ScrubAreaCursor props의 재-export예요.

ScrubAreaCursor.State

type NumberFieldScrubAreaCursorState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Decrement

클릭하면 필드 값을 줄여주는 스테퍼 버튼이에요. <button> 요소를 렌더링해요.

Decrement Props:

Prop Type Default Description
nativeButton boolean true Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
className string | ((state: NumberField.Decrement.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.Decrement.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.Decrement.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Decrement Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

Decrement.Props

Decrement props의 재-export예요.

Decrement.State

type NumberFieldDecrementState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Increment

클릭하면 필드 값을 늘려주는 스테퍼 버튼이에요. <button> 요소를 렌더링해요.

Increment Props:

Prop Type Default Description
nativeButton boolean true Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
className string | ((state: NumberField.Increment.State) => string | undefined) - CSS class applied to the element, or a function that returns a class based on the component's state.
style React.CSSProperties | ((state: NumberField.Increment.State) => React.CSSProperties | undefined) - Style applied to the element, or a function that returns a style object based on the component's state.
render ReactElement | ((props: HTMLProps, state: NumberField.Increment.State) => ReactElement) - Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Increment Data Attributes:

Attribute Type Description
data-disabled - Present when the number field is disabled.
data-readonly - Present when the number field is readonly.
data-required - Present when the number field is required.
data-valid - Present when the number field is in a valid state (when wrapped in Field.Root).
data-invalid - Present when the number field is in an invalid state (when wrapped in Field.Root).
data-dirty - Present when the number field's value has changed (when wrapped in Field.Root).
data-touched - Present when the number field has been touched (when wrapped in Field.Root).
data-filled - Present when the number field is filled (when wrapped in Field.Root).
data-focused - Present when the number field is focused (when wrapped in Field.Root).
data-scrubbing - Present while scrubbing.

Increment.Props

Increment props의 재-export예요.

Increment.State

type NumberFieldIncrementState = {
  /** The raw numeric value of the field. */
  value: number | null;
  /** The formatted string value presented in the input element. */
  inputValue: string;
  /** Whether the user must enter a value before submitting a form. */
  required: boolean;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the user should be unable to change the field value. */
  readOnly: boolean;
  /** Whether the user is currently scrubbing the field. */
  scrubbing: boolean;
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

External Types

Direction

type Direction = -1 | 1;

Export Groups

  • NumberField.Root: NumberField.Root, NumberField.Root.State, NumberField.Root.Props, NumberField.Root.ChangeEventReason, NumberField.Root.ChangeEventDetails, NumberField.Root.CommitEventReason, NumberField.Root.CommitEventDetails
  • NumberField.Group: NumberField.Group, NumberField.Group.State, NumberField.Group.Props
  • NumberField.Increment: NumberField.Increment, NumberField.Increment.State, NumberField.Increment.Props
  • NumberField.Decrement: NumberField.Decrement, NumberField.Decrement.State, NumberField.Decrement.Props
  • NumberField.Input: NumberField.Input, NumberField.Input.State, NumberField.Input.Props
  • NumberField.ScrubArea: NumberField.ScrubArea, NumberField.ScrubArea.State, NumberField.ScrubArea.Props
  • NumberField.ScrubAreaCursor: NumberField.ScrubAreaCursor, NumberField.ScrubAreaCursor.State, NumberField.ScrubAreaCursor.Props
  • Default: NumberFieldRootProps, NumberFieldRootState, NumberFieldRootChangeEventReason, NumberFieldRootChangeEventDetails, NumberFieldRootCommitEventReason, NumberFieldRootCommitEventDetails, NumberFieldGroupState, NumberFieldGroupProps, NumberFieldIncrementState, NumberFieldIncrementProps, NumberFieldDecrementState, NumberFieldDecrementProps, NumberFieldInputState, NumberFieldInputProps, NumberFieldScrubAreaState, NumberFieldScrubAreaProps, NumberFieldScrubAreaCursorState, NumberFieldScrubAreaCursorProps

Canonical Types

Canonical: Alias 매핑이에요. 네임스페이스가 이미 import되어 있을 때는 Canonical을, 그렇지 않으면 Alias를 사용해요.

  • NumberField.Root.State: NumberFieldRootState
  • NumberField.Root.Props: NumberFieldRootProps
  • NumberField.Root.ChangeEventReason: NumberFieldRootChangeEventReason
  • NumberField.Root.ChangeEventDetails: NumberFieldRootChangeEventDetails
  • NumberField.Root.CommitEventReason: NumberFieldRootCommitEventReason
  • NumberField.Root.CommitEventDetails: NumberFieldRootCommitEventDetails
  • NumberField.Group.State: NumberFieldGroupState
  • NumberField.Group.Props: NumberFieldGroupProps
  • NumberField.Increment.State: NumberFieldIncrementState
  • NumberField.Increment.Props: NumberFieldIncrementProps
  • NumberField.Decrement.State: NumberFieldDecrementState
  • NumberField.Decrement.Props: NumberFieldDecrementProps
  • NumberField.Input.State: NumberFieldInputState
  • NumberField.Input.Props: NumberFieldInputProps
  • NumberField.ScrubArea.State: NumberFieldScrubAreaState
  • NumberField.ScrubArea.Props: NumberFieldScrubAreaProps
  • NumberField.ScrubAreaCursor.State: NumberFieldScrubAreaCursorState
  • NumberField.ScrubAreaCursor.Props: NumberFieldScrubAreaCursorProps

더 알아보기