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

InputGroup (입력 그룹)

원문 보기 위키 갱신

InputGroup는 접두어(prefix)와 접미어(suffix) 요소로 관련된 입력 컨트롤을 묶어 향상된 폼 필드를 만들어주는 컴포넌트예요. 입력창 앞뒤에 아이콘이나 텍스트, 버튼을 붙이고 싶을 때 사용해요.

출처: HeroUI InputGroup

본문

사용법 (Usage)

import { InputGroup } from '@heroui/react';
{"name": "input-group-default"}

구조 (Anatomy)

import {InputGroup, TextField, Label} from '@heroui/react';

export default () => (
  <TextField>
    <Label />
    <InputGroup>
      <InputGroup.Prefix />
      <InputGroup.Input /> {/* Or use InputGroup.TextArea for multiline input */}
      <InputGroup.Suffix />
    </InputGroup>
  </TextField>
)

InputGroup은 입력 필드를 선택적 접두어·접미어 요소로 감싸 시각적으로 통일된 그룹을 만들어요. 보통 TextField 안에서 사용해 입력 앞뒤에 아이콘, 텍스트, 버튼, 기타 요소를 추가해요. 한 줄 입력에는 InputGroup.Input을, 여러 줄 텍스트에는 InputGroup.TextArea를 사용하면 돼요.

예시 (Examples)

변형 (Variants)

InputGroup 컴포넌트는 두 가지 시각적 변형을 지원해요:

  • primary (기본값) - 그림자가 있는 표준 스타일, 대부분의 사용 사례에 적합
  • secondary - 그림자가 없는 낮은 강조 변형, Surface 컴포넌트 안에서 사용하기 적합
{"name": "input-group-variants"}

Surface 안에서 (In Surface)

Surface 컴포넌트 안에서 사용할 때는 variant="secondary"를 사용해 표면 배경에 어울리는 낮은 강조 변형을 적용할 수 있어요.

{"name": "input-group-on-surface"}

로딩 상태 (Loading State)

접미어에 로딩 스피너를 표시해 처리 중임을 알릴 수 있어요.

{"name": "input-group-with-loading-suffix"}

필수 필드 (Required Field)

InputGroup은 상위 TextField의 필수(required) 상태를 따르고 있어요.

{"name": "input-group-required"}

비활성화 상태 (Disabled State)

InputGroup은 상위 TextField의 비활성화(disabled) 상태를 따르고 있어요.

{"name": "input-group-disabled"}

전체 너비 (Full Width)

{"name": "input-group-full-width"}

텍스트 접두어 (Text Prefix)

통화 기호나 프로토콜 접두어처럼 텍스트를 접두어로 사용할 수 있어요.

{"name": "input-group-with-text-prefix"}

텍스트 접미어 (Text Suffix)

도메인 확장자나 단위처럼 텍스트를 접미어로 사용할 수 있어요.

{"name": "input-group-with-text-suffix"}

아이콘 접두어와 텍스트 접미어 (Icon Prefix and Text Suffix)

아이콘 접두어와 텍스트 접미어를 결합할 수 있어요.

{"name": "input-group-with-icon-prefix-and-text-suffix"}

복사 버튼 접미어 (Copy Button Suffix)

복사 버튼처럼 접미어에 상호작용형 버튼을 추가할 수 있어요.

{"name": "input-group-with-copy-suffix"}

아이콘 접두어와 복사 버튼 (Icon Prefix and Copy Button)

아이콘 접두어와 상호작용형 버튼 접미어를 결합할 수 있어요.

{"name": "input-group-with-icon-prefix-and-copy-suffix"}

비밀번호 토글 (Password Toggle)

접미어의 버튼으로 비밀번호 표시 여부를 토글할 수 있어요.

{"name": "input-group-password-with-toggle"}

키보드 단축키 (Keyboard Shortcut)

Kbd 컴포넌트로 키보드 단축키를 표시할 수 있어요.

{"name": "input-group-with-keyboard-shortcut"}

배지 접미어 (Badge Suffix)

상태나 라벨을 보여주기 위해 접미어에 배지나 칩을 추가할 수 있어요.

{"name": "input-group-with-badge-suffix"}

검증 (Validation)

InputGroup은 상위 TextField의 유효하지 않은(invalid) 상태를 자동으로 반영해요.

{"name": "input-group-invalid"}

접두어 아이콘과 함께 (With Prefix Icon)

입력 필드 앞에 아이콘을 추가할 수 있어요.

{"name": "input-group-with-prefix-icon"}

접미어 아이콘과 함께 (With Suffix Icon)

