도크
도크 (Dock)
도크는 메뉴 아이템들로 이루어진 내비게이션 컴포넌트예요. macOS 독처럼 화면 가장자리에 아이콘을 나열해 자주 쓰는 기능에 빠르게 접근할 수 있게 해줘요. 이 문서에서는 기본 사용법부터 스크린 리더와 키보드 지원 같은 접근성, Props·Emits·템플릿으로 구성된 API, 패스 스루 옵션과 테마까지 차근차근 설명해요. 데스크톱 UI를 흉내 낸 고급 예제도 포함되어 있어서 실전 활용법을 익히기 좋아요
출처: 문서
본문
접근성
스크린 리더 Dock 컴포넌트는 menu role을 aria-orientation과 함께 사용해요. 메뉴를 설명하는 값은 aria-labelledby 또는 aria-label props로 제공할 수 있어요. 각 리스트 항목은 presentation role을 가지는 반면, 앵커 엘리먼트는 menuitem role을 가져요. 이때 aria-label은 항목의 라벨을 참조하고, 항목이 비활성화된 경우에는 aria-disabled가 정의돼요. 키보드 지원 키 기능 tab 메뉴로 포커스가 들어오면 첫 번째 항목에 포커스를 추가해요. 포커스가 이미 메뉴 안에 있다면, 페이지 탭 시퀀스에서 다음 포커스 가능한 항목으로 포커스가 이동해요. shift + tab 메뉴로 포커스가 들어오면 마지막 항목에 포커스를 추가해요. 포커스가 이미 메뉴 안에 있다면, 페이지 탭 시퀀스에서 이전 포커스 가능한 항목으로 포커스가 이동해요. enter 포커스된 menuitem을 활성화해요. space 포커스된 menuitem을 활성화해요. down arrow 세로 레이아웃에서 다음 menuitem으로 포커스를 이동해요. up arrow 세로 레이아웃에서 이전 menuitem으로 포커스를 이동해요. home 가로 레이아웃에서 첫 번째 menuitem으로 포커스를 이동해요. end 가로 레이아웃에서 마지막 menuitem으로 포커스를 이동해요.
고급
Dock을 비롯한 다양한 컴포넌트로 구현한 모의 데스크톱 UI예요.
import { Component, OnInit, inject } from '@angular/core';
import { DialogModule } from 'primeng/dialog';
import { DockModule } from 'primeng/dock';
import { GalleriaModule } from 'primeng/galleria';
import { MenubarModule } from 'primeng/menubar';
import { TerminalModule } from 'primeng/terminal';
import { ToastModule } from 'primeng/toast';
import { TreeModule } from 'primeng/tree';
import { TooltipModule } from 'primeng/tooltip';
import { NodeService } from '@/service/nodeservice';
import { PhotoService } from '@/service/photoservice';
import { MenuItem, MessageService } from 'primeng/api';
@Component({
template: `
<div class="card dock-demo">
<p-menubar [model]="menubarItems">
<ng-template #start>
<i class="pi pi-apple px-2"></i>
</ng-template>
<ng-template #end>
<i class="pi pi-video px-2"></i>
<i class="pi pi-wifi px-2"></i>
<i class="pi pi-volume-up px-2"></i>
<span class="px-2">Fri 13:07</span>
<i class="pi pi-search px-2"></i>
<i class="pi pi-bars px-2"></i>
</ng-template>
</p-menubar>
<div class="dock-window">
<p-dock [model]="dockItems" position="bottom">
<ng-template #item let-item>
<a [pTooltip]="item.label" tooltipPosition="top" class="p-dock-item-link">
<img [alt]="item.label" [src]="item.icon" style="width: 100%" />
</a>
</ng-template>
</p-dock>
<p-toast position="top-center" key="tc" />
<p-dialog [(visible)]="displayFinder" [breakpoints]="{ '960px': '50vw' }" [style]="{ width: '30vw', height: '18rem' }" [draggable]="false" [resizable]="false" header="Finder">
<p-tree [value]="nodes" />
</p-dialog>
<p-dialog [maximizable]="true" [(visible)]="displayTerminal" [breakpoints]="{ '960px': '50vw' }" [style]="{ width: '30vw' }" [draggable]="false" [resizable]="false" header="Terminal">
<p-terminal welcomeMessage="Welcome to PrimeNG (cmd: 'date', 'greet {0}', 'random')" prompt="primeng $" />
</p-dialog>
<p-galleria
[(value)]="images"
[showThumbnails]="false"
[showThumbnailNavigators]="false"
[showItemNavigators]="true"
[(visible)]="displayGalleria"
[circular]="true"
[responsiveOptions]="responsiveOptions"
[circular]="true"
[fullScreen]="true"
[containerStyle]="{ width: '400px' }"
>
<ng-template #item let-item>
<img [src]="item.itemImageSrc" style="width: 100%; display: block;" />
</ng-template>
</p-galleria>
</div>
</div>
`,
standalone: true,
imports: [DialogModule, DockModule, GalleriaModule, MenubarModule, TerminalModule, ToastModule, TreeModule, TooltipModule],
providers: [NodeService, PhotoService, MessageService]
})
export class DockAdvancedDemo implements OnInit {
private nodeService = inject(NodeService);
private photoService = inject(PhotoService);
private messageService = inject(MessageService);
displayTerminal: boolean | undefined;
displayFinder: boolean | undefined;
displayGalleria: boolean | undefined;
dockItems: MenuItem[] | undefined;
menubarItems: any[] | undefined;
responsiveOptions: any[] | undefined;
images: any[] | undefined;
nodes: any[] | undefined;
subscription: Subscription | undefined;
ngOnInit() {
this.dockItems = [
{
label: 'Finder',
tooltipOptions: {
tooltipLabel: 'Finder',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/finder.svg',
command: () => {
this.displayFinder = true;
}
},
{
label: 'Terminal',
tooltipOptions: {
tooltipLabel: 'Terminal',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/terminal.svg',
command: () => {
this.displayTerminal = true;
}
},
{
label: 'App Store',
tooltipOptions: {
tooltipLabel: 'App Store',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/appstore.svg',
url: 'https://www.apple.com/app-store/'
},
{
label: 'Safari',
tooltipOptions: {
tooltipLabel: 'Safari',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/safari.svg'
},
{
label: 'Photos',
tooltipOptions: {
tooltipLabel: 'Photos',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/photos.svg',
command: () => {
this.displayGalleria = true;
}
},
{
label: 'GitHub',
tooltipOptions: {
tooltipLabel: 'GitHub',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/github.svg',
url: 'https://github.com/primefaces/primeng'
},
{
label: 'Trash',
tooltipOptions: {
tooltipLabel: 'Trash',
tooltipPosition: 'top',
positionTop: -15,
positionLeft: 15,
showDelay: 1000
},
icon: 'https://primefaces.org/cdn/primeng/images/dock/trash.png',
command: () => {
this.messageService.add({ severity: 'info', summary: 'Trash is empty', key: 'tc' });
}
}
];
this.menubarItems = [
{
label: 'Finder',
styleClass: 'menubar-root'
},
{
label: 'File',
items: [
{
label: 'New',
icon: 'pi pi-fw pi-plus',
items: [
{
label: 'Bookmark',
icon: 'pi pi-fw pi-bookmark'
},
{
label: 'Video',
icon: 'pi pi-fw pi-video'
}
]
},
{
label: 'Delete',
icon: 'pi pi-fw pi-trash'
},
{
separator: true
},
{
label: 'Export',
icon: 'pi pi-fw pi-external-link'
}
]
},
{
label: 'Edit',
items: [
{
label: 'Left',
icon: 'pi pi-fw pi-align-left'
},
{
label: 'Right',
icon: 'pi pi-fw pi-align-right'
},
{
label: 'Center',
icon: 'pi pi-fw pi-align-center'
},
{
label: 'Justify',
icon: 'pi pi-fw pi-align-justify'
}
]
},
{
label: 'Users',
items: [
{
label: 'New',
icon: 'pi pi-fw pi-user-plus'
},
{
label: 'Delete',
icon: 'pi pi-fw pi-user-minus'
},
{
label: 'Search',
icon: 'pi pi-fw pi-users',
items: [
{
label: 'Filter',
icon: 'pi pi-fw pi-filter',
items: [
{
label: 'Print',
icon: 'pi pi-fw pi-print'
}
]
},
{
icon: 'pi pi-fw pi-bars',
label: 'List'
}
]
}
]
},
{
label: 'Events',
items: [
{
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
items: [
{
label: 'Save',
icon: 'pi pi-fw pi-calendar-plus'
},
{
label: 'Delete',
icon: 'pi pi-fw pi-calendar-minus'
}
]
},
{
label: 'Archieve',
icon: 'pi pi-fw pi-calendar-times',
items: [
{
label: 'Remove',
icon: 'pi pi-fw pi-calendar-minus'
}
]
}
]
},
{
label: 'Quit'
}
];
this.responsiveOptions = [
{
breakpoint: '1024px',
numVisible: 3
},
{
breakpoint: '768px',
numVisible: 2
},
{
breakpoint: '560px',
numVisible: 1
}
];
this.subscription = this.terminalService.commandHandler.subscribe((command) => this.commandHandler(command));
this.galleriaService.getImages().then((data) => (this.images = data));
this.nodeService.getFiles().then((data) => (this.nodes = data));
}
commandHandler(text: any) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
switch (command) {
case 'date':
response = 'Today is ' + new Date().toDateString();
break;
case 'greet':
response = 'Hola ' + text.substring(argsIndex + 1) + '!';
break;
case 'random':
response = Math.floor(Math.random() * 100);
break;
default:
response = 'Unknown command: ' + command;
break;
}
if (response) {
this.terminalService.sendResponse(response as string);
}
}
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}
기본
Dock는 menuitems 컬렉션을 model로 필요로 해요. 기본 위치는 bottom이고, position 프로퍼티로 정의하면 다른 방향도 사용할 수 있어요. dock 컴포넌트의 콘텐츠는 item 템플릿으로 정의해요.
import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { DockModule } from 'primeng/dock';
import { RadioButtonModule } from 'primeng/radiobutton';
import { TooltipModule } from 'primeng/tooltip';
import { MenuItem } from 'primeng/api';
@Component({
template: `
<div class="card">
<div class="flex flex-wrap gap-4 mb-8">
<div *ngFor="let pos of positionOptions" class="flex items-center">
<p-radiobutton name="dock" [value]="pos.value" [label]="pos.label" [(ngModel)]="position" [inputId]="pos.label" />
<label [for]="pos.label" class="ml-2"> {{ pos.label }} </label>
</div>
</div>
<div class="dock-window">
<p-dock [model]="items" [position]="position">
<ng-template #item let-item>
<img [pTooltip]="item.label" tooltipPosition="top" [src]="item.icon" [alt]="item.label" width="100%" />
</ng-template>
</p-dock>
</div>
</div>
`,
standalone: true,
imports: [DockModule, RadioButtonModule, TooltipModule, FormsModule]
})
export class DockBasicDemo implements OnInit {
items: MenuItem[] | undefined;
positionOptions: any[];
ngOnInit() {
this.items = [
{
label: 'Finder',
icon: 'https://primefaces.org/cdn/primeng/images/dock/finder.svg'
},
{
label: 'App Store',
icon: 'https://primefaces.org/cdn/primeng/images/dock/appstore.svg'
},
{
label: 'Photos',
icon: 'https://primefaces.org/cdn/primeng/images/dock/photos.svg'
},
{
label: 'Trash',
icon: 'https://primefaces.org/cdn/primeng/images/dock/trash.png'
}
];
}
}
Dock
Dock는 menuitems로 구성된 내비게이션 컴포넌트예요.
Props
| 이름 | 타입 | 기본값 | 설명 |
|---|---|---|---|
| dt | InputSignal | undefined | 컴포넌트의 스코프 디자인 토큰을 정의해요. |
| unstyled | InputSignal | undefined | 컴포넌트를 스타일 없이 렌더링할지 여부를 나타내요. |
| pt | InputSignal | undefined | 컴포넌트 내부의 DOM 요소에 속성을 전달할 때 사용해요. |
| ptOptions | InputSignal | undefined | 컴포넌트의 passthrough(pt) 옵션을 구성할 때 사용해요. |
| id | string | - | 문자열 형태의 현재 id 상태예요. |
| styleClass | string | - | 요소의 클래스예요. (지원 중단) |
| model | MenuItem[] | null | 액션 아이템을 정의하는 MenuModel 인스턴스예요. |
| position | "right" | "left" | "top" | "bottom" | bottom | 요소의 위치예요. |
| ariaLabel | string | - | 접근성을 위해 입력 요소를 라벨링하는 문자열을 정의해요. |
| breakpoint | string | 960px | 최대 너비 경계를 정의하는 브레이크포인트예요. |
| ariaLabelledBy | string | - | 접근성을 위해 드롭다운 버튼을 라벨링하는 문자열을 정의해요. |
Emits
| 이름 | 파라미터 | 설명 |
|---|---|---|
| onFocus | event: FocusEvent | 버튼이 포커스를 받을 때 실행되는 콜백이에요. |
| onBlur | event: FocusEvent | 컴포넌트가 포커스를 잃을 때 호출되는 콜백이에요. |
Templates
| 이름 | 타입 | 설명 |
|---|---|---|
| item | TemplateRef | 커스텀 item 템플릿이에요. |
Pass Through Options
| 이름 | 타입 | 설명 |
|---|---|---|
| root | PassThroughOption<HTMLElement, I> | root의 DOM 요소에 속성을 전달할 때 사용해요. |
| listContainer | PassThroughOption<HTMLDivElement, I> | list container의 DOM 요소에 속성을 전달할 때 사용해요. |
| list | PassThroughOption<HTMLUListElement, I> | list의 DOM 요소에 속성을 전달할 때 사용해요. |
| item | PassThroughOption<HTMLLIElement, I> | item의 DOM 요소에 속성을 전달할 때 사용해요. |
| itemContent | PassThroughOption<HTMLDivElement, I> | item content의 DOM 요소에 속성을 전달할 때 사용해요. |
| itemLink | PassThroughOption<HTMLAnchorElement, I> | item link의 DOM 요소에 속성을 전달할 때 사용해요. |
| itemIcon | PassThroughOption<HTMLSpanElement, I> | item icon의 DOM 요소에 속성을 전달할 때 사용해요. |
Theming
CSS Classes
| 클래스 | 설명 |
|---|---|
| p-dock | root 요소의 클래스 이름이에요 |
| p-dock-list-container | list container 요소의 클래스 이름이에요 |
| p-dock-list | list 요소의 클래스 이름이에요 |
| p-dock-item | item 요소의 클래스 이름이에요 |
| p-dock-item-content | item content 요소의 클래스 이름이에요 |
| p-dock-item-link | item link 요소의 클래스 이름이에요 |
| p-dock-item-icon | item icon 요소의 클래스 이름이에요 |
Design Tokens
| 토큰 | CSS 변수 | 설명 |
|---|---|---|
| dock.background | --p-dock-background | root의 배경이에요 |
| dock.border.color | --p-dock-border-color | root의 테두리 색상이에요 |
| dock.padding | --p-dock-padding | root의 패딩이에요 |
| dock.border.radius | --p-dock-border-radius | root의 테두리 반경이에요 |
| dock.item.border.radius | --p-dock-item-border-radius | item의 테두리 반경이에요 |
| dock.item.padding | --p-dock-item-padding | item의 패딩이에요 |
| dock.item.size | --p-dock-item-size | item의 크기예요 |
| dock.item.focus.ring.width | --p-dock-item-focus-ring-width | item의 포커스 링 너비예요 |
| dock.item.focus.ring.style | --p-dock-item-focus-ring-style | item의 포커스 링 스타일이에요 |
| dock.item.focus.ring.color | --p-dock-item-focus-ring-color | item의 포커스 링 색상이에요 |
| dock.item.focus.ring.offset | --p-dock-item-focus-ring-offset | item의 포커스 링 오프셋이에요 |
| dock.item.focus.ring.shadow | --p-dock-item-focus-ring-shadow | item의 포커스 링 그림자예요 |
더 알아보기 (Learn more)
이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.