รายการตัวเลือกมาตรฐาน
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
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "หน่วยงาน" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| placeholder | "เลือกหน่วยงาน" | string | A first, empty choice, such as เลือกหน่วยงาน. |
| options* จำเป็น | รายการ 12 รายการ[
{ 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: "หน่วยงาน ฏ" },
] | readonly NativeOption[] | The choices, in order. |
| value | value | string | The chosen value, when the screen keeps it. |
| onValueChange | setValue | (next: string) => void | Hears the chosen value. |
| required | true | boolean | Marks the label with a red star, and the control as required. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| id | string | — | The select's id. One is made when it's left out. |
| label | string | — | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| hint | string | — | Help under the field, such as the format or a limit. |
| error | string | — | What's wrong and how to fix it, shown under the field. It marks the field invalid. |
| required | boolean | — | Marks the label with a red star, and the control as required. |
| options* จำเป็น | readonly NativeOption[] | — | The choices, in order. |
| placeholder | string | — | A first, empty choice, such as เลือกหน่วยงาน. |
| value | string | — | The chosen value, when the screen keeps it. |
| defaultValue | string | "" | 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.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| 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