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

AutoComplete

원문 보기 위키 갱신

AutoComplete는 입력할 때 실시간 제안을 보여주는 입력 컴포넌트예요. 검색어를 입력하면 그에 맞는 옵션을 바로 보여줘서, 빠르게 선택할 수 있게 해줘요.

출처: 문서

본문

사용법 (Usage)

import { AutoComplete } from '@primereact/ui/autocomplete';
<AutoComplete.Root>
    <AutoComplete.Input />
    <AutoComplete.Clear />
    <AutoComplete.Trigger>
        <AutoComplete.Value />
        <AutoComplete.Indicator />
    </AutoComplete.Trigger>
    <AutoComplete.Portal>
        <AutoComplete.Positioner>
            <AutoComplete.Popup>
                <AutoComplete.Header />
                <AutoComplete.List>
                    <AutoComplete.Option>
                        <AutoComplete.OptionIndicator />
                    </AutoComplete.Option>
                </AutoComplete.List>
                <AutoComplete.Empty />
                <AutoComplete.Footer />
            </AutoComplete.Popup>
        </AutoComplete.Positioner>
    </AutoComplete.Portal>
</AutoComplete.Root>

예시 (Examples)

기본 (Basic)

사용자가 입력할 때 옵션을 필터링하고 제안하는 입력이에요.

트리거 (Trigger)

루트 안에 AutoComplete.Trigger를 사용해서 제안 목록을 여는 트리거 토글 버튼을 표시할 수 있어요.

칩 (Chips)

AutoComplete.Trigger 안에서 AutoComplete.Input과 AutoComplete.Value를 함께 사용하면 칩 기반 태그 입력을 만들 수 있어요. 선택된 항목은 값 영역 안에 제거 가능한 칩으로 표시되고, 입력은 검색을 위해 편집 가능한 상태로 남아요.

커스텀 옵션 (Custom Option)

AutoComplete.Option 안의 렌더 함수로 옵션 콘텐츠를 커스터마이즈할 수 있어요. 렌더 함수는 selected 상태를 포함한 옵션 인스턴스를 받아요.

그룹 (Group)

단순 (Simple)

optionGroupLabel과 optionGroupChildren 속성으로 옵션을 그룹화할 수 있어요.

커스텀 (Custom)

AutoComplete.List 안에서 목록 인스턴스에 접근해 커스텀 렌더링으로 그룹 헤더를 꾸밀 수 있어요.

커맨드 메뉴 (Command Menu)

AutoComplete와 Dialog를 결합해서 검색 가능한 커맨드 팔레트를 만들 수 있어요. 그룹화된 옵션은 커스텀 그룹 헤더와 함께 목록 인스턴스를 통해 렌더링되고, 옵션을 선택하면 다이얼로그가 닫혀요.

강제 선택 (Force Selection)

forceSelection 속성으로 수동 입력을 제안 목록에 대해 검증할 수 있어요. 일치하는 항목이 없으면 입력 값을 지워서 값이 항상 제안 목록에서 오도록 해요.

플로팅 라벨 (Float Label)

FloatLabel과 통합해서 over, in, on 세 가지 변형의 애니메이션 라벨 동작을 만들 수 있어요.

Ifta 라벨 (Ifta Label)

IftaLabel을 사용해서 필드 안쪽 상단 정렬 라벨 패턴을 만들 수 있어요.

화살표 (Arrow)

팝업 안에 AutoComplete.Arrow를 사용해서 트리거 요소를 가리키는 화살표를 표시할 수 있어요. 간격을 위해 AutoComplete.Positioner에 sideOffset을 설정해요.

지우기 (Clear)

루트 안에 AutoComplete.Clear를 사용해서 입력 값을 초기화하는 지우기 버튼을 표시할 수 있어요.

유동 (Fluid)

fluid 속성으로 autocomplete가 컨테이너의 전체 너비를 차지하게 만들 수 있어요.

로딩 (Loading)

InputGroup을 사용해 autocomplete 입력 옆에 로딩 인디케이터를 조합해서 비동기 로딩 상태를 표시할 수 있어요.

크기 (Sizes)

size 속성으로 autocomplete의 크기를 바꿀 수 있어요.

채움 (Filled)

