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

리스트박스

원문 보기 위키 갱신

리스트박스 (Listbox)

리스트박스(Listbox)는 항목 목록에서 하나 이상의 값을 선택할 때 사용하는 컴포넌트예요. 기본 선택 방식부터 체크박스 선택, 필터, 그룹화, 다중 선택, 드래그앤드롭, 가상 스크롤 같은 다양한 기능을 예제와 함께 설명해요. 접근성 속성, 템플릿 기반 폼과 리액티브 폼 연동, Props·Emits 같은 API와 테마 설정까지 문서 전반을 살펴볼 수 있어요

출처: 문서

본문

접근성

스크린 리더: 컴포넌트를 설명하는 값은 ariaLabelledBy 또는 ariaLabel props로 제공할 수 있어요. 리스트 요소는 listbox role을 가지며, 다중 선택이 활성화되면 true로 설정되는 aria-multiselectable 속성이 있어요. 각 리스트 항목은 option role을 가지며 aria-selected와 aria-disabled를 속성으로 가져요.

기본

Listbox는 options 컬렉션과 함께 ngModel 프로퍼티를 사용하는 제어 컴포넌트로 사용돼요. 옵션의 라벨과 값은 각각 optionLabel과 optionValue 프로퍼티로 정의해요. optionLabel의 기본 프로퍼티 이름은 label이고, optionValue는 value예요. optionValue를 생략하고 객체에 value 프로퍼티가 없으면 객체 자체가 옵션의 값이 돼요. 옵션이 문자열 배열처럼 단순 원시 값일 때는 optionLabel과 optionValue가 필요 없다는 점에 유의하세요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxBasicDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

체크박스

Listbox는 체크박스를 사용한 항목 선택을 지원해요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [(ngModel)]="selectedCity" [options]="cities" [multiple]="true" [checkbox]="true" optionLabel="name" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxCheckboxDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

체크마크

선택된 옵션을 강조하는 또 다른 방법으로 체크마크를 표시하는 방법도 있어요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [(ngModel)]="selectedCity" [options]="cities" optionLabel="name" [checkmark]="true" [highlightOnSelect]="false" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxCheckmarkDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

비활성화

disabled가 있으면 요소를 편집하거나 포커스할 수 없어요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" [disabled]="true" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxDisabledDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

dragdrop-doc

dragdrop 프로퍼티를 활성화하면 드래그 앤 드롭으로 항목 순서를 바꿀 수 있어요. @angular/cdk 패키지에 의존해요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" [dragdrop]="true" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxDragdropDemo implements OnInit {
    cities!: any[];
    selectedCity!: any;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

필터

ListBox는 filter 프로퍼티를 추가하면 활성화되는 내장 필터링 기능을 제공해요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" [filter]="true" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxFilterDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

그룹

중첩된 데이터 구조를 제공하면 옵션을 그룹으로 묶을 수 있어요.

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';
import { SelectItemGroup } from 'primeng/api';
import { Country } from '@/domain/customer';