입력 필드 뒤에 아이콘을 추가할 수 있어요.

{"name": "input-group-with-suffix-icon"}

접두어와 접미어와 함께 (With Prefix and Suffix)

접두어와 접미어 요소를 모두 결합할 수 있어요.

{"name": "input-group-with-prefix-and-suffix"}

TextArea와 함께 (With TextArea)

여러 줄 텍스트 입력에는 InputGroup.TextArea를 접두어·접미어 요소와 함께 사용해요. textarea가 있으면 컨테이너가 콘텐츠에 맞게 높이를 자동으로 조절하고 접두어·접미어 요소를 위쪽 정렬해요.

{"name": "input-group-with-textarea"}

사용 예시 (Usage Example)

import {InputGroup, TextField, Label, Button} from '@heroui/react';
import {Icon} from '@iconify/react';

function Example() {
  return (
    <TextField>
      <Label>Email</Label>
      <InputGroup>
        <InputGroup.Prefix>
          <Icon icon="gravity-ui:envelope" />
        </InputGroup.Prefix>
        <InputGroup.Input placeholder="name@email.com" />
        <InputGroup.Suffix>
          <Button isIconOnly aria-label="Confirm" size="sm" variant="ghost">
            <Icon icon="gravity-ui:check" />
          </Button>
        </InputGroup.Suffix>
      </InputGroup>
    </TextField>
  );
}

TextArea 사용 예시 (TextArea Usage Example)

import {Envelope} from "@gravity-ui/icons";
import {Description, FieldError, InputGroup, Label, TextField} from "@heroui/react";
import {useState} from "react";

function TextAreaExample() {
  const [feedback, setFeedback] = useState("");

  return (
    <TextField fullWidth isInvalid={feedback.length > 500} name="feedback" onChange={setFeedback}>
      <Label>Your Feedback</Label>
      <InputGroup fullWidth>
        <InputGroup.Prefix>
          <Envelope className="size-4 text-muted" />
        </InputGroup.Prefix>
        <InputGroup.TextArea
          className="resize-none"
          placeholder="Share your thoughts, suggestions, or issues..."
          rows={5}
          value={feedback}
        />
      </InputGroup>
      <Description className="flex w-full items-center justify-between px-1">
        <span>Maximum 500 characters.</span>
        <span className="ml-auto">{feedback.length}/500</span>
      </Description>
      <FieldError>Feedback must be less than 500 characters</FieldError>
    </TextField>
  );
}

커스터마이징 (Customization)

Tailwind CSS

{"name": "input-group-custom-styles"}

Global CSS

InputGroup은 커스터마이징할 수 있는 CSS 클래스를 사용해요. 디자인 시스템에 맞춰 컴포넌트 클래스를 재정의하면 돼요.