variant="filled" 속성을 지정하면 기본 아웃라인 스타일보다 시각적 강조가 높아져요.

비활성화 (Disabled)

disabled 속성으로 autocomplete를 비활성화할 수 있어요.

무효 (Invalid)

invalid 속성을 지정하면 검증 오류를 나타내는 빨간 테두리로 컴포넌트를 표시해요.

포커스 동작 (Focus Behavior)

autoOptionFocus, selectOnFocus, focusOnHover props로 키보드·마우스 포커스 동작을 커스터마이즈할 수 있어요.

서브 컴포넌트 (Sub-Components)

AutoCompleteRoot, AutoCompleteInput, AutoCompleteTrigger, AutoCompleteList, AutoCompleteOption 외 다른 컴포넌트 문서는 Primitive API에서 확인하세요.

훅 (Hooks)

useAutoComplete 훅 문서는 Headless API에서 확인하세요.

접근성 (Accessibility)

WAI-ARIA 준수 세부사항과 키보드 지원은 AutoComplete Primitive에서 확인하세요.

테마 (Theming)

CSS 클래스 (CSS Classes)

styled 모드에서 사용하는 클래스 이름 목록이에요.

ClassName Description
p-autocomplete Class name of the root element.
p-autocomplete-input Class name of the input element.
p-autocomplete-clear-icon Class name of the clear element.
p-autocomplete-arrow Class name of the arrow element.
p-autocomplete-indicator Class name of the indicator element.
p-autocomplete-dropdown Class name of the trigger element.
p-autocomplete-list-container Class name of the popup element.
p-autocomplete-list Class name of the list element.
p-autocomplete-option Class name of the option element.
p-autocomplete-option-indicator Class name of the option indicator element.
p-autocomplete-label Class name of the label element (non-editable mode).
p-autocomplete-empty-message Class name of the empty message element.

디자인 토큰 (Design Tokens)

디자인 토큰 목록이에요.

