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

Sidebar

원문 보기 위키 갱신

Sidebar는 접이식 패널, 여러 변형 스타일, 조합 가능한 메뉴 구조를 가진 애플리케이션 내비게이션을 만들기 위한 styled가 없는 레이아웃 컴포넌트예요. 레이아웃, 메뉴, 접이식 섹션을 위한 compound 컴포넌트로 커스텀한 사이드바를 만들 수 있어요.

출처: 문서

본문

기능 (Features)

  • 하위 컴포넌트(Layout, Root, Spacer, Panel, Body, Header, Content, Footer, Group, GroupLabel, GroupContent, Menu, MenuItem, MenuButton, MenuAction, MenuBadge, MenuSub, MenuSubItem, MenuSubButton, Trigger, Rail, Inset, Backdrop)로 구성된 compound 컴포넌트 API
  • 세 가지 시각적 변형: sidebar, floating, inset
  • 세 가지 접이식 모드: icon, offcanvas, none
  • 왼쪽/오른쪽 위치 지정
  • Layout + id/target을 통한 다중 사이드바 지원
  • useMotion을 통한 애니메이션 확장/축소가 있는 접이식 메뉴 아이템
  • 설정 가능한 지연 시간의 호버 시 열기
  • 애니메이션 Backdrop을 사용한 오버레이 모드
  • 제어(controlled) 및 비제어(uncontrolled) 열기 상태

사용법 (Usage)

import { Sidebar } from 'primereact/sidebar';
<Sidebar.Layout>
    <Sidebar.Root id="main" collapsible="icon">
        <Sidebar.Spacer />
        <Sidebar.Aside>
            <Sidebar.Panel>
                <Sidebar.Header>...</Sidebar.Header>
                <Sidebar.Content>
                    <Sidebar.Group>
                        <Sidebar.GroupLabel>Navigation</Sidebar.GroupLabel>
                        <Sidebar.GroupContent>
                            <Sidebar.Menu>
                                <Sidebar.MenuItem>
                                    <Sidebar.MenuButton isActive>
                                        <HomeIcon />
                                        <span>Home</span>
                                    </Sidebar.MenuButton>
                                </Sidebar.MenuItem>
                            </Sidebar.Menu>
                        </Sidebar.GroupContent>
                    </Sidebar.Group>
                </Sidebar.Content>
                <Sidebar.Footer>...</Sidebar.Footer>
                <Sidebar.Rail />
            </Sidebar.Panel>
        </Sidebar.Aside>
    </Sidebar.Root>
    <Sidebar.Main>
        <Sidebar.Trigger />
        <main>Content</main>
    </Sidebar.Main>
</Sidebar.Layout>

동작 (Behavior)

다형적 렌더링 (Polymorphic Rendering)

아무 하위 컴포넌트에 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Sidebar.Trigger as="div">...</Sidebar.Trigger>

렌더 함수 자식 (Render Function Children)

하위 컴포넌트는 렌더 함수를 자식으로 받아 컴포넌트 인스턴스에 접근할 수 있게 해 줘요.

<Sidebar.Content>{(instance) => <div>{instance.sidebar?.state.open ? 'Open' : 'Closed'}</div>}</Sidebar.Content>

접이식 메뉴 아이템 (Collapsible Menu Items)

MenuItem에 collapsible prop을 추가하면 애니메이션 형태로 확장되는 서브메뉴를 만들 수 있어요.

<Sidebar.MenuItem collapsible defaultOpen={false}>
    <Sidebar.MenuButton>
        <FolderIcon />
        <span>Documents</span>
    </Sidebar.MenuButton>
    <Sidebar.MenuSub>
        <Sidebar.MenuSubItem>
            <Sidebar.MenuSubButton>Shared</Sidebar.MenuSubButton>
        </Sidebar.MenuSubItem>
    </Sidebar.MenuSub>
</Sidebar.MenuItem>

다중 사이드바 (Multi-Sidebar)

여러 개의 독립적인 사이드바를 위해 Layout에 id와 target props를 사용해요.

<Sidebar.Layout>
    <Sidebar.Root side="left" id="nav">
        ...
    </Sidebar.Root>
    <Sidebar.Main>
        <Sidebar.Trigger target="nav" />
        <Sidebar.Trigger target="tools" />
    </Sidebar.Main>
    <Sidebar.Root side="right" id="tools">
        ...
    </Sidebar.Root>
</Sidebar.Layout>

패스 스루 (Pass Through)

<DocPTViewer name="sidebar-pt" components={['SidebarRoot']} />

API

SidebarLayout

SidebarRoot

Attribute Value
data-state "expanded" | "collapsed"
data-variant "sidebar" | "floating" | "inset"
data-collapsible "offcanvas" | "icon" | "" (empty when expanded)
data-collapsible-mode "offcanvas" | "icon" | "none" (always present)
data-side "left" | "right"
data-overlay Present when overlay is true

SidebarSpacer

Label Type Description
root SidebarSpacerPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarAside

Label Type Description
root SidebarAsidePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarPanel

Label Type Description
root SidebarPanelPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarHeader

Label Type Description
root SidebarHeaderPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarContent

Label Type Description
root SidebarContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarFooter

Label Type Description
root SidebarFooterPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarGroup

Label Type Description
root SidebarGroupPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarGroupLabel

Label Type Description
root SidebarGroupLabelPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarGroupContent

Label Type Description
root SidebarGroupContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenu

Label Type Description
root SidebarMenuPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuItem

Attribute Value
data-open Present when the menu item is expanded
Label Type Description
root SidebarMenuItemPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuButton

Attribute Value
data-active "true" when the button is active
Label Type Description
root SidebarMenuButtonPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuAction

Label Type Description
root SidebarMenuActionPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuBadge

Label Type Description
root SidebarMenuBadgePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuSub

Label Type Description
root SidebarMenuSubPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuSubItem

Label Type Description
root SidebarMenuSubItemPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMenuSubButton

Attribute Value
data-active "true" when the button is active
data-size "sm" when small size is set
Label Type Description
root SidebarMenuSubButtonPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarTrigger

Label Type Description
root SidebarTriggerPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarRail

Label Type Description
root SidebarRailPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarMain

Label Type Description
root SidebarMainPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SidebarBackdrop

애니메이션 오버레이 렌더링을 위해 내부적으로 Backdrop 컴포넌트를 사용해요.

Label Type Description
root SidebarBackdropPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Sidebar는 기본적으로 navigation 랜드마크 역할을 사용해요. Trigger 요소가 사이드바의 열기 상태를 토글해요. 각 MenuItem은 상호작용 메뉴 아이템을 위해 button 역할을 사용해요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the next focusable element.
shift + tab Moves focus to the previous focusable element.
enter Activates the focused menu button or trigger.
space Activates the focused menu button or trigger.

더 알아보기 (Learn more)