ข้ามไปยังเนื้อหา

แท็บ

Tabs

Tabs for the parts of one record, such as details, items and history. Follows the ARIA tabs pattern: Left and Right move between tabs, Home and End jump to the first and last, and the tab chosen shows at once. Only the chosen tab is in the Tab order, so Tab moves from it into its panel.

ใช้แบ่งส่วนของรายการเดียวในหน้ารายละเอียด เช่น รายละเอียด รายการ ไฟล์แนบ และประวัติ ให้ผู้ใช้ดูทีละส่วน ส่งอาร์เรย์ของแท็บพร้อมเนื้อหา และเก็บแท็บที่เลือกไว้ใน state ของหน้าจอ ถ้าเป็นการเลือกมุมมองหรือตัวกรองของข้อมูลชุดเดียว ใช้ Segmented ถ้าทุกส่วนควรเห็นพร้อมกัน เช่น ในแผงดูเร็ว ใช้ RecordSection

import { Tabs } from "@bsru/ui";

ตัวอย่าง

ส่วนของคำขอซื้อ

แต่ละแท็บมี value label และ panel บอกจำนวนในชื่อแท็บเมื่อช่วยให้ตัดสินใจได้ว่าจะเปิดหรือไม่ เนื้อหาของแต่ละแท็บเป็นส่วนประกอบที่รับข้อมูล

หน่วยงาน
หน่วยงาน ก
ผู้ค้า
บริษัท ตัวอย่าง จำกัด
รหัสงบประมาณ
BG-2570-ก-001
ผู้ขอ
นายทดสอบ มีสุข
หมายเหตุ
ไม่มีข้อมูล
const [part, setPart] = useState("details");

<Tabs
  label="ส่วนของคำขอ"
  value={part}
  onChange={setPart}
  tabs={[
    { value: "details", label: "รายละเอียด", panel: <FieldList fields={fields} /> },
    {
      value: "items",
      label: `รายการ (${items.length})`,
      panel: (
        <LineItems
          caption="รายการในคำขอ PR-2570-0001"
          columns={columns}
          items={items}
          totalLabel="รวมทั้งสิ้น"
          total={150000}
        />
      ),
    },
    {
      value: "files",
      label: `ไฟล์แนบ (${files.length})`,
      panel: <AttachmentList files={files} downloadLabel="ดาวน์โหลด" />,
    },
    { value: "history", label: "ประวัติ", panel: <ApprovalChain levels={history} /> },
  ]}
/>

สองแท็บ

ใช้แท็บเมื่อมีอย่างน้อยสองส่วน ถ้ามีส่วนเดียวให้แสดงเนื้อหาเลยโดยไม่มีแท็บ

PR-2570-0001
รอรองอธิการบดีที่กำกับอนุมัติ
PR-2570-0005
รอหัวหน้าหน่วยงานอนุมัติ
const [value, setValue] = useState("open");

<Tabs
  label="งานของฉัน"
  value={value}
  onChange={setValue}
  tabs={[
    {
      value: "open",
      label: "รอดำเนินการ (2)",
      panel: <Component
        fields={[
          {
            label: "PR-2570-0001",
            value: "รอรองอธิการบดีที่กำกับอนุมัติ",
          },
          { label: "PR-2570-0005", value: "รอหัวหน้าหน่วยงานอนุมัติ" },
        ]}
      />,
    },
    {
      value: "done",
      label: "เสร็จแล้ว (1)",
      panel: <Component
        fields={[{ label: "PR-2570-0003", value: "อนุมัติแล้ว" }]}
      />,
    },
  ]}
/>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

Tabs props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—Names the tab list for screen readers.
tabs* จำเป็นreadonly TabItem<V>[]—The tabs, in order.
value* จำเป็นV—The value of the chosen tab.
onChange* จำเป็น(next: V) => void—Called with the tab's value when someone picks a tab, by click or by arrow key.
classNamestring—Classes for the wrapper, such as grid column spans.

ชนิดข้อมูล

TabItem

One tab and the panel it shows.

TabItem fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
value* จำเป็นV—Unique among the tabs. The screen keeps the chosen one in state.
label* จำเป็นReactNode—The tab's name, already in the screen language, such as รายการ (3).
panel* จำเป็นReactNode—What the tab shows, such as a FieldList.

ข้อควรปฏิบัติ

  • แป้นพิมพ์: ลูกศรซ้ายขวาย้ายแท็บและแสดงทันที Home และ End ไปแท็บแรกและสุดท้าย Tab ออกจากแถบแท็บเข้าสู่เนื้อหา
  • label ตั้งชื่อแถบแท็บให้โปรแกรมอ่านหน้าจอ ส่งในภาษาของหน้าจอ
  • value ต้องไม่ซ้ำกัน ถ้า value ไม่ตรงกับแท็บใด แท็บแรกจะถูกเลือก

ซอร์สโค้ด: ui/src/tabs.tsx