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

รายการตัวเลือกมาตรฐาน

NativeSelect

The browser's own select, for long plain lists on phones, where the phone's picker is easier than a menu. Use Select everywhere else: it has search-as-you-type, groups, details and icons.

ใช้รายการตัวเลือกของเบราว์เซอร์สำหรับรายการยาวแบบข้อความล้วนบนมือถือ ที่ตัวเลือกของโทรศัพท์ใช้ง่ายกว่าเมนู ที่อื่นทั้งหมดใช้ Select ซึ่งพิมพ์เพื่อค้นหา แบ่งกลุ่ม และมีคำอธิบายหรือไอคอนได้

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

ตัวอย่าง

รายการยาวบนมือถือ

placeholder เพิ่มตัวเลือกว่างอันแรก ถ้า required ตัวเลือกว่างนั้นเลือกไม่ได้

const [value, setValue] = useState("");

<NativeSelect
  label="หน่วยงาน"
  placeholder="เลือกหน่วยงาน"
  options={[
    { value: "u1", label: "หน่วยงาน ก" },
    { value: "u2", label: "หน่วยงาน ข" },
    { value: "u3", label: "หน่วยงาน ค" },
    { value: "u4", label: "หน่วยงาน ง" },
    { value: "u5", label: "หน่วยงาน จ" },
    { value: "u6", label: "หน่วยงาน ฉ" },
    { value: "u7", label: "หน่วยงาน ช" },
    { value: "u8", label: "หน่วยงาน ซ" },
    { value: "u9", label: "หน่วยงาน ฌ" },
    { value: "u10", label: "หน่วยงาน ญ" },
    { value: "u11", label: "หน่วยงาน ฎ" },
    { value: "u12", label: "หน่วยงาน ฏ" },
  ]}
  value={value}
  onValueChange={setValue}
  required
/>

props ทั้งหมด

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

NativeSelect props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
idstring—The select's id. One is made when it's left out.
labelstring—The visible label, already in the screen language. Every field needs one, unless the screen labels it another way.
hintstring—Help under the field, such as the format or a limit.
errorstring—What's wrong and how to fix it, shown under the field. It marks the field invalid.
requiredboolean—Marks the label with a red star, and the control as required.
options* จำเป็นreadonly NativeOption[]—The choices, in order.
placeholderstring—A first, empty choice, such as เลือกหน่วยงาน.
valuestring—The chosen value, when the screen keeps it.
defaultValuestring""The value chosen at first, when the select keeps it.
onValueChange(next: string) => void—Hears the chosen value.

รับ attribute ของ element HTML ต้นแบบได้ทั้งหมดด้วย เช่น id, name, required และ disabled

ชนิดข้อมูล

NativeOption

One choice in NativeSelect.

NativeOption fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
value* จำเป็นstring—What the choice means to the screen.
label* จำเป็นstring—The choice's text, already in the screen language.

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

  • ตัวเลือกเป็นข้อความล้วน ถ้าต้องมีคำอธิบายหรือไอคอน ใช้ Select

ซอร์สโค้ด: ui/src/choice-inputs.tsx