导航

v2.1.0
应用区块

表格视图

带搜索、筛选、选行和分页的表格。

表格视图包含操作表格所需的各项功能:标题和主要操作、筛选和排序、选择、行操作及分页。各项功能由组件提供,区块负责把这些组件组织在同一块面板上。

表格视图

<section class="sheet container-inline flex flex-col overflow-hidden" data-example="table-view" aria-labelledby="tv-title">  <header class="flex flex-wrap items-center justify-between gap-sm p-md">    <div class="flex flex-col gap-3xs">      <h2 class="heading heading-sm" id="tv-title">Atlas Labs</h2>      <p class="m(0) fg-text-muted" id="tv-summary">24 projects</p>    </div>    <div class="flex flex-wrap items-center gap-xs">      <div class="segmented segmented-sm" role="radiogroup" aria-label="Show">        <label class="segmented-item">          <input type="radio" class="segmented-input" name="tv-set" value="projects" checked>Projects</label>        <label class="segmented-item">          <input type="radio" class="segmented-input" name="tv-set" value="people">People</label>        <label class="segmented-item">          <input type="radio" class="segmented-input" name="tv-set" value="files">Files</label>      </div>      <button type="button" class="btn btn-primary btn-sm" id="tv-action">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M3 8L13 8" />          <path d="M8 3L8 13" />        </svg>        <span>New project</span>      </button>    </div>  </header>  <div class="flex flex-wrap items-center gap-xs px-md pb-md">    <label class="input-group input-group-sm grow(1) basis(200) max-w(320)">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="7" cy="7" r="4.5" />        <path d="M10.182 10.182L14 14" />      </svg>      <input class="input-group-field" type="search" id="tv-search" placeholder="Search projects" aria-label="Search projects" autocomplete="off">    </label>    <button type="button" class="btn btn-sm" popovertarget="tv-filters" data-filter="open">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" />      </svg>Filters      <span data-filter="count" aria-hidden="true" hidden>        <span class="badge badge-sm badge-ink badge-pill">0</span>      </span>    </button>    <select class="select select-raised select-sm ml-auto" id="tv-sort" aria-label="Sort by"></select>    <div class="w-full" data-filter="applied" hidden>      <div class="flex flex-wrap items-center gap-xs">        <ul class="flex flex-wrap gap-xs m(0) p(0)" aria-label="Applied filters" data-filter="chips"></ul>        <button type="button" class="btn btn-quiet btn-sm" data-filter="clear-all">Clear all</button>      </div>    </div>  </div>  <div class="popover p(0) w(560)" id="tv-filters" popover role="dialog" aria-labelledby="tv-filters-title" style="--popover-max-width: min(36rem, calc(100vw - 2rem))" data-filter="panel">    <form class="flex flex-col" data-filter="form" novalidate>      <header class="flex flex-col gap-3xs px-md pt-md pb-sm">        <h3 class="heading heading-xs" id="tv-filters-title">Filter projects</h3>        <p class="m(0) fg-text-muted" id="tv-filters-hint">A project shows when it meets every condition.</p>      </header>      <ul class="flex flex-col gap-xs m(0) px-md py-xs" data-filter="conditions"></ul>      <p class="m(0) px-md py-xs fg-text-muted" data-filter="empty">No conditions yet: every row shows.</p>      <p class="m(0) px-md py-xs fg-danger" id="tv-filters-error" role="alert" data-filter="error" hidden></p>      <div class="px-md pb-md">        <button type="button" class="btn btn-quiet btn-sm" data-filter="add">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M3 8L13 8" />            <path d="M8 3L8 13" />          </svg>Add condition</button>      </div>      <footer class="flex flex-wrap items-center justify-between gap-xs p-md bt(1) bt-solid b-line-hair">        <button type="button" class="btn btn-quiet btn-sm" data-filter="clear">Clear</button>        <div class="flex gap-xs">          <button type="button" class="btn btn-sm" data-filter="cancel">Cancel</button>          <button type="submit" class="btn btn-primary btn-sm">Apply</button>        </div>      </footer>    </form>  </div>  <div class="scroll-area scroll-area-inline bt(1) bt-solid b-line-hair">    <table class="table table-interactive" id="tv-table" aria-labelledby="tv-title">      <thead id="tv-head"></thead>      <tbody id="tv-body"></tbody>    </table>  </div>  <footer class="flex flex-wrap items-center justify-between gap-sm p-md bt(1) bt-solid b-line-hair">    <div class="flex flex-wrap items-center gap-xs min-h(32)">      <p class="m(0) fg-text-muted" id="tv-count">No projects selected</p>      <div id="tv-selected" hidden>        <div class="flex items-center gap-3xs">          <button type="button" class="btn btn-quiet btn-sm btn-danger" id="tv-delete">Delete</button>          <button type="button" class="btn btn-quiet btn-sm" id="tv-deselect">Clear selection</button>        </div>      </div>    </div>    <div class="flex flex-wrap items-center gap-sm">      <p class="m(0) fg-text-muted whitespace-nowrap" id="tv-range">1–8 of 24</p>      <nav aria-label="Pagination">        <ol class="pagination" id="tv-pages"></ol>      </nav>    </div>  </footer>  <p class="sr-only" role="status" id="tv-status"></p>  <template data-filter="row">    <li class="flex flex-wrap items-center gap-xs">      <span class="w(44) shrink(0) fg-text-muted text-end" data-part="joiner">Where</span>      <select class="select select-sm" aria-label="Field" data-part="field"></select>      <select class="select select-sm" aria-label="Comparison" data-part="operator"></select>      <input class="input input-sm grow(1) basis(128) min-w(0)" aria-label="Value" data-part="value" required>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove condition" data-part="remove">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M4 4L12 12" />          <path d="M4 12L12 4" />        </svg>      </button>    </li>  </template>  <template data-filter="choice">    <select class="select select-sm grow(1) basis(128)" aria-label="Value" data-part="value"></select>  </template>  <template data-filter="chip">    <li>      <span class="chip">        <span class="chip-label"></span>        <button type="button" class="chip-remove" aria-label="Remove the filter">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M4 4L12 12" />            <path d="M4 12L12 4" />          </svg>        </button>      </span>    </li>  </template>  <template id="tv-head-projects">    <table class="table">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">            <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all projects">          </th>          <th class="table-heading" scope="col" data-sort="name">Project</th>          <th class="table-heading" scope="col">Status</th>          <th class="table-heading" scope="col">Region</th>          <th class="table-heading table-numeric" scope="col" data-sort="deployments">Deployments</th>          <th class="table-heading" scope="col" data-sort="deployed">Last deployed</th>          <th class="table-heading" scope="col">            <span class="sr-only">Actions</span>          </th>        </tr>      </thead>    </table>  </template>  <template id="tv-row-projects">    <table class="table">      <tbody>        <tr class="table-row">          <td class="table-cell">            <input type="checkbox" class="checkbox" data-part="select" aria-label="Select">          </td>          <th class="table-cell table-primary" scope="row">            <span data-part="name"></span>            <span class="block fg-text-muted font-regular" data-part="domain"></span>          </th>          <td class="table-cell">            <span class="badge badge-dot" data-part="status"></span>          </td>          <td class="table-cell" data-part="region"></td>          <td class="table-cell table-numeric" data-part="deployments"></td>          <td class="table-cell whitespace-nowrap" data-part="deployed"></td>          <td class="table-cell text-end" data-part="actions"></td>        </tr>      </tbody>    </table>  </template>  <template id="tv-head-people">    <table class="table">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">            <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all people">          </th>          <th class="table-heading" scope="col" data-sort="name">Person</th>          <th class="table-heading" scope="col">Role</th>          <th class="table-heading" scope="col">Status</th>          <th class="table-heading table-numeric" scope="col" data-sort="projects">Projects</th>          <th class="table-heading" scope="col" data-sort="active">Last active</th>          <th class="table-heading" scope="col">            <span class="sr-only">Actions</span>          </th>        </tr>      </thead>    </table>  </template>  <template id="tv-row-people">    <table class="table">      <tbody>        <tr class="table-row">          <td class="table-cell">            <input type="checkbox" class="checkbox" data-part="select" aria-label="Select">          </td>          <th class="table-cell table-primary" scope="row">            <span class="flex items-center gap-sm">              <span class="avatar avatar-sm" aria-hidden="true" data-part="initials"></span>              <span class="min-w(0)">                <span class="block" data-part="name"></span>                <span class="block fg-text-muted font-regular" data-part="email"></span>              </span>            </span>          </th>          <td class="table-cell" data-part="role"></td>          <td class="table-cell">            <span class="badge badge-dot" data-part="status"></span>          </td>          <td class="table-cell table-numeric" data-part="projects"></td>          <td class="table-cell whitespace-nowrap" data-part="active"></td>          <td class="table-cell text-end" data-part="actions"></td>        </tr>      </tbody>    </table>  </template>  <template id="tv-head-files">    <table class="table">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">            <input type="checkbox" class="checkbox" data-part="all" aria-label="Select all files">          </th>          <th class="table-heading" scope="col" data-sort="name">File</th>          <th class="table-heading" scope="col">Type</th>          <th class="table-heading table-numeric" scope="col" data-sort="size">Size</th>          <th class="table-heading" scope="col" data-sort="modified">Modified</th>          <th class="table-heading" scope="col">Owner</th>          <th class="table-heading" scope="col">            <span class="sr-only">Actions</span>          </th>        </tr>      </thead>    </table>  </template>  <template id="tv-row-files">    <table class="table">      <tbody>        <tr class="table-row">          <td class="table-cell">            <input type="checkbox" class="checkbox" data-part="select" aria-label="Select">          </td>          <th class="table-cell table-primary" scope="row">            <span class="flex items-center gap-sm">              <span class="icon-frame icon-frame-xs" aria-hidden="true">                <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">                  <path d="M4.5 2L9.0858 2A1 1 0 0 1 9.7929 2.2929L12.2071 4.7071A1 1 0 0 1 12.5 5.4142L12.5 13A1 1 0 0 1 11.5 14L4.5 14A1 1 0 0 1 3.5 13L3.5 3A1 1 0 0 1 4.5 2Z" />                  <path d="M10 2.5V4.4A0.1 0.1 0 0 0 10.1 4.5H12L12.2409 4.7427A0.9993 0.9993 0 0 1 12.5 5.4142V5.5H10.1Q9.6444 5.5 9.3222 5.1778Q9 4.8556 9 4.4V2A1.1002 1.1002 0 0 1 9.3761 2.0431A1.0001 1.0001 0 0 1 9.7929 2.2929L10 2.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" />                </svg>              </span>              <span class="min-w(0) truncate" data-part="name"></span>            </span>          </th>          <td class="table-cell" data-part="type"></td>          <td class="table-cell table-numeric" data-part="size"></td>          <td class="table-cell whitespace-nowrap" data-part="modified"></td>          <td class="table-cell whitespace-nowrap" data-part="owner"></td>          <td class="table-cell text-end" data-part="actions"></td>        </tr>      </tbody>    </table>  </template>  <template id="tv-actions">    <div>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Actions">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <circle cx="3.5" cy="8" r="1.05" fill="currentColor" stroke="none" />          <circle cx="8" cy="8" r="1.05" fill="currentColor" stroke="none" />          <circle cx="12.5" cy="8" r="1.05" fill="currentColor" stroke="none" />        </svg>      </button>      <div class="menu menu-end" popover>        <a class="menu-item" href="#" data-part="open">Open</a>        <hr class="menu-separator">        <button type="button" class="menu-item menu-item-danger" data-part="delete">Delete</button>      </div>    </div>  </template>  <template id="tv-empty">    <table class="table">      <tbody>        <tr class="table-row">          <td class="table-cell" colspan="7">            <div class="empty">              <p class="empty-title" data-part="title">No projects match</p>              <p class="empty-description">Try another search, or remove a filter.</p>              <div class="empty-actions">                <button type="button" class="btn btn-sm" data-part="reset">Clear the search and the filters</button>              </div>            </div>          </td>        </tr>      </tbody>    </table>  </template>  <template id="tv-page">    <ol class="pagination">      <li>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Page"></button>      </li>    </ol>  </template>  <template id="tv-gap">    <ol class="pagination">      <li class="pagination-gap" aria-hidden="true">…</li>    </ol>  </template>  <template id="tv-previous">    <ol class="pagination">      <li>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Previous page">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />          </svg>        </button>      </li>    </ol>  </template>  <template id="tv-next">    <ol class="pagination">      <li>        <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Next page">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />          </svg>        </button>      </li>    </ol>  </template></section>
搜索、筛选、排序和翻页浏览项目,或切换到成员和文件。选中行后可以删除。