Token CSS Variable Description
autocomplete.background --p-autocomplete-background Background of root
autocomplete.disabled.background --p-autocomplete-disabled-background Disabled background of root
autocomplete.filled.background --p-autocomplete-filled-background Filled background of root
autocomplete.filled.hover.background --p-autocomplete-filled-hover-background Filled hover background of root
autocomplete.filled.focus.background --p-autocomplete-filled-focus-background Filled focus background of root
autocomplete.border.color --p-autocomplete-border-color Border color of root
autocomplete.hover.border.color --p-autocomplete-hover-border-color Hover border color of root
autocomplete.focus.border.color --p-autocomplete-focus-border-color Focus border color of root
autocomplete.invalid.border.color --p-autocomplete-invalid-border-color Invalid border color of root
autocomplete.color --p-autocomplete-color Color of root
autocomplete.disabled.color --p-autocomplete-disabled-color Disabled color of root
autocomplete.placeholder.color --p-autocomplete-placeholder-color Placeholder color of root
autocomplete.invalid.placeholder.color --p-autocomplete-invalid-placeholder-color Invalid placeholder color of root
autocomplete.shadow --p-autocomplete-shadow Shadow of root
autocomplete.padding.x --p-autocomplete-padding-x Padding x of root
autocomplete.padding.y --p-autocomplete-padding-y Padding y of root
autocomplete.border.radius --p-autocomplete-border-radius Border radius of root
autocomplete.focus.ring.width --p-autocomplete-focus-ring-width Focus ring width of root
autocomplete.focus.ring.style --p-autocomplete-focus-ring-style Focus ring style of root
autocomplete.focus.ring.color --p-autocomplete-focus-ring-color Focus ring color of root
autocomplete.focus.ring.offset --p-autocomplete-focus-ring-offset Focus ring offset of root
autocomplete.focus.ring.shadow --p-autocomplete-focus-ring-shadow Focus ring shadow of root
autocomplete.transition.duration --p-autocomplete-transition-duration Transition duration of root
autocomplete.overlay.background --p-autocomplete-overlay-background Background of overlay
autocomplete.overlay.border.color --p-autocomplete-overlay-border-color Border color of overlay
autocomplete.overlay.border.radius --p-autocomplete-overlay-border-radius Border radius of overlay
autocomplete.overlay.color --p-autocomplete-overlay-color Color of overlay
autocomplete.overlay.shadow --p-autocomplete-overlay-shadow Shadow of overlay
autocomplete.list.padding --p-autocomplete-list-padding Padding of list
autocomplete.list.gap --p-autocomplete-list-gap Gap of list
autocomplete.option.focus.background --p-autocomplete-option-focus-background Focus background of option
autocomplete.option.selected.background --p-autocomplete-option-selected-background Selected background of option
autocomplete.option.selected.focus.background --p-autocomplete-option-selected-focus-background Selected focus background of option
autocomplete.option.color --p-autocomplete-option-color Color of option
autocomplete.option.focus.color --p-autocomplete-option-focus-color Focus color of option
autocomplete.option.selected.color --p-autocomplete-option-selected-color Selected color of option
autocomplete.option.selected.focus.color --p-autocomplete-option-selected-focus-color Selected focus color of option
autocomplete.option.padding --p-autocomplete-option-padding Padding of option
autocomplete.option.border.radius --p-autocomplete-option-border-radius Border radius of option
autocomplete.option.font.weight --p-autocomplete-option-font-weight Font weight of option
autocomplete.option.font.size --p-autocomplete-option-font-size Font size of option
autocomplete.option.group.background --p-autocomplete-option-group-background Background of option group
autocomplete.option.group.color --p-autocomplete-option-group-color Color of option group
autocomplete.option.group.font.weight --p-autocomplete-option-group-font-weight Font weight of option group
autocomplete.option.group.font.size --p-autocomplete-option-group-font-size Font size of option group
autocomplete.option.group.padding --p-autocomplete-option-group-padding Padding of option group
autocomplete.dropdown.width --p-autocomplete-dropdown-width Width of dropdown
autocomplete.dropdown.sm.width --p-autocomplete-dropdown-sm-width Sm width of dropdown
autocomplete.dropdown.lg.width --p-autocomplete-dropdown-lg-width Lg width of dropdown
autocomplete.dropdown.border.color --p-autocomplete-dropdown-border-color Border color of dropdown
autocomplete.dropdown.hover.border.color --p-autocomplete-dropdown-hover-border-color Hover border color of dropdown
autocomplete.dropdown.active.border.color --p-autocomplete-dropdown-active-border-color Active border color of dropdown
autocomplete.dropdown.border.radius --p-autocomplete-dropdown-border-radius Border radius of dropdown
autocomplete.dropdown.focus.ring.width --p-autocomplete-dropdown-focus-ring-width Focus ring width of dropdown
autocomplete.dropdown.focus.ring.style --p-autocomplete-dropdown-focus-ring-style Focus ring style of dropdown
autocomplete.dropdown.focus.ring.color --p-autocomplete-dropdown-focus-ring-color Focus ring color of dropdown
autocomplete.dropdown.focus.ring.offset --p-autocomplete-dropdown-focus-ring-offset Focus ring offset of dropdown
autocomplete.dropdown.focus.ring.shadow --p-autocomplete-dropdown-focus-ring-shadow Focus ring shadow of dropdown
autocomplete.dropdown.background --p-autocomplete-dropdown-background Background of dropdown
autocomplete.dropdown.hover.background --p-autocomplete-dropdown-hover-background Hover background of dropdown
autocomplete.dropdown.active.background --p-autocomplete-dropdown-active-background Active background of dropdown
autocomplete.dropdown.color --p-autocomplete-dropdown-color Color of dropdown
autocomplete.dropdown.hover.color --p-autocomplete-dropdown-hover-color Hover color of dropdown
autocomplete.dropdown.active.color --p-autocomplete-dropdown-active-color Active color of dropdown
autocomplete.chip.border.radius --p-autocomplete-chip-border-radius Border radius of chip
autocomplete.chip.focus.background --p-autocomplete-chip-focus-background Focus background of chip
autocomplete.chip.focus.color --p-autocomplete-chip-focus-color Focus color of chip
autocomplete.empty.message.padding --p-autocomplete-empty-message-padding Padding of empty message

더 알아보기 (Learn more)

  • AutoComplete 서브 컴포넌트의 세부 API를 Primitive 문서에서 살펴보세요.
  • forceSelection과 그룹 옵션을 조합해 검증된 다중 선택 검색 UI를 만들어 보세요.