@layer components {
  .input-group {
    @apply bg-field text-field-foreground shadow-field rounded-field inline-flex min-h-9 items-center overflow-hidden border text-sm outline-none;
  }

  .input-group__input {
    @apply flex-1 rounded-none border-0 bg-transparent px-3 py-2 shadow-none outline-none;
  }

  .input-group__prefix {
    @apply text-field-placeholder rounded-l-field flex h-full items-center justify-center rounded-r-none bg-transparent px-3;
  }

  .input-group__suffix {
    @apply text-field-placeholder rounded-r-field flex h-full items-center justify-center rounded-l-none bg-transparent px-3;
  }

  /* Secondary variant */
  .input-group--secondary {
    @apply shadow-none;
    background-color: var(--color-default);
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

기본 클래스 (Base Classes) [!toc]

  • .input-group – 테두리, 배경, 플렉스 레이아웃을 가진 루트 컨테이너. 유연한 높이를 위해 min-h-9를 사용하고 기본적으로 items-center를 쓰며, textarea가 있으면 items-start로 전환돼요.
  • .input-group__input – 투명 배경과 테두리가 없는 입력 요소. textarea 요소의 기본 클래스로도 사용돼요.
  • .input-group__prefix – 왼쪽 테두리 반경을 가진 접두어 컨테이너. textarea와 함께 쓸 때는 위쪽 정렬돼요.
  • .input-group__suffix – 오른쪽 테두리 반경을 가진 접미어 컨테이너. textarea와 함께 쓸 때는 위쪽 정렬돼요.

변형 클래스 (Variant Classes) [!toc]

  • .input-group--primary – 그림자가 있는 기본 변형 (기본값)
  • .input-group--secondary – 그림자가 없는 보조 변형, 표면(surface) 안에서 사용하기 적합

참고: InputGroup.TextArea를 사용하면 컨테이너가 items-center에서 items-start 정렬로 자동 전환되고 고정 높이 대신 height: auto를 사용해요. 접두어·접미어 요소는 textarea의 세로 패딩에 맞춰 추가 패딩과 함께 위쪽 정렬돼요. textarea는 동일한 .input-group__input 기본 클래스를 사용하며, textarea 특유의 스타일(최소 높이와 세로 리사이즈)은 [data-slot="input-group-textarea"] 속성 선택자로 적용돼요.

상호작용 상태 (Interactive States)

InputGroup은 상태에 따라 다음 데이터 속성을 자동으로 관리해요:

  • 호버 (Hover): [data-hovered] - 그룹 위에 마우스를 올렸을 때 적용
  • 포커스 내부 (Focus Within): [data-focus-within] - 입력이 포커스되었을 때 적용
  • 유효하지 않음 (Invalid): [data-invalid] - 상위 TextField가 유효하지 않을 때 적용
  • 비활성화 (Disabled): [data-disabled] 또는 [aria-disabled] - 상위 TextField가 비활성화되었을 때 적용

API 참고 (API Reference)

InputGroup

InputGroup은 React Aria의 Group 컴포넌트에서 모든 속성을 상속해요.

기본 속성 (Base Props)

Prop Type Default Description
children React.ReactNode | (values: GroupRenderProps) => React.ReactNode - Child components (Input, TextArea, Prefix, Suffix) or render function.
className string | (values: GroupRenderProps) => string - CSS classes for styling, supports render props.
style React.CSSProperties | (values: GroupRenderProps) => React.CSSProperties - Inline styles, supports render props.
fullWidth boolean false Whether the input group should take full width of its container
id string - The element's unique identifier.

변형 속성 (Variant Props)

Prop Type Default Description
variant "primary" | "secondary" "primary" Visual variant of the component. primary is the default style with shadow. secondary is a lower emphasis variant without shadow, suitable for use in surfaces.

접근성 속성 (Accessibility Props)

Prop Type Default Description
aria-label string - Accessibility label when no visible label is present.
aria-labelledby string - ID of elements that label this group.
aria-describedby string - ID of elements that describe this group.
aria-details string - ID of elements with additional details.
role 'group' | 'region' | 'presentation' 'group' Accessibility role for the group. Use 'region' for important content, 'presentation' for visual-only grouping.

조합 컴포넌트 (Composition Components)

InputGroup은 다음 하위 컴포넌트와 함께 동작해요:

  • InputGroup.Root - 루트 컨테이너 (InputGroup으로도 사용 가능)
  • InputGroup.Input - 한 줄 입력 요소 컴포넌트
  • InputGroup.TextArea - 여러 줄 textarea 요소 컴포넌트
  • InputGroup.Prefix - 접두어 컨테이너 컴포넌트
  • InputGroup.Suffix - 접미어 컨테이너 컴포넌트

InputGroup.Input 속성 (InputGroup.Input Props)

InputGroup.Input은 React Aria의 Input 컴포넌트에서 모든 속성을 상속해요.

Prop Type Default Description
className string - CSS classes for styling.
variant "primary" | "secondary" "primary" Visual variant of the input. primary is the default style with shadow. secondary is a lower emphasis variant without shadow, suitable for use in surfaces.
type string 'text' Input type (text, password, email, etc.).
value string - Current value (controlled).
defaultValue string - Default value (uncontrolled).
placeholder string - Placeholder text.
disabled boolean - Whether the input is disabled.
readOnly boolean - Whether the input is read-only.

InputGroup.TextArea 속성 (InputGroup.TextArea Props)

InputGroup.TextArea은 React Aria의 TextArea 컴포넌트에서 모든 속성을 상속해요.

Prop Type Default Description
className string - CSS classes for styling.
variant "primary" | "secondary" "primary" Visual variant of the textarea. primary is the default style with shadow. secondary is a lower emphasis variant without shadow, suitable for use in surfaces.
value string - Current value (controlled).
defaultValue string - Default value (uncontrolled).
placeholder string - Placeholder text.
rows number - Number of visible text lines.
disabled boolean - Whether the textarea is disabled.
readOnly boolean - Whether the textarea is read-only.

InputGroup.Prefix 속성 (InputGroup.Prefix Props)

Prop Type Default Description
children React.ReactNode - Content to display in the prefix (icons, text, etc.).
className string - CSS classes for styling.

InputGroup.Suffix 속성 (InputGroup.Suffix Props)

Prop Type Default Description
children React.ReactNode - Content to display in the suffix (icons, buttons, badges, etc.).
className string - CSS classes for styling.

더 알아보기 (Learn more)