interface Country {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="groupedCities" [group]="true" [(ngModel)]="selectedCountry" class="w-full md:w-56">
                <ng-template let-group #group>
                    <div class="flex items-center">
                        <img src="https://primefaces.org/cdn/primeng/images/demo/flag/flag_placeholder.png" [class]="'mr-2 flag flag-' + group.value" style="width: 20px" />
                        <span>{{ group.label }}</span>
                    </div>
                </ng-template>
            </p-listbox>
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxGroupDemo {
    groupedCities!: SelectItemGroup[];
    selectedCountry!: Country;

    constructor() {
        this.groupedCities = [
                    {
                        label: 'Germany',
                        value: 'de',
                        items: [
                            { label: 'Berlin', value: 'Berlin' },
                            { label: 'Frankfurt', value: 'Frankfurt' },
                            { label: 'Hamburg', value: 'Hamburg' },
                            { label: 'Munich', value: 'Munich' }
                        ]
                    },
                    {
                        label: 'USA',
                        value: 'us',
                        items: [
                            { label: 'Chicago', value: 'Chicago' },
                            { label: 'Los Angeles', value: 'Los Angeles' },
                            { label: 'New York', value: 'New York' },
                            { label: 'San Francisco', value: 'San Francisco' }
                        ]
                    },
                    {
                        label: 'Japan',
                        value: 'jp',
                        items: [
                            { label: 'Kyoto', value: 'Kyoto' },
                            { label: 'Osaka', value: 'Osaka' },
                            { label: 'Tokyo', value: 'Tokyo' },
                            { label: 'Yokohama', value: 'Yokohama' }
                        ]
                    }
                ];
    }
}

유효하지 않음

invalid 프로퍼티를 사용해 유효성 검사 실패를 나타내는 invalid 상태를 적용할 수 있고, Angular Forms와 통합할 수도 있어요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" class="w-full md:w-56" [invalid]="selectedCity === undefined" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxInvalidDemo implements OnInit {
    cities!: City[];
    selectedCity!: City;

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

다중 선택

ListBox는 기본적으로 하나의 항목만 선택할 수 있고, 하나 이상을 선택하려면 multiple 프로퍼티를 활성화하세요. 선택 사항인 metaKeySelection이 있으면 동작이 바뀌어서 새 항목을 선택하려면 meta 키를 누른 상태여야 해요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="cities" [(ngModel)]="selectedCities" optionLabel="name" [multiple]="true" [metaKeySelection]="false" class="w-full md:w-56" />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxMultipleDemo implements OnInit {
    cities!: City[];
    selectedCities!: City[];

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }
}

reactiveforms-doc

Listbox는 reactive forms와 함께 사용할 수도 있어요. 이 경우 formControlName 속성을 사용해서 컴포넌트를 폼 컨트롤에 바인딩해요.

import { Component, inject } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';
import { MessageModule } from 'primeng/message';
import { ToastModule } from 'primeng/toast';
import { ButtonModule } from 'primeng/button';
import { MessageService } from 'primeng/api';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <p-toast />
        <div class="card flex justify-center">
            <form [formGroup]="exampleForm" (ngSubmit)="onSubmit()" class="flex flex-col gap-4 sm:w-56">
                <div class="flex flex-col gap-1">
                    <p-listbox [options]="cities" formControlName="selectedCity" optionLabel="name" class="w-full md:w-56" [invalid]="isInvalid('selectedCity')" />
                    @if (isInvalid('selectedCity')) {
                        <p-message severity="error" size="small" variant="simple">City is required.</p-message>
                    }
                </div>
                <button pButton severity="secondary" type="submit"><span pButtonLabel>Submit</span></button>
            </form>
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, MessageModule, ToastModule, ButtonModule, ReactiveFormsModule]
})
export class ListboxReactiveformsDemo {
    messageService = inject(MessageService);
    exampleForm: FormGroup | undefined;
    formSubmitted: boolean = false;
    cities!: City[];

    constructor() {
        this.cities = [
                    { name: 'New York', code: 'NY' },
                    { name: 'Rome', code: 'RM' },
                    { name: 'London', code: 'LDN' },
                    { name: 'Istanbul', code: 'IST' },
                    { name: 'Paris', code: 'PRS' }
                ];
                this.exampleForm = this.fb.group({
                    selectedCity: ['', Validators.required]
                });
    }

    onSubmit() {
        this.formSubmitted = true;
        if (this.exampleForm.valid) {
            this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Form is submitted', life: 3000 });
            this.exampleForm.reset();
            this.formSubmitted = false;
        }
    }

    isInvalid(controlName: string) {
        const control = this.exampleForm.get(controlName);
        return control?.invalid && this.formSubmitted;
    }
}

템플릿

커스텀 콘텐츠를 지원하려면 item이라는 이름의 템플릿을 정의하세요. 이때 기본 로컬 템플릿 변수가 옵션을 참조해요.

