Skip to content

CSS: drawer-layout ​

.instui-drawer-layout — 一個分割佈局,具有可摺疊的側邊抽屜和可捲動的主要內容窗格。

-placement-end 與預設(start)都使用 flex-direction/inset-inline-* 邏輯屬性,而非 left/right,因此抽屜的側邊會自動遵循 direction/dir="rtl" — 不需要額外的 RTL 規則。

Source: drawer-layout.css

使用方法 ​

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/drawer-layout.css";

範例 ​

html
<div class="instui-drawer-layout" id="drawer" open>
  <div class="tray" role="region" aria-label="Course panel">導覽</div>
  <div class="content" role="region" aria-label="Course content">主要內容</div>
</div>

結構 ​

text
.instui-drawer-layout
  drawer-layout.tray (component)
  drawer-layout.content (component)
flowchart TD n0[".instui-drawer-layout"]:::cssdoc-root n1(["drawer-layout.tray"]):::cssdoc-component n2(["drawer-layout.content"]):::cssdoc-component n0 --> n1 n0 --> n2 click n1 "/api/css/drawer-layout.tray.md" click n2 "/api/css/drawer-layout.content.md" classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

修飾器 ​

修飾器說明
.-open即使未設定 open 屬性,也要顯示抽屜。
.-placement-end將抽屜停靠在 inline-end 側。
.-placement-start將抽屜停靠在 inline-start 側(預設;明確設定為此)。
.-should-overlay-trayInteraction — Render the tray as an overlay instead of shrinking content inline.

部件 ​

部件說明
.content主要窗格。
.tray側邊面板。

自訂屬性 ​

屬性型別預設說明
--pantoken-bp-md——覆蓋模式的寬度閾值(30em,可透過響應式工具設定主題)。

無障礙 ​

請為每個區域命名為 aria-label 或 aria-labelledby。InstUI 樣式的區域請使用 div,而非 <main role="region">。當托盤做為導覽使用時,請使用具名的 <nav>,或在托盤內放置一個。

條件品牌重塑(淺色)品牌重塑(深色)CanvasCanvas 高對比
less-contrast-stays-readableWCAG 2.2 1.4.3需要檢查需要檢查需要檢查需要檢查

頁面在 prefers-contrast: less 下會變更,但無法測得任何可見文字。

more-contrast-respectedWCAG 2.2 1.4.3、1.4.6需要檢查需要檢查需要檢查需要檢查

在 prefers-contrast: more 設定下,頁面會有所變化,但無法測量到可見文字。

reflow-at-320pxWCAG 2.2 1.4.10PassPassPassPass
text-spacing-no-clippingWCAG 2.2 1.4.12PassPassPassPass
螢幕閱讀器(模擬)品牌重塑(淺色)品牌重塑(深色)CanvasCanvas 高對比
AnnouncementsPassPassPassPass

這些自動化結果無法證明頁面符合 WCAG;仍需進行人工檢查。

瀏覽器支援 ​

  • 當本元素的 inline-size 降到 抽屜寬度 + --pantoken-bp-md 以下時,drawer-layout.tray/drawer-layout.content 成員會透過 @container 查詢自動切換到覆蓋模式。@pantoken/interactions 的行為還會切換 [should-overlay-tray]/.-should-overlay-tray(手動覆蓋),並釋出 overlaytraychange 事件,供需要此變更的應用使用。

子元件 ​

相關 ​

  • tray — 一個獨立的邊緣覆蓋;此佈局將抽屜與內容保留在相同流程中。
  • context-view — 一個較小的錨定面板,用於情境性操作與細節。