区块提供可直接复制的标记,沿用所在页面的文字颜色和字号。预览在 body 上设置 fg-text-body text-sm。每个区块都是尺寸容器,会根据自身宽度重排,无论放在宽页面、侧边栏大小的空间还是对话框中。

#区块组成

  • 一块面板。 各区域用细线 bt(1) bt-solid b-line-hair 分隔,避免在卡片内再套卡片。
  • 顶部标题区采用两端布局。 左侧是工作区名称和显示匹配行数的计数,右侧是在项目、成员和文件之间切换的分段控件以及主要操作。整体使用 flex flex-wrap items-center justify-between,面板较窄时,切换控件和主要操作移到标题下方。
  • 搜索、筛选和排序位于同一可换行的行中。 其中有宽度在 200px 到 320px 之间伸展的搜索输入组、筛选栏的按钮,以及用于选择排序方式的凸起下拉选择框,后者用 ml-auto 推到行尾。已应用的筛选条件在下方单独占一行,以胶囊标签显示,每个都可单独移除。
  • 排序状态直接显示在表头。 已排序列的列标题带有 aria-sort,表格会加深标题文字颜色,并显示尖角箭头;更改排序则通过下拉选择框。
  • 表格在自己的区域内滚动。 表格放在带有 scroll-area-inline 的滚动区域中,面板变窄时,横向滚动限定在表格内,仍有列可继续滚动查看的边缘会渐隐。
  • 每个数据集都有自己的首列单元格。 项目显示名称及其下方的域名,成员显示头像及旁边的姓名和邮箱,文件显示图标框及旁边的文件名。每个首列单元格都是 <th scope="row">,因此辅助技术读出单元格时会一并读出所在行。
  • 选择只针对匹配的行。 在 table-row 上设置 aria-selected="true",使该行呈现选中色调,同时勾选行内的复选框。表头复选框会选中所有页中与搜索和筛选条件匹配的每一行,只选中其中一部分时则处于 indeterminate 状态。不再匹配的行会退出选择,因此“已选 3 项,共 15 项”只统计当前匹配结果中的行。
  • 底部采用两端布局。 左侧是已选数量,有选中行时还会显示“删除”和“清除选择”;右侧是数据范围和由按钮组成的分页。到达首页或末页时,“上一页”或“下一页”会被禁用;页数较多时,保留第一页、最后一页以及当前页的相邻页,中间用省略号隔开。
  • 行操作收在菜单中,由行尾一个低调的按钮打开。按钮名称包含该行所显示的项目、成员或文件的名称,例如“Atlas 的操作”。
  • 没有匹配结果时会明确说明。 空状态填满表格主体,并提供返回的途径:清除搜索和筛选条件。