import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';
import { Country } from '@/domain/customer';

interface Country {
    name: string;
    code: string;
}

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox [options]="countries" [(ngModel)]="selectedCountry" optionLabel="name" class="w-full md:w-56">
                <ng-template #item let-country>
                    <div class="flex items-center gap-2">
                        <img src="https://primefaces.org/cdn/primeng/images/demo/flag/flag_placeholder.png" [class]="'flag flag-' + country.code.toLowerCase()" style="width: 18px" />
                        <div>{{ country.name }}</div>
                    </div>
                </ng-template>
            </p-listbox>
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxTemplateDemo implements OnInit {
    countries!: Country[];
    selectedCountry!: Country;

    ngOnInit() {
        this.countries = [
            { name: 'Australia', code: 'AU' },
            { name: 'Brazil', code: 'BR' },
            { name: 'China', code: 'CN' },
            { name: 'Egypt', code: 'EG' },
            { name: 'France', code: 'FR' },
            { name: 'Germany', code: 'DE' },
            { name: 'India', code: 'IN' },
            { name: 'Japan', code: 'JP' },
            { name: 'Spain', code: 'ES' },
            { name: 'United States', code: 'US' }
        ];
    }
}

templatedrivenforms-doc

import { Component, OnInit, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';
import { MessageModule } from 'primeng/message';
import { ToastModule } from 'primeng/toast';
import { ButtonModule } from 'primeng/button';
import { MessageService } from 'primeng/api';

interface City {
    name: string;
    code: string;
}

@Component({
    template: `
        <p-toast />
        <div class="card flex justify-center">
            <form #exampleForm="ngForm" (ngSubmit)="onSubmit(exampleForm)" class="flex justify-center flex-col gap-4 md:w-56">
                <div class="flex flex-col gap-1">
                    <p-listbox #city="ngModel" [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" class="w-full md:w-56" [invalid]="city.invalid && exampleForm.submitted" name="city" required />
                    @if (city.invalid && exampleForm.submitted) {
                        <p-message severity="error" size="small" variant="simple">City is required.</p-message>
                    }
                </div>
                <button pButton severity="secondary" type="submit"><span pButtonLabel>Submit</span></button>
            </form>
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, MessageModule, ToastModule, ButtonModule, FormsModule]
})
export class ListboxTemplatedrivenformsDemo implements OnInit {
    messageService = inject(MessageService);
    selectedCity!: City;
    cities!: City[];

    ngOnInit() {
        this.cities = [
            { name: 'New York', code: 'NY' },
            { name: 'Rome', code: 'RM' },
            { name: 'London', code: 'LDN' },
            { name: 'Istanbul', code: 'IST' },
            { name: 'Paris', code: 'PRS' }
        ];
    }

    onSubmit(form: any) {
        if (form.valid) {
            this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Form Submitted', life: 3000 });
            form.resetForm();
        }
    }
}

가상 스크롤

VirtualScrolling은 뷰포트에 데이터의 일부만 표시하는 방식으로 옵션을 렌더링하는 효율적인 방법이에요. 아주 많은 수의 옵션을 다룰 때는 성능 문제를 피하기 위해 VirtualScrolling을 활성화하는 게 좋아요. 사용법은 간단해서 virtualScroll 속성을 true로 설정하고 virtualScrollItemSize를 정의해 아이템의 높이를 지정하기만 하면 돼요.

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ListboxModule } from 'primeng/listbox';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-listbox
                [options]="items"
                [(ngModel)]="selectedItems"
                [selectAll]="selectAll"
                [filter]="true"
                [checkbox]="true"
                optionLabel="label"
                [virtualScroll]="true"
                [virtualScrollItemSize]="40"
                [multiple]="true"
                [metaKeySelection]="false"
                (onSelectAllChange)="onSelectAllChange($event)"
                (onChange)="onChange($event)"
                scrollHeight="250px"
                [striped]="true"
                class="w-full md:w-56"
            />
        </div>
    `,
    standalone: true,
    imports: [ListboxModule, FormsModule]
})
export class ListboxVirtualscrollDemo {
    items: any = Array.from({ length: 100000 }, (_, i) => ({ label: `Item #${i}`, value: i }));
    selectedItems!: any[];
    selectAll: boolean = false;

    onSelectAllChange(event) {
        this.selectedItems = event.checked ? [...this.items] : [];
        this.selectAll = event.checked;
    }

    onChange(event) {
        const { value } = event;
        if (value) this.selectAll = value.length === this.items.length;
    }
}

Listbox

ListBox는 아이템 목록에서 하나 이상의 값을 선택할 때 사용해요.

프로퍼티

이름 타입 기본값 설명
dt InputSignal undefined 컴포넌트의 스코프 디자인 토큰을 정의해요.
unstyled InputSignal undefined 컴포넌트를 스타일 없이 렌더링할지 여부를 나타내요.
pt InputSignal undefined 컴포넌트 내부의 DOM 요소에 속성을 전달할 때 사용해요.
ptOptions InputSignal undefined 컴포넌트의 passthrough(pt) 옵션을 설정할 때 사용해요.
required InputSignalWithTransform<boolean, unknown> false 값이 반드시 있어야 해요(설정된 경우).
invalid InputSignalWithTransform<boolean, unknown> false 설정하면 컴포넌트가 invalid 상태 스타일을 가져야 함을 나타내요.
disabled InputSignalWithTransform<boolean, unknown> false 설정하면 컴포넌트가 disabled 상태 스타일을 가져야 함을 나타내요.
name InputSignal undefined 설정하면 입력의 이름을 지정해요.
id string - 컴포넌트의 고유 식별자예요.
searchMessage string '{0} results are available' 검색이 활성화되어 있을 때 표시할 텍스트예요. i18n 번역 설정의 전역 값을 기본값으로 사용해요.
emptySelectionMessage string 'No selected item' 필터링 결과가 없을 때 표시할 텍스트예요. i18n 번역 설정의 전역 값을 기본값으로 사용해요.
selectionMessage string '{0} items selected' 옵션이 선택되었을 때 숨겨진 접근성 필드에 표시할 텍스트예요. i18n 번역 설정의 전역 값을 기본값으로 사용해요.
autoOptionFocus boolean true 오버레이 패널이 표시될 때 첫 번째로 보이는 요소 또는 선택된 요소에 포커스를 맞출지 여부예요.
ariaLabel string - 접근성을 위해 입력을 라벨링하는 문자열을 정의해요.
selectOnFocus boolean false 활성화하면 포커스된 옵션이 선택돼요.
searchLocale boolean false 검색에 사용할 로케일이에요. 기본 로케일은 호스트 환경의 현재 로케일이에요.
focusOnHover boolean true 활성화하면 호버된 옵션에 포커스가 가요.
filterMessage string - 필터링 중에 표시할 텍스트예요.
filterFields any[] - 옵션을 필터링할 때 사용할 필드예요. 기본값은 optionLabel이에요.
lazy boolean false 데이터를 지연(lazy) 방식으로 로드하고 상호작용할지 정의해요.
virtualScroll boolean false 스크롤 중에 데이터를 필요할 때 로드할지 여부예요.
virtualScrollItemSize number - VirtualScrolling에서 목록 항목의 높이예요.
virtualScrollOptions ScrollerOptions - scroller 기능을 사용할지 여부예요. scroller 컴포넌트의 속성들을 객체 형태로 그 안에 지정할 수 있어요.
scrollHeight string 14rem 뷰포트의 높이(픽셀)예요. 목록의 높이가 이 값을 초과하면 스크롤바가 표시돼요.
tabindex number 0 탭 순서에서 요소의 인덱스예요.
multiple boolean false 설정하면 여러 값을 선택할 수 있어요.
styleClass string - 컨테이너의 스타일 클래스예요. (지원 중단)
listStyle { [klass: string]: any } - 목록 요소의 인라인 스타일이에요.
listStyleClass string - 목록 요소의 스타일 클래스예요.
readonly boolean false 설정하면 요소 값을 변경할 수 없어요.
checkbox boolean false 설정하면 체크박스로 항목을 선택할 수 있어요.
filter boolean false 설정하면 헤더에 필터 입력창이 표시돼요.
filterBy string - 필터링이 활성화되면 filterBy가 검색 대상이 될 필드(쉼표로 구분)를 결정해요.
filterMatchMode string contains 항목을 필터링하는 방식을 정의해요.
filterLocale string - 필터링에 사용할 로케일이에요. 기본 로케일은 호스트 환경의 현재 로케일이에요.
metaKeySelection boolean false 여러 항목을 선택하는 방식을 정의해요. true면 항목을 선택하거나 해제할 때 metaKey를 눌러야 하고, false로 설정하면 각 항목의 선택을 개별적으로 토글할 수 있어요. 터치 지원 기기에서는 metaKeySelection이 자동으로 꺼져요.
dataKey string - 옵션에서 값을 고유하게 식별하는 속성이에요.
showToggleAll boolean true multiple 모드에서 헤더 체크박스를 표시할지 여부예요.
optionLabel string - 옵션의 라벨 필드 이름이에요.
optionValue string - 옵션의 값 필드 이름이에요.
optionGroupChildren string items 옵션 그룹의 options 필드 이름이에요.
optionGroupLabel string label 옵션 그룹의 라벨 필드 이름이에요.
optionDisabled string | ((item: any) => boolean) - 옵션의 disabled 필드 이름이거나 disabled 상태를 판단하는 함수예요.
ariaFilterLabel string - 필터 입력창을 라벨링하는 문자열을 정의해요.
filterPlaceHolder string - 필터 입력창의 placeholder를 정의해요.
emptyFilterMessage string - 필터링 결과가 없을 때 표시할 텍스트예요.
emptyMessage string - 데이터가 없을 때 표시할 텍스트예요. i18n 번역 설정의 전역 값을 기본값으로 사용해요.
group boolean false 중첩된 옵션이 제공될 때 옵션을 그룹으로 표시할지 여부예요.
options any[] - 선택 가능한 옵션으로 표시할 selectitem 배열이에요.
filterValue string - 설정하면 필터가 이 값으로 표시돼요.
selectAll boolean - 모든 데이터가 선택되어 있는지 여부예요.
striped boolean false 행을 교대로 다른 색상으로 표시할지 여부예요.
highlightOnSelect boolean true 선택된 옵션에 highlight 클래스를 추가할지 여부예요.
checkmark boolean false 선택된 옵션을 체크 마크와 함께 표시할지 여부예요.
dragdrop boolean false 드래그앤드롭 기반 재정렬을 활성화할지 여부예요.
dropListData any[] - CDK drop list 데이터 바인딩에 사용할 배열이에요. 제공하지 않으면 options 배열을 사용해요.
fluid InputSignalWithTransform<boolean, unknown> undefined 활성화하면 컨테이너의 100% 너비를 차지해요.

이벤트

이름 파라미터 설명
onChange event: ListboxChangeEvent 값이 변경될 때 호출되는 콜백이에요.
onClick event: ListboxClickEvent 옵션이 클릭될 때 호출되는 콜백이에요.
onDblClick event: ListboxDoubleClickEvent 옵션이 더블 클릭될 때 호출되는 콜백이에요.
onFilter event: ListboxFilterEvent 데이터가 필터링될 때 호출되는 콜백이에요.
onFocus event: FocusEvent 컴포넌트가 포커스를 받을 때 호출되는 콜백이에요.
onBlur event: FocusEvent 컴포넌트가 포커스를 잃을 때 호출되는 콜백이에요.
onSelectAllChange event: ListboxSelectAllChangeEvent 모든 데이터가 선택될 때 호출되는 콜백이에요.
onLazyLoad event: ScrollerLazyLoadEvent 지연 로드 시 발생해요.
onDrop value: CdkDragDrop<string[], string[], any 항목이 드롭될 때 발생해요.

템플릿

이름 타입 설명
item TemplateRef<ListboxItemTemplateContext> 커스텀 항목 템플릿이에요.
group TemplateRef<ListboxGroupTemplateContext> 커스텀 그룹 템플릿이에요.
header TemplateRef<ListboxHeaderTemplateContext> 커스텀 헤더 템플릿이에요.
filter TemplateRef 커스텀 필터 템플릿이에요.
footer TemplateRef<ListboxFooterTemplateContext> 커스텀 푸터 템플릿이에요.
emptyfilter TemplateRef 커스텀 빈 필터 메시지 템플릿이에요.
empty TemplateRef 커스텀 빈 메시지 템플릿이에요.
filtericon TemplateRef 커스텀 필터 아이콘 템플릿이에요.
checkicon TemplateRef 커스텀 체크 아이콘 템플릿이에요.
checkmark TemplateRef 커스텀 체크마크 아이콘 템플릿이에요.
loader TemplateRef 커스텀 로더 템플릿이에요.

메서드

이름 파라미터 반환 타입 설명
updateModel value: any, event: any void 모델 값을 업데이트해요.

패스스루 옵션

이름 타입 설명
root PassThroughOption<HTMLDivElement, I> 루트의 DOM 요소에 속성을 전달할 때 사용해요.
header PassThroughOption<HTMLDivElement, I> 헤더의 DOM 요소에 속성을 전달할 때 사용해요.
pcCheckbox any Checkbox 컴포넌트에 속성을 전달할 때 사용해요.
pcFilterContainer any IconField 컴포넌트에 속성을 전달할 때 사용해요.
pcFilter any 필터 입력창의 DOM 요소에 속성을 전달할 때 사용해요.
pcFilterIconContainer any InputIcon 컴포넌트에 속성을 전달할 때 사용해요.
filterIcon PassThroughOption<SVGElement, I> 필터 아이콘의 DOM 요소에 속성을 전달할 때 사용해요.
hiddenFilterResult PassThroughOption<HTMLSpanElement, I> 숨겨진 필터 결과의 DOM 요소에 속성을 전달할 때 사용해요.
listContainer PassThroughOption<HTMLDivElement, I> 목록 컨테이너의 DOM 요소에 속성을 전달할 때 사용해요.
virtualScroller any VirtualScroller 컴포넌트에 속성을 전달할 때 사용해요.
list PassThroughOption<HTMLUListElement, I> 목록의 DOM 요소에 속성을 전달할 때 사용해요.
optionGroup PassThroughOption<HTMLLIElement, I, ListBoxContext> 옵션 그룹의 DOM 요소에 속성을 전달할 때 사용해요.
option PassThroughOption<HTMLLIElement, I, ListBoxContext> 옵션의 DOM 요소에 속성을 전달할 때 사용해요.
optionCheckIcon PassThroughOption<SVGElement, I> 옵션 체크 아이콘의 DOM 요소에 속성을 전달할 때 사용해요.
optionBlankIcon PassThroughOption<SVGElement, I> 옵션 빈(blank) 아이콘의 DOM 요소에 속성을 전달할 때 사용해요.
emptyMessage PassThroughOption<HTMLLIElement, I> 빈 메시지의 DOM 요소에 속성을 전달할 때 사용해요.
hiddenEmptyMessage PassThroughOption<HTMLSpanElement, I> 숨겨진 빈 메시지의 DOM 요소에 속성을 전달할 때 사용해요.
hiddenSelectedMessage PassThroughOption<HTMLSpanElement, I> 숨겨진 선택 메시지의 DOM 요소에 속성을 전달할 때 사용해요.
hiddenFirstFocusableEl PassThroughOption<HTMLSpanElement, I> 첫 번째 숨겨진 포커스 가능 요소에 속성을 전달할 때 사용해요.
hiddenLastFocusableEl PassThroughOption<HTMLSpanElement, I> 마지막 숨겨진 포커스 가능 요소에 속성을 전달할 때 사용해요.

테마

CSS 클래스

클래스 설명
p-listbox 루트 요소의 클래스 이름이에요
p-listbox-header 헤더 요소의 클래스 이름이에요
p-listbox-filter 필터 요소의 클래스 이름이에요
p-listbox-list-container 목록 컨테이너 요소의 클래스 이름이에요
p-listbox-list 목록 요소의 클래스 이름이에요
p-listbox-option-group 옵션 그룹 요소의 클래스 이름이에요
p-listbox-option 옵션 요소의 클래스 이름이에요
p-listbox-option-check-icon 옵션 체크 아이콘 요소의 클래스 이름이에요
p-listbox-option-blank-icon 옵션 빈(blank) 아이콘 요소의 클래스 이름이에요
p-listbox-empty-message 빈 메시지 요소의 클래스 이름이에요

디자인 토큰

토큰 CSS 변수 설명
listbox.background --p-listbox-background 루트의 배경
listbox.disabled.background --p-listbox-disabled-background 루트의 비활성화 배경
listbox.border.color --p-listbox-border-color 루트의 테두리 색상
listbox.invalid.border.color --p-listbox-invalid-border-color 루트의 유효하지 않은 테두리 색상
listbox.color --p-listbox-color 루트의 색상
listbox.disabled.color --p-listbox-disabled-color 루트의 비활성화 색상
listbox.shadow --p-listbox-shadow 루트의 그림자
listbox.border.radius --p-listbox-border-radius 루트의 테두리 반경
listbox.transition.duration --p-listbox-transition-duration 루트의 전환 지속 시간
listbox.list.padding --p-listbox-list-padding 리스트의 패딩
listbox.list.gap --p-listbox-list-gap 리스트의 간격
listbox.list.header.padding --p-listbox-list-header-padding 리스트의 헤더 패딩
listbox.option.focus.background --p-listbox-option-focus-background 옵션의 포커스 배경
listbox.option.selected.background --p-listbox-option-selected-background 옵션의 선택 배경
listbox.option.selected.focus.background --p-listbox-option-selected-focus-background 옵션의 선택 포커스 배경
listbox.option.color --p-listbox-option-color 옵션의 색상
listbox.option.focus.color --p-listbox-option-focus-color 옵션의 포커스 색상
listbox.option.selected.color --p-listbox-option-selected-color 옵션의 선택 색상
listbox.option.selected.focus.color --p-listbox-option-selected-focus-color 옵션의 선택 포커스 색상
listbox.option.padding --p-listbox-option-padding 옵션의 패딩
listbox.option.border.radius --p-listbox-option-border-radius 옵션의 테두리 반경
listbox.option.striped.background --p-listbox-option-striped-background 옵션의 줄무늬 배경
listbox.option.group.background --p-listbox-option-group-background 옵션 그룹의 배경
listbox.option.group.color --p-listbox-option-group-color 옵션 그룹의 색상
listbox.option.group.font.weight --p-listbox-option-group-font-weight 옵션 그룹의 글꼴 두께
listbox.option.group.padding --p-listbox-option-group-padding 옵션 그룹의 패딩
listbox.checkmark.color --p-listbox-checkmark-color 체크마크의 색상
listbox.checkmark.gutter.start --p-listbox-checkmark-gutter-start 체크마크의 거터 시작
listbox.checkmark.gutter.end --p-listbox-checkmark-gutter-end 체크마크의 거터 끝
listbox.empty.message.padding --p-listbox-empty-message-padding 빈 메시지의 패딩

더 알아보기 (Learn more)

이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.