Side panel
Side panel เลื่อนเข้ามาจากขอบจอ ใต้ header ของ UI shell สูง 48px ใช้แสดงรายละเอียดหรือฟอร์มสั้น ๆ โดยที่หน้าเว็บยังมองเห็นอยู่ ตัวนี้คือ SidePanel ของ Carbon for IBM Products ถ้างานต้องใช้ทั้งหน้าจอ ให้ใช้ Tearsheet ถ้าเป็นการตัดสินใจสั้น ๆ ให้ใช้ Modal
panel เป็น position: fixed ตัวอย่างที่ใช้งานได้ด้านล่างจึงอยู่ในกล่องที่กัก panel ไว้ และตั้ง --ui-side-panel-top: 0px เพราะกล่องไม่มี header ด้านบน
แก้ไขเหตุการณ์
ฝ่ายการเงินแจ้งเมื่อ 8 ตุลาคม 2569
ต่ำ
สูง
ยกเลิก
บันทึก
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 420px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-open" >แก้ไขเหตุการณ์</ui-button ></div >
<ui-side-panel id ="side-panel-edit" heading ="เหตุการณ์ INC-2041" size ="sm" selector-initial-focus ="#side-panel-edit-title" >
<span slot ="subtitle" >ฝ่ายการเงินแจ้งเมื่อ 8 ตุลาคม 2569</span >
<div style ="display: grid; gap: 16px; padding-block: 16px" >
<ui-text-input id ="side-panel-edit-title" label ="หัวข้อ" value ="ส่งออกใบแจ้งหนี้ไม่ได้" ></ui-text-input >
<ui-select label ="ความสำคัญ" value ="high" >
<option value ="low" >ต่ำ</option >
<option value ="high" >สูง</option >
</ui-select >
<ui-text-area label ="หมายเหตุ" ></ui-text-area >
</div >
<ui-button slot ="actions" kind ="secondary" >ยกเลิก</ui-button >
<ui-button slot ="actions" >บันทึก</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-edit' );
document.getElementById ('side-panel-open' ).addEventListener ('click' , () => (panel.open = true ));
for (const button of panel.querySelectorAll ('[slot="actions"]' )) button.addEventListener ('click' , () => (panel.open = false ));
</script >
const [open, setOpen] = useState (false );
<UiButton onClick = {() => setOpen (true )}>แก้ไขเหตุการณ์</UiButton >
<UiSidePanel open = {open} heading = "เหตุการณ์ INC-2041" size = "sm" selectorInitialFocus = "#incident-title" onUiClose = {() => setOpen (false )}>
<span slot = "subtitle" >ฝ่ายการเงินแจ้งเมื่อ 8 ตุลาคม 2569</span >
<UiTextInput id = "incident-title" label = "หัวข้อ" value = "ส่งออกใบแจ้งหนี้ไม่ได้" />
<UiSelect label = "ความสำคัญ" value = "high" >…</UiSelect >
<UiTextArea label = "หมายเหตุ" />
<UiButton slot = "actions" kind = "secondary" onClick = {() => setOpen (false )}>ยกเลิก</UiButton >
<UiButton slot = "actions" onClick = {() => setOpen (false )}>บันทึก</UiButton >
</UiSidePanel >
const [open, setOpen] = useState (false );
<Button onClick = {() => setOpen (true )}>แก้ไขเหตุการณ์</Button >
<SidePanel
open = {open}
onRequestClose = {() => setOpen (false )}
heading = "เหตุการณ์ INC-2041"
subtitle = "ฝ่ายการเงินแจ้งเมื่อ 8 ตุลาคม 2569"
size = "sm"
selectorInitialFocus = "#incident-title"
actions = {[
{ label: 'ยกเลิก' , kind: 'secondary' , onClick : () => setOpen (false ) },
{ label: 'บันทึก' , onClick : () => setOpen (false ) },
]}
>
<TextInput id = "incident-title" label = "หัวข้อ" defaultValue = "ส่งออกใบแจ้งหนี้ไม่ได้" />
<Select label = "ความสำคัญ" defaultValue = "high" >…</Select >
<TextArea label = "หมายเหตุ" />
</SidePanel >
ติดตั้ง
npm shadcn · Web component shadcn · React + Tailwind คัดลอกเอง npm install @purpurabog/ui
npx shadcn@4 add @kanok-ui/side-panel
npx shadcn@4 add @kanok-ui/tw-side-panel
# Web component
# 1. ติดตั้ง dependency
npm install lit@^3.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/side-panel.json
# ไปไว้ที่ target ของมัน:
# components/ui/primitives/side-panel/side-panel.styles.ts
# components/ui/primitives/side-panel/side-panel.ts
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-action-set, core-modal, core-motion, core-overlay, core-position, icon-button, layer, shared-action-set, shared-element, shared-events, shared-field, shared-localize, shared-quiet-focus, tokens
# React + Tailwind
# 1. ติดตั้ง dependency
npm install @purpurabog/ui@^2.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-side-panel.json
# ไปไว้ที่ target ของมัน:
# components/ui/react-tw/side-panel.tsx
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-action-set, core-motion, core-position, tw-action-set, tw-i18n, tw-icon-button, tw-layer, tw-refs, tw-theme, tw-utils
npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง
วิธีใช้
HTML React React + Tailwind <script type ="module" >import '@purpurabog/ui/side-panel' ;</script >
<ui-button onclick ="document. getElementById ('incident').open = true " >แก้ไขเหตุการณ์</ui-button >
<ui-side-panel id ="incident" heading ="เหตุการณ์ INC-2041" >
<p >ส่งออกใบแจ้งหนี้ไม่ได้</p >
</ui-side-panel >
import { UiSidePanel } from '@purpurabog/ui/react' ;
<UiSidePanel open = {open} heading = "เหตุการณ์ INC-2041" onUiClose = {() => setOpen (false )}>
<p >ส่งออกใบแจ้งหนี้ไม่ได้</p >
</UiSidePanel >
import { SidePanel } from '@/components/ui/react-tw/side-panel' ;
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} heading = "เหตุการณ์ INC-2041" >
<p >ส่งออกใบแจ้งหนี้ไม่ได้</p >
</SidePanel >
ตั้ง open เพื่อแสดง และตั้งกลับเป็น false เพื่อซ่อน panel จะเลื่อนเข้ามา 320px จากขอบพร้อมค่อย ๆ ปรากฏ และออกแบบเดียวกัน (ครั้งละ 150ms ตาม Carbon) และไม่เคลื่อนไหวเลยถ้าผู้อ่านตั้งให้ลดการเคลื่อนไหว heading เป็นชื่อของ panel สำหรับ screen reader ด้วย ตอนเปิด โฟกัสจะไปที่ selector-initial-focus (selector ของ element ใน panel) ถ้าไม่ตั้งจะไปที่ช่องแรก ตอนปิดโฟกัสจะกลับไปที่ตัวเดิม
× กด Esc และคลิกที่ overlay จะขอปิดก่อน (ดู ขอยืนยันก่อนปิด ) และส่ง ui-close เมื่อ panel เลื่อนออกไปแล้ว React + Tailwind เป็นแบบ controlled: onRequestClose(reason) บอกเหตุผล แล้วคุณตั้ง open เป็น false
ขนาด
size: xs 16rem, sm 20rem, md 30rem (ค่าเริ่มต้น), lg 40rem, xl 65rem, 2xl 80rem ตั้งแต่จอขนาดกลางขึ้นไป panel จะกว้างไม่เกิน 75% ของจอ และไม่กว้างเกินกล่องที่อยู่
xs
sm
md
lg
บริษัท สยามโลจิสติกส์ จำกัด เลขประจำตัวผู้เสียภาษี 0105556000000
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 360px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="display: flex; flex-wrap: wrap; gap: 16px; padding: 16px" >
<ui-button kind ="tertiary" data-side-panel-size ="xs" >xs</ui-button >
<ui-button kind ="tertiary" data-side-panel-size ="sm" >sm</ui-button >
<ui-button kind ="tertiary" data-side-panel-size ="md" >md</ui-button >
<ui-button kind ="tertiary" data-side-panel-size ="lg" >lg</ui-button >
</div >
<ui-side-panel id ="side-panel-size" heading ="ข้อมูลผู้ขาย" >
<p >บริษัท สยามโลจิสติกส์ จำกัด เลขประจำตัวผู้เสียภาษี 0105556000000</p >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-size' );
for (const button of document.querySelectorAll ('[data-side-panel-size]' )) {
button.addEventListener ('click' , () => {
panel.size = button.dataset.sidePanelSize;
panel.heading = `ข้อมูลผู้ขาย (${ panel.size })` ;
panel.open = true ;
});
}
</script >
<UiSidePanel open = {open} size = "xs" heading = "ข้อมูลผู้ขาย" onUiClose = {() => setOpen (false )}>…</UiSidePanel >
<UiSidePanel open = {open} size = "lg" heading = "ข้อมูลผู้ขาย" onUiClose = {() => setOpen (false )}>…</UiSidePanel >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} size = "xs" heading = "ข้อมูลผู้ขาย" >…</SidePanel >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} size = "lg" heading = "ข้อมูลผู้ขาย" >…</SidePanel >
เข้าจากด้านซ้าย
placement="left" ทำให้ panel เลื่อนเข้ามาจากขอบต้นบรรทัดแทนขอบท้าย
ตัวกรอง
เปิดอยู่
รออนุมัติ
ปิดแล้ว
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="display: flex; justify-content: flex-end; padding: 16px" ><ui-button id ="side-panel-left-open" kind ="tertiary" >ตัวกรอง</ui-button ></div >
<ui-side-panel id ="side-panel-left" heading ="ตัวกรอง" placement ="left" size ="sm" >
<div style ="display: grid; gap: 16px; padding-block: 16px" >
<ui-checkbox >เปิดอยู่</ui-checkbox >
<ui-checkbox >รออนุมัติ</ui-checkbox >
<ui-checkbox >ปิดแล้ว</ui-checkbox >
</div >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-left' );
document.getElementById ('side-panel-left-open' ).addEventListener ('click' , () => (panel.open = true ));
</script >
<UiSidePanel open = {open} heading = "ตัวกรอง" placement = "left" size = "sm" onUiClose = {() => setOpen (false )}>
<UiCheckbox >เปิดอยู่</UiCheckbox >
<UiCheckbox >รออนุมัติ</UiCheckbox >
<UiCheckbox >ปิดแล้ว</UiCheckbox >
</UiSidePanel >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} heading = "ตัวกรอง" placement = "left" size = "sm" >
<Checkbox label = "เปิดอยู่" />
<Checkbox label = "รออนุมัติ" />
<Checkbox label = "ปิดแล้ว" />
</SidePanel >
หรี่หน้าเว็บ
include-overlay หรี่หน้าเว็บข้างหลัง panel และทำให้หน้าเว็บเลื่อนไม่ได้ คลิกที่ overlay จะขอปิด (overlay) ยกเว้นตั้ง prevent-close-on-click-outside
มอบหมายผู้ตรวจ
อนัญญา พ.
บุญมี ส.
ยกเลิก
มอบหมาย
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-overlay-open" >มอบหมายผู้ตรวจ</ui-button ></div >
<ui-side-panel id ="side-panel-overlay" heading ="มอบหมายผู้ตรวจ" include-overlay size ="sm" >
<div style ="padding-block: 16px" >
<ui-radio-group label ="ผู้ตรวจ" name ="reviewer" value ="ananya" >
<ui-radio value ="ananya" >อนัญญา พ.</ui-radio >
<ui-radio value ="boonmee" >บุญมี ส.</ui-radio >
</ui-radio-group >
</div >
<ui-button slot ="actions" kind ="secondary" >ยกเลิก</ui-button >
<ui-button slot ="actions" >มอบหมาย</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-overlay' );
document.getElementById ('side-panel-overlay-open' ).addEventListener ('click' , () => (panel.open = true ));
for (const button of panel.querySelectorAll ('[slot="actions"]' )) button.addEventListener ('click' , () => (panel.open = false ));
</script >
<UiSidePanel open = {open} heading = "มอบหมายผู้ตรวจ" includeOverlay size = "sm" onUiClose = {() => setOpen (false )}>
<UiRadioGroup label = "ผู้ตรวจ" name = "reviewer" value = "ananya" >…</UiRadioGroup >
<UiButton slot = "actions" kind = "secondary" onClick = {() => setOpen (false )}>ยกเลิก</UiButton >
<UiButton slot = "actions" onClick = {() => setOpen (false )}>มอบหมาย</UiButton >
</UiSidePanel >
<SidePanel
open = {open}
onRequestClose = {() => setOpen (false )}
heading = "มอบหมายผู้ตรวจ"
includeOverlay
size = "sm"
actions = {[
{ label: 'ยกเลิก' , kind: 'secondary' , onClick : () => setOpen (false ) },
{ label: 'มอบหมาย' , onClick : () => setOpen (false ) },
]}
>
<RadioGroup label = "ผู้ตรวจ" name = "reviewer" defaultValue = "ananya" >…</RadioGroup >
</SidePanel >
ดันหน้าเว็บออกไป
slide-in เปิดที่ให้ panel แทนการทับหน้าเว็บ: element ที่ selector-page-content ชี้ไปจะได้ margin กว้างเท่า panel panel แบบ slide-in ไม่ดึงโฟกัส ไม่กัก Tab ไว้ข้างใน และไม่ปิดด้วย Esc หน้าเว็บข้าง ๆ จึงยังใช้งานได้
รายการสัญญา: 24 ฉบับรอลงนาม
แสดงสรุป
ซื้อขาย 8 เช่า 12 บริการ 4 ฉบับ
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 300px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div id ="side-panel-page" style ="display: grid; gap: 16px; padding: 16px" >
<p style ="margin: 0" >รายการสัญญา: 24 ฉบับรอลงนาม</p >
<div ><ui-button id ="side-panel-push-open" kind ="tertiary" >แสดงสรุป</ui-button ></div >
</div >
<ui-side-panel id ="side-panel-push" heading ="สรุป" slide-in selector-page-content ="#side-panel-page" size ="xs" >
<p >ซื้อขาย 8 เช่า 12 บริการ 4 ฉบับ</p >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-push' );
document.getElementById ('side-panel-push-open' ).addEventListener ('click' , () => (panel.open = ! panel.open));
</script >
<main id = "contracts" >…</main >
<UiSidePanel open = {open} heading = "สรุป" slideIn selectorPageContent = "#contracts" size = "xs" onUiClose = {() => setOpen (false )}>
<p >ซื้อขาย 8 เช่า 12 บริการ 4 ฉบับ</p >
</UiSidePanel >
<main id = "contracts" >…</main >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} heading = "สรุป" slideIn selectorPageContent = "#contracts" size = "xs" >
<p >ซื้อขาย 8 เช่า 12 บริการ 4 ฉบับ</p >
</SidePanel >
ปุ่มด้านล่าง
<ui-button slot="actions"> ใส่ได้ถึงสี่ปุ่มที่ท้าย panel จัดวางแบบ ActionSet ของ Carbon ตามขนาดของ panel: เรียงในแถวเดียว หรือเรียงทีละแถวเมื่อ panel เป็น xs หรือ sm และเมื่อ panel md มีมากกว่าสองปุ่ม ปุ่มสูง 64px ส่วน condensed-actions ทำให้สูง 48px React + Tailwind รับปุ่มเป็นข้อมูลใน actions
สามปุ่ม
แบบกะทัดรัด
ใบขอซื้อ PR-2026-0318 จำนวน 128,500 บาท จากฝ่ายไอที
ยกเลิก
ส่งกลับ
อนุมัติ
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 380px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="display: flex; flex-wrap: wrap; gap: 16px; padding: 16px" >
<ui-button id ="side-panel-actions-open" kind ="tertiary" >สามปุ่ม</ui-button >
<ui-button id ="side-panel-actions-condensed" kind ="tertiary" >แบบกะทัดรัด</ui-button >
</div >
<ui-side-panel id ="side-panel-actions" heading ="อนุมัติคำขอ" size ="lg" >
<p >ใบขอซื้อ PR-2026-0318 จำนวน 128,500 บาท จากฝ่ายไอที</p >
<ui-button slot ="actions" kind ="ghost" >ยกเลิก</ui-button >
<ui-button slot ="actions" kind ="secondary" >ส่งกลับ</ui-button >
<ui-button slot ="actions" >อนุมัติ</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-actions' );
const show = (condensed) => {
panel.condensedActions = condensed;
panel.open = true ;
};
document.getElementById ('side-panel-actions-open' ).addEventListener ('click' , () => show (false ));
document.getElementById ('side-panel-actions-condensed' ).addEventListener ('click' , () => show (true ));
for (const button of panel.querySelectorAll ('[slot="actions"]' )) button.addEventListener ('click' , () => (panel.open = false ));
</script >
<UiSidePanel open = {open} heading = "อนุมัติคำขอ" size = "lg" condensedActions onUiClose = {() => setOpen (false )}>
<p >ใบขอซื้อ PR-2026-0318 จำนวน 128,500 บาท จากฝ่ายไอที</p >
<UiButton slot = "actions" kind = "ghost" onClick = {close}>ยกเลิก</UiButton >
<UiButton slot = "actions" kind = "secondary" onClick = {sendBack}>ส่งกลับ</UiButton >
<UiButton slot = "actions" onClick = {approve}>อนุมัติ</UiButton >
</UiSidePanel >
<SidePanel
open = {open}
onRequestClose = {() => setOpen (false )}
heading = "อนุมัติคำขอ"
size = "lg"
condensedActions
actions = {[
{ label: 'ยกเลิก' , kind: 'ghost' , onClick: close },
{ label: 'ส่งกลับ' , kind: 'secondary' , onClick: sendBack },
{ label: 'อนุมัติ' , onClick: approve },
]}
>
<p >ใบขอซื้อ PR-2026-0318 จำนวน 128,500 บาท จากฝ่ายไอที</p >
</SidePanel >
แถบเครื่องมือใต้ส่วนหัว
slot="action-toolbar" วางปุ่มเล็ก ๆ ใต้ส่วนหัว ปุ่มแรกแสดงข้อความ ปุ่มที่เหลือเป็นปุ่มไอคอน React + Tailwind ใส่ใน actionToolbar
เปิดสัญญา
เช่าสำนักงานชั้น 3
คัดลอกลิงก์
24 เดือน ตั้งแต่ 1 พฤศจิกายน 2569 เดือนละ 45,000 บาท
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 340px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-toolbar-open" kind ="tertiary" >เปิดสัญญา</ui-button ></div >
<ui-side-panel id ="side-panel-toolbar" heading ="CT-2026-0142" size ="md" >
<span slot ="subtitle" >เช่าสำนักงานชั้น 3</span >
<ui-button slot ="action-toolbar" kind ="ghost" size ="sm" >คัดลอกลิงก์</ui-button >
<ui-icon-button slot ="action-toolbar" kind ="ghost" size ="sm" label ="แก้ไขสัญญา" >
<svg viewBox ="0 0 16 16" ><path d ="m13.7 4.3-2-2a1 1 0 0 0-1.4 0L2 10.6V14h3.4l8.3-8.3a1 1 0 0 0 0-1.4ZM5 13H3v-2l6-6 2 2Zm7-7-2-2 1-1 2 2Z" /></svg >
</ui-icon-button >
<p >24 เดือน ตั้งแต่ 1 พฤศจิกายน 2569 เดือนละ 45,000 บาท</p >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-toolbar' );
document.getElementById ('side-panel-toolbar-open' ).addEventListener ('click' , () => (panel.open = true ));
</script >
import { Edit as EditIcon } from '@carbon/icons-react' ;
<UiSidePanel open = {open} heading = "CT-2026-0142" onUiClose = {() => setOpen (false )}>
<span slot = "subtitle" >เช่าสำนักงานชั้น 3</span >
<UiButton slot = "action-toolbar" kind = "ghost" size = "sm" >คัดลอกลิงก์</UiButton >
<UiIconButton slot = "action-toolbar" kind = "ghost" size = "sm" label = "แก้ไขสัญญา" ><EditIcon /></UiIconButton >
<p >24 เดือน ตั้งแต่ 1 พฤศจิกายน 2569 เดือนละ 45,000 บาท</p >
</UiSidePanel >
import { Edit as EditIcon } from '@carbon/icons-react' ;
<SidePanel
open = {open}
onRequestClose = {() => setOpen (false )}
heading = "CT-2026-0142"
subtitle = "เช่าสำนักงานชั้น 3"
actionToolbar = {<>
<Button kind = "ghost" size = "sm" >คัดลอกลิงก์</Button >
<IconButton kind = "ghost" size = "sm" label = "แก้ไขสัญญา" ><EditIcon /></IconButton >
</>}
>
<p >24 เดือน ตั้งแต่ 1 พฤศจิกายน 2569 เดือนละ 45,000 บาท</p >
</SidePanel >
หัวข้อที่ย่อลงเมื่อเลื่อน
เมื่อมี label-text subtitle หรือแถบเครื่องมือ และเนื้อหายาวพอให้เลื่อน label กับ subtitle จะค่อย ๆ จางหายเมื่อเลื่อน และหัวข้อจะย่อเป็นแถบเล็ก (ค่าเริ่มต้นของ Carbon) animate-title="false" ทำให้ส่วนหัวอยู่นิ่ง การตั้งให้ลดการเคลื่อนไหวก็ปิดลูกเล่นนี้ด้วย ลองเลื่อน panel ด้านล่าง
เปิดงานตรวจสอบ
ตอบทุกข้อก่อนส่ง
บันทึกร่าง
ส่ง
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 420px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-title-open" kind ="tertiary" >เปิดงานตรวจสอบ</ui-button ></div >
<ui-side-panel id ="side-panel-title" heading ="ตรวจสอบประจำปี 2569" label-text ="ตรวจสอบภายใน" size ="md" >
<span slot ="subtitle" >ตอบทุกข้อก่อนส่ง</span >
<div style ="display: grid; gap: 16px; padding-block: 16px" >
<ui-text-input label ="ผู้ตรวจสอบ" ></ui-text-input >
<ui-text-input label ="หน่วยงาน" ></ui-text-input >
<ui-text-area label ="สิ่งที่พบ" ></ui-text-area >
<ui-text-area label ="ความเสี่ยง" ></ui-text-area >
<ui-text-area label ="ข้อเสนอแนะ" ></ui-text-area >
</div >
<ui-button slot ="actions" kind ="secondary" >บันทึกร่าง</ui-button >
<ui-button slot ="actions" >ส่ง</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-title' );
document.getElementById ('side-panel-title-open' ).addEventListener ('click' , () => (panel.open = true ));
for (const button of panel.querySelectorAll ('[slot="actions"]' )) button.addEventListener ('click' , () => (panel.open = false ));
</script >
<UiSidePanel open = {open} heading = "ตรวจสอบประจำปี 2569" labelText = "ตรวจสอบภายใน" onUiClose = {() => setOpen (false )}>
<span slot = "subtitle" >ตอบทุกข้อก่อนส่ง</span >
…
</UiSidePanel >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} heading = "ตรวจสอบประจำปี 2569" labelText = "ตรวจสอบภายใน" subtitle = "ตอบทุกข้อก่อนส่ง" actions = {…}>
…
</SidePanel >
หลายขั้นตอน
panel ใช้ทำขั้นตอนสั้น ๆ ได้ current-step ที่มากกว่า 0 จะแสดงปุ่มย้อนกลับด้านบน กดแล้วจะส่ง ui-navigate-back (React + Tailwind ใช้ onNavigationBack) แล้วคุณเปลี่ยนขั้นตอนและเนื้อหาเอง เนื้อหาจะเลื่อนกลับขึ้นบนสุดเมื่อเปลี่ยนขั้นตอน
คำขอใหม่
ใบขอซื้อ
ขออนุมัติเดินทาง
ถัดไป
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 360px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-steps-open" >คำขอใหม่</ui-button ></div >
<ui-side-panel id ="side-panel-steps" heading ="เลือกแบบฟอร์ม" size ="sm" >
<div id ="side-panel-step-0" style ="padding-block: 16px" >
<ui-radio-group label ="แบบฟอร์ม" name ="template" value ="purchase" >
<ui-radio value ="purchase" >ใบขอซื้อ</ui-radio >
<ui-radio value ="travel" >ขออนุมัติเดินทาง</ui-radio >
</ui-radio-group >
</div >
<div id ="side-panel-step-1" hidden style ="padding-block: 16px" >
<ui-text-input label ="จำนวนเงิน" suffix-text ="บาท" ></ui-text-input >
</div >
<ui-button slot ="actions" id ="side-panel-steps-next" >ถัดไป</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-steps' );
const next = document.getElementById ('side-panel-steps-next' );
const step = (n) => {
panel.currentStep = n;
panel.heading = n ? 'รายละเอียดคำขอ' : 'เลือกแบบฟอร์ม' ;
document.getElementById ('side-panel-step-0' ).hidden = n !== 0 ;
document.getElementById ('side-panel-step-1' ).hidden = n !== 1 ;
next.textContent = n ? 'ส่ง' : 'ถัดไป' ;
};
document.getElementById ('side-panel-steps-open' ).addEventListener ('click' , () => {
step (0 );
panel.open = true ;
});
next.addEventListener ('click' , () => {
if (panel.currentStep === 0 ) step (1 );
else panel.open = false ;
});
panel.addEventListener ('ui-navigate-back' , () => step (panel.currentStep - 1 ));
</script >
const [step, setStep] = useState (0 );
<UiSidePanel open = {open} heading = {step ? 'รายละเอียดคำขอ' : 'เลือกแบบฟอร์ม' } currentStep = {step} onUiNavigateBack = {() => setStep (step - 1 )} onUiClose = {() => setOpen (false )}>
{step === 0 ? <TemplateStep /> : <DetailsStep />}
<UiButton slot = "actions" onClick = {() => (step === 0 ? setStep (1 ) : send ())}>{step ? 'ส่ง' : 'ถัดไป' }</UiButton >
</UiSidePanel >
const [step, setStep] = useState (0 );
<SidePanel
open = {open}
onRequestClose = {() => setOpen (false )}
heading = {step ? 'รายละเอียดคำขอ' : 'เลือกแบบฟอร์ม' }
currentStep = {step}
onNavigationBack = {() => setStep (step - 1 )}
actions = {[{ label: step ? 'ส่ง' : 'ถัดไป' , onClick : () => (step === 0 ? setStep (1 ) : send ()) }]}
>
{step === 0 ? <TemplateStep /> : <DetailsStep />}
</SidePanel >
ปุ่มย้อนกลับมีชื่อว่า "ย้อนกลับ" ตามภาษาของหน้า เปลี่ยนได้ด้วย navigation-back-icon-description
เนื้อหาเหนือและใต้หัวข้อ
slot="above-title" อยู่เหนือ label และหัวข้อ slot="below-title" อยู่ใต้ subtitle เช่น tag บอกสถานะ หรือช่องค้นหา React + Tailwind ไม่มีทั้งสองอย่าง ให้ใส่เนื้อหาไว้ต้น children ของ panel
เปิดคำขอ
โน้ตบุ๊กสำหรับฝ่ายไอที
อนุมัติแล้ว
128,500 บาท ชัยยา ร. อนุมัติเมื่อ 9 ตุลาคม 2569
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" ><ui-button id ="side-panel-slots-open" kind ="tertiary" >เปิดคำขอ</ui-button ></div >
<ui-side-panel id ="side-panel-slots" heading ="PR-2026-0318" size ="sm" >
<span slot ="subtitle" >โน้ตบุ๊กสำหรับฝ่ายไอที</span >
<div slot ="below-title" style ="padding-block-end: 16px" ><ui-tag type ="green" >อนุมัติแล้ว</ui-tag ></div >
<p >128,500 บาท ชัยยา ร. อนุมัติเมื่อ 9 ตุลาคม 2569</p >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-slots' );
document.getElementById ('side-panel-slots-open' ).addEventListener ('click' , () => (panel.open = true ));
</script >
<UiSidePanel open = {open} heading = "PR-2026-0318" size = "sm" onUiClose = {() => setOpen (false )}>
<span slot = "subtitle" >โน้ตบุ๊กสำหรับฝ่ายไอที</span >
<div slot = "below-title" ><UiTag type = "green" >อนุมัติแล้ว</UiTag ></div >
<p >128,500 บาท ชัยยา ร. อนุมัติเมื่อ 9 ตุลาคม 2569</p >
</UiSidePanel >
<SidePanel open = {open} onRequestClose = {() => setOpen (false )} heading = "PR-2026-0318" subtitle = "โน้ตบุ๊กสำหรับฝ่ายไอที" size = "sm" >
<Tag type = "green" >อนุมัติแล้ว</Tag >
<p >128,500 บาท ชัยยา ร. อนุมัติเมื่อ 9 ตุลาคม 2569</p >
</SidePanel >
ขอยืนยันก่อนปิด
× กด Esc และคลิกที่ overlay จะส่ง ui-request-close ซึ่งยกเลิกได้ และมี reason เป็น close-button, escape หรือ overlay เรียก preventDefault() เพื่อให้ panel เปิดค้างไว้ requestClose(reason) ใช้ถามแบบเดียวกันจากปุ่มของคุณเอง ส่วนการตั้ง open เป็น false จะปิดโดยไม่ถาม panel ด้านล่างปิดได้ด้วยปุ่มเสร็จสิ้นเท่านั้น
เปิดรายการตรวจ
ขอปิดด้วย:
ติ๊กให้ครบทุกข้อ แล้วกดเสร็จสิ้น
เสร็จสิ้น
HTML React React + Tailwind <div style ="transform: translateZ(0); position: relative; height: 300px; overflow: hidden; border: 1px solid var(--ui-hairline); --ui-side-panel-top: 0px" >
<div style ="padding: 16px" >
<ui-button id ="side-panel-guard-open" kind ="tertiary" >เปิดรายการตรวจ</ui-button >
<p >ขอปิดด้วย: <output id ="side-panel-guard-out" ></output ></p >
</div >
<ui-side-panel id ="side-panel-guard" heading ="รายการตรวจก่อนลงนาม" size ="sm" include-overlay >
<p >ติ๊กให้ครบทุกข้อ แล้วกดเสร็จสิ้น</p >
<ui-button slot ="actions" id ="side-panel-guard-done" >เสร็จสิ้น</ui-button >
</ui-side-panel >
</div >
<script type ="module" >
const panel = document.getElementById ('side-panel-guard' );
document.getElementById ('side-panel-guard-open' ).addEventListener ('click' , () => (panel.open = true ));
document.getElementById ('side-panel-guard-done' ).addEventListener ('click' , () => (panel.open = false ));
panel.addEventListener ('ui-request-close' , (event) => {
event.preventDefault ();
document.getElementById ('side-panel-guard-out' ).value = event.detail.reason;
});
</script >
<UiSidePanel open = {open} heading = "รายการตรวจก่อนลงนาม" includeOverlay onUiRequestClose = {(e) => { e.preventDefault (); setReason (e.detail.reason); }} onUiClose = {() => setOpen (false )}>
<p >ติ๊กให้ครบทุกข้อ แล้วกดเสร็จสิ้น</p >
<UiButton slot = "actions" onClick = {() => setOpen (false )}>เสร็จสิ้น</UiButton >
</UiSidePanel >
// onRequestClose แค่แจ้ง panel จะเปิดค้างจนกว่าคุณตั้ง open เป็น false
<SidePanel open = {open} onRequestClose = {setReason} heading = "รายการตรวจก่อนลงนาม" includeOverlay actions = {[{ label: 'เสร็จสิ้น' , onClick : () => setOpen (false ) }]}>
<p >ติ๊กให้ครบทุกข้อ แล้วกดเสร็จสิ้น</p >
</SidePanel >
ui-request-close และ ui-close bubble ขึ้นมา notification ที่อยู่ข้างในจึงส่ง event เหล่านี้ถึง panel ด้วย ต้องเช็กว่า event.target คือ panel ส่วน UiSidePanel ของ React เช็กให้แล้ว onUiRequestClose และ onUiClose ได้รับเฉพาะ event ของ panel เอง
hide-close-button เอาปุ่ม × ออก ถ้าใช้ ต้องมีทางอื่นให้ปิด panel ได้
คีย์บอร์ด
ปุ่ม
ทำอะไร
Tab / Shift+Tab
เลื่อนไปมาระหว่างช่องและปุ่มใน panel และวนอยู่ข้างใน (ยกเว้น slide-in)
Esc
ขอปิด (escape ยกเว้น slide-in) แล้วโฟกัสกลับไปที่ตัวที่เปิด panel
Accessibility
panel เป็น landmark complementary ที่ใช้ heading เป็นชื่อ
× มีชื่อว่า "ปิด" และปุ่มย้อนกลับมีชื่อว่า "ย้อนกลับ" ตามภาษาของหน้า พร้อม tooltip เปลี่ยนได้ด้วย close-icon-description และ navigation-back-icon-description
panel แบบ slide-over กัก Tab ไว้ข้างใน แต่หน้าเว็บข้างหลังไม่ได้เป็น inert ผู้ใช้ screen reader ยังอ่านไปถึงได้ด้วยปุ่มอ่านของตัวเอง ถ้าต้องกันไม่ให้เข้าถึงหน้าเว็บเลย ให้ใช้ Modal
ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Side panel
API
สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)
<ui-side-panel> · React UiSidePanel
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
open
open
boolean
false
placement
placement
'right' | 'left'
'right'
size
size
SidePanelSize
'md'
xs 16rem, sm 20rem, md 30rem, lg 40rem, xl 65rem, 2xl 80rem.
heading
heading
string
''
The heading (Carbon title); also the panel's accessible name.
label-text
labelText
string
''
A small label above the heading.
slide-in
slideIn
boolean
false
Push the page aside (selector-page-content) instead of covering it; no focus trap, no Esc.
include-overlay
includeOverlay
boolean
false
Dim the page; a click on it closes the panel (unless prevent-close-on-click-outside).
prevent-close-on-click-outside
preventCloseOnClickOutside
boolean
false
selector-initial-focus
selectorInitialFocus
string
''
What takes focus on open (a selector in the content), else the first control.
selector-page-content
selectorPageContent
string
''
The page element a slide-in panel pushes aside.
hide-close-button
hideCloseButton
boolean
false
close-icon-description
closeIconDescription
string
''
The × button's name and tooltip (default "Close", translated).
close-icon-tooltip-alignment
closeIconTooltipAlignment
Placement
'left'
navigation-back-icon-description
navigationBackIconDescription
string
''
The back button's name and tooltip (default "Back", translated).
current-step
currentStep
number
0
Above 0 shows the back button (a panel with steps).
condensed-actions
condensedActions
boolean
false
48px action buttons instead of 64px.
animate-title
animateTitle
boolean
true
Shrink the heading as the content scrolls (Carbon's default).
Method
Method
คำอธิบาย
requestClose(reason)
Asks to close (cancelable ui-request-close), then closes.
Event
Event
React
คำอธิบาย
ui-close
onUiClose
After it closed
ui-navigate-back
onUiNavigateBack
The back button (current-step > 0) was pressed
ui-request-close
onUiRequestClose
Cancelable; detail: { reason: 'escape' | 'close-button' | 'overlay' }
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The content
subtitle
Text under the heading
above-title
Content above the label and heading
below-title
Content under the subtitle
action-toolbar
Small buttons under the header (the first one with its label)
actions
The action buttons
CSS part
Part
คำอธิบาย
panel
The panel
overlay
The overlay of include-overlay
header
The header
heading
The heading
body
The content's box
actions
The row of action buttons
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-side-panel-top
Where the panel starts (default 3rem, under the UI shell header)
--ui-side-panel-radius
Corner radius of the edge facing the page (default 0; Kanok: 12px)
--ui-actions-gap
/ --ui-actions-padding - Gap between the action buttons and padding round them (default none: full-bleed buttons that touch; Kanok: 8px / 16px 20px)
--ui-actions-button-flex
flex of each action button (default: Carbon's widths by count; Kanok: their own width)
--ui-actions-button-align
/ --ui-actions-button-padding-top - Where a button's label sits (default: at the top, 16px in)
--ui-actions-stacked-direction
/ --ui-actions-stacked-wrap / --ui-actions-stacked-width - Where Carbon stacks the actions (narrow): flex-direction, flex-wrap and each button's width (default column-reverse, nowrap, 100%; Kanok: one row that wraps)