#哪些操作需要脚本

表格行是数据,因此示例中的 main.js 从 data.js 读取数据,写入标记中为每个数据集准备的模板:样式表和工具类来自标记,文字来自数据。它与筛选栏共用两个模块:query.js 对普通的行数据进行搜索、筛选、排序和分页,filters.js 负责运行筛选栏。在实际产品中,这些查询应交给你的数据源处理;区块只展示如何呈现每一种结果。没有脚本时,用 <form method="get"> 包住各区域:搜索框、下拉选择框和复选框会变成服务器可以处理的查询字符串,分页则变成链接。

#对选中行执行操作

示例只有一个针对选中行的操作,放在底部的已选数量旁边。如果有多个操作,就在浮动工具栏中显示已选数量、各项操作以及清除选择的入口。用 sticky bottom(16) 将工具栏放在面板底部,也可将其固定在视口底部;有选中行时显示工具栏。

对选中行执行操作

<div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected">  <span class="px-xs fg-text-strong">2 selected</span>  <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-sm">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M8 1.3333C4 4.6667 3.6667 8.6667 5.6667 12.3333H10.3333C12.3333 8.6667 12 4.6667 8 1.3333Z" /><circle cx="8" cy="6.6667" r="0.85" fill="currentColor" stroke="none" /><path d="M10.016 12.3333Q10.1079 12.4463 10.2446 12.5147L12.5342 13.6594A0.6999 0.6999 0 0 0 13.5377 13.1484L14.1443 9.5091Q14.1989 9.1824 13.9807 8.9328L11.9808 6.6473A0.7011 0.7011 0 0 0 11.3582 6.4146C11.5022 7.0678 11.5536 7.7269 11.5195 8.3865L11.635 7.7707L13.1346 9.4845L12.6181 12.5833L10.8942 11.7215L11.1203 10.5157C10.924 11.1275 10.6597 11.7349 10.3333 12.3333H10.016ZM4.6418 6.4146A0.6958 0.6958 0 0 0 4.0192 6.6473L2.0193 8.9328Q1.8012 9.1824 1.8557 9.5091L2.4623 13.1484A0.6999 0.6999 0 0 0 3.4658 13.6594L5.7554 12.5147Q5.8921 12.4463 5.984 12.3333H5.6667C5.3403 11.7349 5.076 11.1275 4.8797 10.5157L5.1058 11.7215L3.3819 12.5833L2.8654 9.4845L4.365 7.7707L4.4805 8.3865C4.4464 7.7269 4.4978 7.0678 4.6418 6.4146Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M6.6667 15L9.3333 15" />    </svg>Redeploy  </button>  <button type="button" class="btn btn-quiet btn-sm">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M8.5 9L8.4994 1.9755A0.5 0.5 0 0 0 7.5054 1.9266L7.5 2L7.5014 9.0379A0.5007 0.5007 0 0 0 7.5892 9.285A0.7044 0.7044 0 0 0 8.4108 9.285A0.4996 0.4996 0 0 0 8.5 9Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M5 6L7.8586 8.8586A0.2 0.2 0 0 0 8.1414 8.8586L11 6" /><path d="M2.5 10.5L2.5 12.5A1 1 0 0 0 3.5 13.5L12.5 13.5A1 1 0 0 0 13.5 12.5L13.5 10.5" />    </svg>Export  </button>  <button type="button" class="btn btn-quiet btn-sm btn-danger">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M2.5 4.5L13.5 4.5" /><path d="M4 4.5L4.4501 13.0526A1 1 0 0 0 5.4488 14L10.5512 14A1 1 0 0 0 11.5499 13.0526L12 4.5" /><path d="M6 4.5L6 3A1 1 0 0 1 7 2L9 2A1 1 0 0 1 10 3L10 4.5" /><path d="M8 7.5L8 11" />    </svg>Delete  </button>  <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></div>
import RocketIcon from '@master/icons-react/native/16/soft/rocket'import DownloadIcon from '@master/icons-react/native/16/soft/download'import TrashIcon from '@master/icons-react/native/16/soft/trash'import XIcon from '@master/icons-react/native/16/soft/x'<div className="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected">  <span className="px-xs fg-text-strong">2 selected</span>  <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" className="btn btn-quiet btn-sm">    <RocketIcon className="icon" />Redeploy  </button>  <button type="button" className="btn btn-quiet btn-sm">    <DownloadIcon className="icon" />Export  </button>  <button type="button" className="btn btn-quiet btn-sm btn-danger">    <TrashIcon className="icon" />Delete  </button>  <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection">    <XIcon className="icon" />  </button></div>
<script>  import RocketIcon from '@master/icons-svelte/native/16/soft/rocket'  import DownloadIcon from '@master/icons-svelte/native/16/soft/download'  import TrashIcon from '@master/icons-svelte/native/16/soft/trash'  import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected">  <span class="px-xs fg-text-strong">2 selected</span>  <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-sm"><RocketIcon class="icon" />Redeploy</button>  <button type="button" class="btn btn-quiet btn-sm"><DownloadIcon class="icon" />Export</button>  <button type="button" class="btn btn-quiet btn-sm btn-danger">    <TrashIcon class="icon" />Delete  </button>  <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection">    <XIcon class="icon" />  </button></div>
<script setup>import RocketIcon from '@master/icons-vue/native/16/soft/rocket'import DownloadIcon from '@master/icons-vue/native/16/soft/download'import TrashIcon from '@master/icons-vue/native/16/soft/trash'import XIcon from '@master/icons-vue/native/16/soft/x'</script><template>  <div class="toolbar toolbar-floating flex-wrap justify-center" role="toolbar" aria-label="2 projects selected">    <span class="px-xs fg-text-strong">2 selected</span>    <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>    <button type="button" class="btn btn-quiet btn-sm"><RocketIcon class="icon" />Redeploy</button>    <button type="button" class="btn btn-quiet btn-sm"><DownloadIcon class="icon" />Export</button>    <button type="button" class="btn btn-quiet btn-sm btn-danger">      <TrashIcon class="icon" />Delete    </button>    <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>    <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Clear the selection">      <XIcon class="icon" />    </button>  </div></template>

#无障碍

  • 面板是一个 <section>,以其标题作为无障碍名称,表格也以该标题命名。
  • 每个行内复选框的无障碍名称都包含该行所代表的对象名称,例如“选择 Atlas”。表头复选框的名称说明它会选中什么,例如“选择全部 15 个项目”。
  • 标题下方的计数是普通文本;另有一个 sr-only 的状态区域,用于说明操作的结果,例如“第 2 页,共 3 页”“已删除 3 个项目”。焦点停留在刚按下的控件上;如果该控件所在的行已不存在,焦点会移到表头复选框。
  • 操作列的列标题在视觉上隐藏,供辅助技术读取。
  • 分页使用带标签的 <nav>;由于各页会就地更改视图,页码使用按钮,当前页带有 aria-current="page"。
  • 每行的第一个单元格是 <th scope="row">,因此辅助技术会在读出单元格时一并读出对应的项目、成员或文件。
  • 筛选条件在名为“筛选项目”的弹出层中打开;其中各行和提示信息如何朗读,参见筛选栏。
  • 表格在滚动区域内横向滚动。表格中包含复选框和按钮,因此键盘用户可以通过它们访问表格。如果表格内没有可聚焦的元素,需要为滚动区域设置 tabindex="0"、角色和无障碍名称。