ช่องวันที่
DateInput
A field that picks a day, a day and time, a month, a week or a range of days from the guide's own calendar, instead of the browser's. Its colours follow the guide, and its words follow LangProvider: Thai shows the Buddhist year, such as 8 ธ.ค. 2569, and English the Gregorian year. The value is always ISO text with the Gregorian year, so it goes to the core API as it is: date 2026-12-08, datetime 2026-12-08T09:30, month 2026-12, week 2026-W50, and range 2026-12-15/2026-12-19, which the first click starts and the second ends, as when booking a hotel. An empty string means nothing is picked. Weeks are ISO weeks, Monday to Sunday, so the calendar starts on Monday.
ใช้เลือกวัน วันและเวลา เดือน สัปดาห์ หรือช่วงวันที่ ปฏิทินเป็นของไลบรารี ไม่ใช่ของเบราว์เซอร์ สีจึงตรงกับคู่มือ และคำตามภาษาของหน้าจอ ภาษาไทยแสดงปี พ.ศ. ภาษาอังกฤษแสดงปี ค.ศ. ค่าเป็นข้อความ ISO ปี ค.ศ. เสมอ ส่งให้ core API ได้ตรง ๆ ใช้แทน TextInput ที่ type เป็น date datetime-local month หรือ week
import { DateInput } from "@bsru/ui";ตัวอย่าง
วันที่
kind เป็น date โดยค่าเริ่มต้น ค่าเป็นวันที่ ISO เช่น 2026-12-15 ช่องแสดง 15 ธ.ค. 2569 ในภาษาไทย และ 15 Dec 2026 ในภาษาอังกฤษ min ทำให้วันก่อนหน้ากดไม่ได้ ลองสลับภาษาที่แถบด้านบน
ต้องไม่ก่อนวันที่ 1 ธ.ค. 2569
const [value, setValue] = useState("2026-12-15");
<DateInput
label="วันที่ต้องการใช้"
value={value}
onValueChange={setValue}
min="2026-12-01"
hint="ต้องไม่ก่อนวันที่ 1 ธ.ค. 2569"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "วันที่ต้องการใช้" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
| min | "2026-12-01" | string | The earliest value people can pick, in the same ISO form as value, or a day such as 2026-12-01 for range. Earlier days can't be pressed. |
| hint | "ต้องไม่ก่อนวันที่ 1 ธ.ค. 2569" | string | Help under the field, such as the format or a limit. |
วันและเวลา
kind datetime มีปฏิทินและเวลาแบบ 24 ชั่วโมง ค่าเป็น 2026-12-08T09:30 รายการนาทีเว้นทีละ minuteStep นาที ค่าเริ่มต้น 5 ค่าที่ไม่ตรงช่วงยังแสดงได้ กด เสร็จ เพื่อปิด
const [value, setValue] = useState("2026-12-08T09:30");
<DateInput
label="วันและเวลานัดหมาย"
kind="datetime"
value={value}
onValueChange={setValue}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "วันและเวลานัดหมาย" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| kind | "datetime" | DateKind ค่าที่ใช้ได้: "date""datetime""month""week""range" | What to pick: date for a day, datetime for a day and time, month, week, or range for a first and last day. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
เดือน
kind month แสดงเดือนทั้งปี ค่าเป็น 2026-12 ช่องแสดง ธันวาคม 2569 ปุ่มลูกศรเลื่อนทีละปี max ทำให้เดือนหลังจากนั้นกดไม่ได้
const [value, setValue] = useState("2026-12");
<DateInput
label="เดือนที่รายงาน"
kind="month"
value={value}
onValueChange={setValue}
max="2027-09"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "เดือนที่รายงาน" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| kind | "month" | DateKind ค่าที่ใช้ได้: "date""datetime""month""week""range" | What to pick: date for a day, datetime for a day and time, month, week, or range for a first and last day. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
| max | "2027-09" | string | The latest value people can pick, in the same ISO form as value, or a day for range. |
สัปดาห์
kind week ใช้สัปดาห์แบบ ISO วันจันทร์ถึงวันอาทิตย์ กดวันใดก็ได้เพื่อเลือกทั้งสัปดาห์ ค่าเป็น 2026-W50 ช่องแสดงเลขสัปดาห์และช่วงวัน เช่น สัปดาห์ที่ 50 (7–13 ธ.ค. 2569)
const [value, setValue] = useState("2026-W50");
<DateInput
label="สัปดาห์ที่ลงเวลา"
kind="week"
value={value}
onValueChange={setValue}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "สัปดาห์ที่ลงเวลา" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| kind | "week" | DateKind ค่าที่ใช้ได้: "date""datetime""month""week""range" | What to pick: date for a day, datetime for a day and time, month, week, or range for a first and last day. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
ช่วงวันที่
kind range เลือกวันเริ่มและวันสิ้นสุดในปฏิทินเดียว เหมือนจองโรงแรม คลิกแรกเป็นวันเริ่ม คลิกที่สองเป็นวันสิ้นสุด วันระหว่างกลางเป็นแถบสีอ่อนของสีหลักของแอป ระหว่างเลือก แถบตามเมาส์หรือโฟกัส ถ้าคลิกวันก่อนวันเริ่ม วันนั้นเป็นวันเริ่มใหม่ ค่าเป็นช่วงแบบ ISO เช่น 2026-12-15/2026-12-19 ช่องแสดง 15–19 ธ.ค. 2569 (5 วัน) min และ max เป็นวันที่
const [value, setValue] = useState("2026-12-15/2026-12-19");
<DateInput
label="ช่วงวันลา"
kind="range"
value={value}
onValueChange={setValue}
min="2026-12-01"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "ช่วงวันลา" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| kind | "range" | DateKind ค่าที่ใช้ได้: "date""datetime""month""week""range" | What to pick: date for a day, datetime for a day and time, month, week, or range for a first and last day. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
| min | "2026-12-01" | string | The earliest value people can pick, in the same ISO form as value, or a day such as 2026-12-01 for range. Earlier days can't be pressed. |
ช่องบังคับที่ยังไม่ได้เลือก
ค่าว่างหมายถึงยังไม่ได้เลือก ช่องแสดงคำแนะนำของตัวเอง เช่น เลือกวันที่ ถ้าไม่ส่ง placeholder ช่องบังคับไม่มีปุ่มล้าง
เลือกวันที่ส่งมอบ
const [value, setValue] = useState("");
<DateInput
label="วันที่ส่งมอบ"
required
value={value}
onValueChange={setValue}
error={value ? undefined : "เลือกวันที่ส่งมอบ"}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "วันที่ส่งมอบ" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| required | true | boolean | Marks the label with a red star, and the control as required. |
| value | value | string | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| onValueChange | setValue | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
| error | value ? undefined : "เลือกวันที่ส่งมอบ" | string | What's wrong and how to fix it, shown under the field. It marks the field invalid. |
ปิดใช้งาน
disabled แสดงค่าแต่เปลี่ยนไม่ได้
<DateInput label="วันที่อนุมัติ" defaultValue="2026-11-02" disabled />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "วันที่อนุมัติ" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| defaultValue | "2026-11-02" | string | The starting ISO value, when the field keeps it. |
| disabled | true | boolean | The field can't be changed. |
| onValueChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. |
ส่งพร้อมฟอร์ม
เมื่อหน้าจออ่านค่าตอนส่งฟอร์มเท่านั้น ส่ง name และ defaultValue ช่องส่งค่า ISO ในชื่อนั้น
<DateInput label="ตั้งแต่วันที่" name="from" defaultValue="2026-12-01" />
<DateInput label="ถึงวันที่" name="to" defaultValue="2026-12-31" />| Prop | ค่า 1 | ค่า 2 | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|---|
| label | "ตั้งแต่วันที่" | "ถึงวันที่" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| name | "from" | "to" | string | Sends the ISO value with a form, under this name. |
| defaultValue | "2026-12-01" | "2026-12-31" | string | The starting ISO value, when the field keeps it. |
| onValueChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: string) => void | Hears the ISO value on each change, or an empty string when it's cleared. | |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| 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. |
| hideLabel | boolean | false | Keeps the label for screen readers only, with the placeholder naming the field on screen, such as a filter in a DataTable's filter bar. Pass the label as usual. |
| kind | DateKind ค่าที่ใช้ได้: "date""datetime""month""week""range" | "date" | What to pick: date for a day, datetime for a day and time, month, week, or range for a first and last day. |
| value | string | — | The ISO value, when the screen keeps it. An empty string means nothing is picked. |
| defaultValue | string | "" | The starting ISO value, when the field keeps it. |
| onValueChange | (next: string) => void | — | Hears the ISO value on each change, or an empty string when it's cleared. |
| min | string | — | The earliest value people can pick, in the same ISO form as value, or a day such as 2026-12-01 for range. Earlier days can't be pressed. |
| max | string | — | The latest value people can pick, in the same ISO form as value, or a day for range. |
| minuteStep | number | 5 | For datetime, the minutes the minute list offers, such as 5 for 00, 05 and 10. A value between them still shows. |
| placeholder | string | — | The text in the empty field, already in the screen language. Leave it out for the field's own, such as เลือกวันที่. Without a label, it also names the field for screen readers, such as ตั้งแต่วันที่ in a date range. |
| name | string | — | Sends the ISO value with a form, under this name. |
| disabled | boolean | false | The field can't be changed. |
| id | string | — | The field's id. One is made when it's left out. |
| className | string | — | Places the field in the page layout, such as a grid cell. Don't use it to change the field's look. |
| aria-describedby | string | — | Ids of text that describes the field, added to its own hint and error. Pass FormField's, when DateInput is one of a group, such as the two ends of a date range, so the group's hint and error are read with each field. |
| aria-invalid | boolean | — | Marks the field invalid, such as when the group it's in has an error. Its own error prop does this already. |
ชนิดข้อมูล
DateKind
What a DateInput picks: a day, a day and time, a month, an ISO week, or a range of days.
type DateKind = "date" | "datetime" | "month" | "week" | "range";ข้อควรปฏิบัติ
- แป้นพิมพ์: ลูกศรลงหรือ Enter เปิดปฏิทิน ลูกศรเลื่อนทีละวันหรือสัปดาห์ Page Up และ Page Down เลื่อนทีละเดือน กด Shift ด้วยเลื่อนทีละปี Home และ End ไปต้นและท้ายสัปดาห์ Esc ปิดและกลับไปที่ช่อง
- กดชื่อเดือนที่หัวปฏิทินเพื่อเลือกเดือนและปีได้เร็วขึ้น
- สำหรับช่วงวันที่ ใช้ kind range ช่องเดียว ถ้าวันเริ่มและวันสิ้นสุดต้องมีป้ายหรือข้อผิดพลาดของตัวเอง ใส่ DateInput สองช่องใน FormField แบบ group ส่ง placeholder เป็นชื่อของแต่ละช่อง ส่ง aria-describedby ของกลุ่มต่อให้ทั้งสองช่อง และตั้ง min ของวันสิ้นสุดเป็นวันเริ่ม ดูตัวอย่างที่หน้า FormField
- ค่าเป็นปี ค.ศ. เสมอ แม้หน้าจอแสดงปี พ.ศ. อย่าแปลงปีในหน้าจอ
ซอร์สโค้ด: ui/src/date-input.tsx