Date picker
date picker รับวันที่ที่ผู้ใช้พิมพ์เองหรือเลือกจากปฏิทิน หน้าภาษาไทยแสดงปีเป็น พ.ศ. แต่โค้ดของคุณได้วันที่แบบ ISO ปี ค.ศ. เสมอ
ติดตั้ง
npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง
วิธีใช้
UiDatePicker ยิง change แบบ native จึงใช้ prop onChange (ไม่มี onUiChange) ส่วน DatePicker ของ Tailwind ส่งสตริง ISO ให้ onChange โดยตรง
สิ่งที่ผู้ใช้เห็นกับค่าที่คุณได้
ผู้ใช้เห็นและพิมพ์วันที่ตามภาษาและปีศักราชของหน้า ส่วนโค้ดของคุณอ่านวันที่ ISO ค่าเดียวกันทุกภาษา picker สองตัวด้านล่างใช้ค่าเดียวกัน ลองเปลี่ยนตัวไหนก็ได้
value:
| หน้าภาษาไทย | หน้าภาษาอังกฤษ | |
|---|---|---|
| ผู้ใช้เห็นและพิมพ์ | 10/10/2569 | 10/10/2026 |
value, change และค่าที่ฟอร์มส่ง |
2026-10-10 |
2026-10-10 |
value,minและmaxเป็นyyyy-mm-ddปี ค.ศ. เสมอ ถ้าvalueไม่ใช่วันที่จริงในรูปแบบนี้ จะกลายเป็น''เหมือน<input type="date">- element ยิง
changeเมื่อค่าถูกยืนยัน: ออกจากช่อง กด Enter เลือกจากปฏิทิน หรือกดล้าง อ่านค่าจากevent.target.value(และendValueในโหมดช่วง) - ช่องว่างยังส่ง
name=ไปกับฟอร์มเหมือน date input แบบ native ส่วน picker ที่disabledไม่ส่งอะไรเลย
พิมพ์หรือเลือกจากปฏิทิน
ปฏิทินเปิดเมื่อช่องได้โฟกัส ทั้งจากการคลิกและการกด Tab โดยโฟกัสยังอยู่ในช่อง ผู้ใช้จึงพิมพ์ต่อได้ และปฏิทินเลื่อนตามสิ่งที่พิมพ์
- ข้อความที่เป็นวันที่ครบตามรูปแบบของช่องแล้ว เช่น
10/10/2569เป็นค่าของช่องทันที ส่วนchangeเกิดตอนยืนยัน (ออกจากช่องหรือกด Enter) ไม่ใช่ระหว่างพิมพ์ - นอกนั้นอ่านตอนออกจากช่องหรือกด Enter โดยดึงตัวเลขออกจากสิ่งที่พิมพ์
s10/12/2569xจึงกลายเป็น 10/12/2569 - ไม่มีการเดา วันที่ไม่ครบ (
10/12) วันที่ไม่มีจริง (31/04/2569) หรือข้อความที่ไม่มีวันที่อยู่เลย จะค้างอยู่ในช่องพร้อมข้อความบอกว่าผิดตรงไหน และvalueเป็น'' - วันที่ครบแต่อยู่นอก
min/maxหรือเป็นวันที่isDateDisabledไม่รับ จะถูกเก็บและยืนยันพร้อมข้อความของมันเอง ฟอร์มจะส่งไม่ได้จนกว่าจะแก้
ลองดู: พิมพ์วันที่ที่ไม่มีจริง หรือวันที่นอกปีที่กำหนด แล้วออกจากช่อง
ข้อความเหล่านี้มีในตัวทั้งภาษาไทยและอังกฤษ error ขึ้นเมื่อไร และจะใส่ข้อความของตัวเองอย่างไร ดูที่ ฟอร์มและการตรวจค่า
พ.ศ. และภาษาไทย
ภาษามาจาก lang ที่ตัว element หรือ ancestor ที่ใกล้ที่สุด ถ้าไม่มีใช้ <html lang> ภาษาไทยให้ label และข้อความภาษาไทย ชื่อเดือนภาษาไทย และปีเป็น พ.ศ. (ค.ศ. + 543) ใส่ locale ถ้าต้องการกำหนดภาษาเฉพาะ picker ตัวนี้
eraกำหนดปีที่ผู้ใช้เห็นและพิมพ์:be(พ.ศ. ค่าเริ่มต้นของภาษาไทย) หรือce(ค.ศ. ค่าเริ่มต้นของภาษาอื่น) ทุกภาษาเลือกได้ทั้งสองแบบ- ปีที่พิมพ์ใช้ศักราชเดียวกัน ในโหมด พ.ศ. ถ้าพิมพ์ปีต่ำกว่า 2400 (เช่น 2026) จะมีข้อความขอให้กรอกปี พ.ศ. ระบบไม่แปลงปีให้เองแบบเงียบ ๆ
- ผู้ใช้พิมพ์เลขไทย (๐–๙) ได้ ระบบแปลงเป็น 0–9 ระหว่างพิมพ์
- placeholder และข้อความช่วยตั้งต้นแสดงรูปแบบตามภาษาของหน้า: ภาษาไทยเป็น
วว/ดด/ปปปป - React + Tailwind อ่าน
<html lang>หรือ proplocale
รูปแบบวันที่
format กำหนดลำดับวัน เดือน ปี: dd/mm/yyyy (ค่าเริ่มต้น), mm/dd/yyyy หรือ yyyy-mm-dd เปลี่ยนแค่สิ่งที่ผู้ใช้เห็น value ยังเป็น ISO
รูปแบบแสดงเป็นข้อความช่วยจนกว่าคุณจะใส่ helper-text (helperText ใน React + Tailwind) หลังจากนั้น screen reader ยังอ่านรูปแบบให้เหมือนเดิม
เลือกเป็นช่วง
range ให้สองช่องที่ใช้ปฏิทินร่วมกัน: value / name / label สำหรับวันเริ่ม และ end-value / end-name / end-label สำหรับวันสิ้นสุด ถ้าตั้งชื่อทั้งสองช่อง ฟอร์มจะได้ค่าสองรายการ ถ้าไม่มี end-name ตัว ui-date-picker จะส่งค่ารายการเดียวภายใต้ name เป็น start/end (2026-10-01/2026-10-05) แบบ cds-date-picker ของ Carbon ส่วน DatePicker ของ React + Tailwind จะส่งวันสิ้นสุดเฉพาะเมื่อมี endName
- เลือกวันแรกแล้วปฏิทินยังเปิดค้างไว้ให้เลือกวันสิ้นสุด วันระหว่างกลางมีไฮไลต์แบบแถบริบบิ้นต่อเนื่อง และมี preview ทั้งก่อนและหลังวันเริ่มระหว่างเลือกวันสิ้นสุด (ตามเมาส์หรือคีย์บอร์ด วันที่เลือกไม่ได้ไม่ทำให้ preview ขยับ)
- ถ้าเลือกวันสิ้นสุดก่อนวันเริ่ม ระบบสลับสองค่าให้
- ถ้ามีช่วงครบแล้ว การเลือกครั้งถัดไปเริ่มช่วงใหม่ (แบบ Cally) และ
changeเกิดเมื่อเลือกครบทั้งสองวัน - ถ้าพิมพ์วันสิ้นสุดก่อนวันเริ่ม ค่าจะค้างไว้พร้อมข้อความแจ้ง ไม่สลับให้
ปฏิทินสองเดือน (Two-Month Range Picker)
ใส่ months="2" เพื่อแสดงปฏิทินสองเดือนเคียงข้างกันในหน้าจอขนาดกว้าง เหมาะกับระบบจองห้องพัก ตั๋วเครื่องบิน หรือสัญญาเช่าที่มีช่วงเวลายาวข้ามเดือน:
จำกัดวันที่เลือกได้
min และ max รับวันที่ ISO วันที่อยู่นอกช่วงจะเป็นสีจาง และปุ่มเลื่อนเดือนจะหยุดที่ขอบนั้น
ถ้าจะปิดบางวัน (เสาร์-อาทิตย์ วันหยุด) ใช้ isDateDisabled: ฟังก์ชันที่คืน true หรือคืนข้อความเพื่อใช้เป็นข้อความแจ้งผู้ใช้ ใน web component เป็น property จึงต้องตั้งด้วย JavaScript:
ปุ่มล้างและปุ่มวันนี้
clearable เพิ่มปุ่ม × ในช่องเมื่อมีข้อความ show-today เพิ่มปุ่ม "วันนี้" ใต้ปฏิทิน (Carbon ไม่มี ตัวนี้ต้องเปิดเอง) first-day กำหนดวันแรกของสัปดาห์ ตั้งแต่ 0 (อาทิตย์ ค่าเริ่มต้น) ถึง 6
ขนาดและแบบ fluid
size: sm 32px, md 40px (ค่าเริ่มต้น ตาม Carbon), lg 48px สเกลเดียวกับ text input ส่วน fluid หรือการวางไว้ในฟอร์มแบบ fluid (<ui-fluid-form>, FluidForm ใน React + Tailwind) ให้ช่องแบบ fluid ของ Carbon คือกล่องสูง 64px ที่มี label อยู่ข้างใน ทั้งสอง prop ใช้ชื่อเดียวกันใน React และ React + Tailwind
แบบมีขอบ (ดีไซน์ Kanok)
ในดีไซน์ Kanok ช่องกรอกเป็นแบบ filled โดยปกติ คือพื้นเทาอ่อน ไม่มีขอบ ใส่ data-field-variant="outlined" ที่ element ที่ครอบช่อง (เช่น <form> หรือ <html> ถ้าต้องการทั้งแอป) จะเปลี่ยนเป็นขอบ 1px บนพื้นใส ส่วน focus ยังเป็นวงแสงสีฟ้าเหมือนเดิม attribute นี้ไม่มีผลในดีไซน์ Carbon ตัวอย่างด้านล่างจึงครอบด้วย data-design="kanok" ดูรายละเอียดทั้งหมดที่ ดีไซน์ Kanok
ข้อความช่วย error และคำเตือน
helper-text บอกว่าวันที่นี้ใช้ทำอะไร (slot helper-text รับ markup ได้) warn กับ warn-text เตือนวันที่ที่เลือกได้แต่ผิดปกติ และไม่กันการส่งฟอร์ม invalid กับ invalid-text แสดง error จากการตรวจของคุณเอง เช่น ผลจาก server ในโหมดช่วง คำเตือนแสดงใต้ช่องวันเริ่ม
อ่านอย่างเดียวและปิดใช้งาน
readonly แสดงและส่งค่า แต่พิมพ์ไม่ได้และเปิดปฏิทินไม่ได้ disabled ทำให้ช่องเป็นสีจาง ไม่ส่งค่าและไม่ตรวจค่า <fieldset> ที่ disabled ครอบอยู่ก็ให้ผลเหมือนกัน
web component และ wrapper ของ React สะกดว่า readonly ส่วน React + Tailwind ใช้ readOnly
ใช้ในฟอร์ม
ถ้ามี required ฟอร์มจะส่งไม่ได้จนกว่าจะกรอกวันที่ ในโหมดช่วงต้องกรอกทั้งสองช่อง ฟอร์มได้วันที่ ISO ภายใต้ name (และ end-name) ลองกดส่งฟอร์มเปล่าด้านล่างเพื่อดูข้อความ
ค่าที่ส่ง:
send แทนโค้ดของคุณเอง
มือถือและแท็บเล็ต
บนมือถือ (จอสัมผัสที่แคบกว่า 42rem) picker="auto" (ค่าเริ่มต้น) เปิดปฏิทินใน bottom sheet คือ dialog ที่ชิดขอบล่างของจอ บนหน้าเว็บที่ถูกทำให้มืดลง
- แตะที่ช่องเพื่อเปิด โดยโฟกัสอยู่ที่วันหนึ่งวัน คีย์บอร์ดบนจอจึงไม่ขึ้นมาบัง แค่โฟกัสที่ช่องยังไม่เปิด หลัง sheet ปิดแล้ว แตะที่ช่องอีกครั้งจะเป็นการพิมพ์
- ปิดได้ด้วย Esc ปุ่ม × การปัดลงที่แถบด้านบน หรือแตะที่หน้าเว็บที่มืดลง ข้อความที่พิมพ์ไว้ถูกบันทึก และโฟกัสกลับไปที่ช่อง
- ระหว่างที่เปิด หน้าเว็บด้านหลังใช้และเลื่อนไม่ได้ และระยะขอบของ sheet เว้นพื้นที่ปลอดภัยของเครื่องไว้ (แถบ home ติ่งกล้อง)
บนแท็บเล็ตและจอที่ใหญ่กว่านั้น ปฏิทินเปิดใต้ช่องเหมือนเดิม
picker |
เปิด |
|---|---|
auto (ค่าเริ่มต้น) |
bottom sheet บนมือถือ และปฏิทินใต้ช่องบนอุปกรณ์อื่น |
custom |
ปฏิทินใต้ช่องทุกอุปกรณ์ |
sheet |
bottom sheet ทุกอุปกรณ์ |
native |
ตัวเลือกวันที่ของ OS ซึ่งทำวันที่ isDateDisabled ให้จางไม่ได้ วันที่เลือกจากตัวนั้นจึงถูกตรวจเหมือนข้อความที่พิมพ์ |
ปรับหน้าตา sheet ด้วย ::part(sheet) (ฉากหลังมืดใช้ ::part(sheet)::backdrop) ::part(sheet-grip) และ ::part(sheet-close) ส่วน --ui-sheet-radius กำหนดความมนของมุมด้านบน (ค่าเริ่มต้นเท่ากับความมนของเมนู) prop นี้ชื่อเดียวกันทุกแบบ
ใช้ปฏิทินเดี่ยว ๆ
ปฏิทินใน picker เป็น element ของมันเองชื่อ ui-calendar มาพร้อม import เดียวกัน เป็น view แบบ controlled: มันเลื่อนโฟกัสเองได้ แต่วันที่เลือกเป็นหน้าที่ของคุณ ฟัง ui-pick (detail { date } เป็น Date) แล้วตั้ง value:
เดือนที่แสดงตาม property focusDate (เป็น Date ค่าเริ่มต้นคือวันนี้) ui-calendar ใช้ภาษาของหน้าเหมือน picker (lang ที่ใกล้ที่สุด) และแสดงปี พ.ศ. เมื่อเป็นภาษาไทย ใส่ locale และ era เพื่อกำหนดเอง รับ min, max, isDateDisabled, range กับ end-value, first-day และ show-today เหมือน picker ส่วน Calendar ของ React + Tailwind ก็เป็นแบบ controlled เช่นกัน ต้องส่ง focusDate, onFocusDateChange และ onPick เสมอ
เลือกหลายวัน (Multiple Dates)
<ui-calendar multi> รองรับการเลือกหลายวันที่พร้อมกัน (แบบ Cally) โดยคลิกเพื่อเปิด/ปิดวันที่ในรายการ values:
สองเดือนพร้อมช่วงวันที่ (Dual-Month Calendar)
<ui-calendar range months="2"> แสดงปฏิทินสองเดือนพร้อมแถบริบบิ้นต่อเนื่อง:
เลือกเดือนและปี (แบบ Cally)
หัวปฏิทินมี select แบบ native สองตัวแบบ Cally คือ <ui-calendar-select-month> และ <ui-calendar-select-year> เดือนที่อยู่นอก min / max ทั้งเดือนจะเลือกไม่ได้ ส่วนรายการปีมี 20 ปีรอบปีที่แสดง และตัดตาม min / max หน้าภาษาไทยแสดงปีเป็น พ.ศ. ถ้าแสดงหลายเดือน หัวปฏิทินจะมีแค่ select ปี เพราะแต่ละตารางมีชื่อเดือนของตัวเองอยู่แล้ว
ใส่เนื้อหาของคุณเองใน slot heading เพื่อแทน select ทั้งสองได้ select ที่ใส่ไว้ใน slot นี้ หรืออยู่ข้างในสิ่งที่ใส่ จะทำงานตามปฏิทินด้วย:
| Element | Attribute | ทำอะไร |
|---|---|---|
ui-calendar-select-month |
format-month |
ชื่อเดือนแบบ long (ค่าเริ่มต้น) หรือ short |
ui-calendar-select-year |
max-years |
จำนวนปีในรายการรอบปีที่แสดง (ค่าเริ่มต้น 20) |
ตกแต่ง select ด้วย ui-calendar::part(month-select) และ ::part(year-select) ฝั่ง React + Tailwind Calendar มีหัวแบบเดียวกัน ส่วน headless ใช้ Calendar.MonthSelect และ Calendar.YearSelect
ตัวเลือกเพิ่มเติมของปฏิทิน (แบบ Cally)
ui-calendar / ui-date-picker |
React + Tailwind | ทำอะไร |
|---|---|---|
months |
months |
แสดง 1 ถึง 12 เดือนเรียงกัน ถ้า 12 เดือนจะแสดงทั้งปีเริ่มที่มกราคม |
page-by="single" |
pageBy="single" |
ปุ่ม ‹ › เลื่อนทีละหนึ่งเดือนแม้แสดงหลายเดือน (ค่าเริ่มต้นเลื่อนทั้งหน้า) |
show-week-numbers |
showWeekNumbers |
แสดงเลขสัปดาห์ ISO หน้าแต่ละสัปดาห์ และ popover ของ date picker จะกว้างขึ้น |
show-outside-days |
showOutsideDays |
แสดงวันของเดือนอื่นเต็มหกสัปดาห์ ค่าเริ่มต้นเว้นว่างไว้และแสดงเฉพาะสัปดาห์ที่เดือนนั้นต้องใช้ แบบ Cally (เฉพาะแบบเดือนเดียว) |
weekday-format |
weekdayFormat |
ชื่อวันบนหัวตารางแบบ narrow หรือ short (ค่าเริ่มต้นใช้ของคำแปล) |
today |
today |
วันที่ให้ถือเป็นวันนี้ (ISO) ใช้กับเทสต์หรือภาพหน้าจอ |
getDayParts (property เฉพาะ ui-calendar) |
dayClassName |
ชื่อ part หรือ class ของคุณเองสำหรับวันหนึ่ง ๆ เช่น วันหยุด หรือวันที่มีนัด |
ตกแต่ง part ที่ getDayParts คืนมาด้วย ::part():
event ที่ ui-calendar ส่งเพิ่ม:
ui-range-startและui-range-end(detail{ date }) เมื่อเลือกปลายแต่ละด้านของช่วง ส่วนchangeจะส่งเมื่อเลือกครบทั้งสองด้านแล้วui-page-change(detail{ start, end }) เมื่อเดือนที่แสดงเปลี่ยน ฝั่ง React + Tailwind ใช้onPageChangeของCalendar
ตัวเลือกอื่น:
focus({ target: 'previous' | 'next' | 'day' })ย้าย focus ไปที่ปุ่มลูกศรหรือที่วัน- slot
previousและnextใช้แทนไอคอนลูกศร ส่วน slotheadingใช้แทน select เดือนและปี <ui-date-picker>รับshow-outside-daysและgetDayParts(picker ส่งต่อชื่อ part ที่ได้ ใช้ui-date-picker::part(holiday)ได้) และส่งui-range-start/ui-range-endฝั่ง React + TailwindDatePickerมีonRangeStart/onRangeEnd- ปุ่มวันมี part ตามสถานะของวันนั้น:
selected,today,outside,disabled,disallowed,range-start,range-end,in-rangeและday-0…day-6ส่วนเลขสัปดาห์มี partweeknumber - ในหน้าที่อ่านจากขวาไปซ้าย ปุ่ม ← และ → จะสลับทิศกัน
Skeleton
ระหว่างที่หน้ากำลังโหลดข้อมูล ให้แสดง <ui-date-picker-skeleton> แทนที่ picker เหมือน DatePickerSkeleton ของ Carbon ใส่ range ถ้าเป็นสองช่อง ตัวนี้ import แยกจาก @purpurabog/ui/date-picker-skeleton และ screen reader มองไม่เห็น
คีย์บอร์ด
ในช่องพิมพ์:
| ปุ่ม | ผล |
|---|---|
| พิมพ์ | กรอกวันที่ ปฏิทินที่เปิดอยู่เลื่อนตามเมื่อวันที่ครบ |
| ↓ | เปิดปฏิทินและย้ายโฟกัสเข้าไป |
| Tab | ไปช่องถัดไป (โหมดช่วงจากช่องวันเริ่มไปช่องวันสิ้นสุด) บันทึกข้อความที่พิมพ์ และปฏิทินปิดเมื่อโฟกัสออกจาก picker |
| Shift + Tab | จากช่องวันเริ่ม: ปิดปฏิทินแล้วย้อนกลับ |
| Enter | ยืนยันข้อความที่พิมพ์ ปิดปฏิทิน และส่งฟอร์มที่ช่องอยู่ |
| Esc | ปิดปฏิทิน |
ในปฏิทิน:
| ปุ่ม | ผล |
|---|---|
| ← / → | วันก่อนหน้า / ถัดไป |
| ↑ / ↓ | วันเดียวกันของสัปดาห์ก่อน / ถัดไป |
| Home / End | วันแรก / วันสุดท้ายของสัปดาห์ |
| Page Up / Page Down | เดือนก่อน / เดือนถัดไป |
| Shift + Page Up / Page Down | ปีก่อน / ปีถัดไป |
| Enter, Space | เลือกวันนั้น แล้วปิดปฏิทิน (โหมดช่วงปิดหลังเลือกวันสิ้นสุด) |
| Esc | ปิด แล้วโฟกัสกลับไปที่ช่องพิมพ์ |
| Tab | วนอยู่ในปฏิทิน: ‹ เดือน ปี › และวัน (และปุ่มวันนี้) จากตัวสุดท้ายกลับไปตัวแรก ออกจากปฏิทินด้วย Esc หรือเลือกวัน |
| Shift + Tab | วนแบบเดียวกันย้อนกลับ |
ถ้าใช้เมาส์ เลือกเดือนหรือปีจาก select ที่หัวปฏิทินได้
Accessibility
- ช่องพิมพ์เป็น combobox ที่เปิด dialog (
aria-haspopup="dialog",aria-expanded) ปฏิทินเป็น dialog ชื่อ "เลือกวันที่" ที่มี grid ของปุ่มวัน ตาม pattern date picker dialog ของ WAI-ARIA - แต่ละวันถูกอ่านเป็นวันที่เต็ม (เช่น "วันเสาร์ที่ 10 ตุลาคม พ.ศ. 2569") วันนี้มี
aria-current="date"วันที่เลือกมีaria-pressedวันที่เลือกไม่ได้มีaria-disabled - การเปลี่ยนเดือนถูกประกาศผ่าน live region แบบ polite
- bottom sheet เป็น modal dialog ชื่อเดียวกัน หน้าเว็บด้านหลังเป็น inert จนกว่าจะปิด
- ไอคอนปฏิทินเป็นแค่ภาพประกอบแบบ Carbon ไม่ใช่จุดหยุดของ Tab และการคลิกที่ไอคอนเท่ากับคลิกในช่องพิมพ์
- error ตั้ง
aria-invalidและผูกกับช่องด้วยaria-describedbyเช่นเดียวกับคำอธิบายรูปแบบ
ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Date picker
API
สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)
<ui-date-picker> · React UiDatePicker
Attribute
| Attribute | Property | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|---|
label |
label |
string |
'' |
Visible label text; the label slot replaces it when markup is needed. |
hide-label |
hideLabel |
boolean |
false |
Keep the label for screen readers but don't show it. |
helper-text |
helperText |
string |
'' |
Helper text under the field, shown while there is no error or warning. |
invalid-text |
invalidText |
string |
'' |
Error text shown while invalid or while the field fails validation. |
invalid |
invalid |
boolean |
false |
Forces the error state, e.g. after server-side validation. |
warn |
warn |
boolean |
false |
Non-blocking warning; shown when there is no error. |
warn-text |
warnText |
string |
'' |
Text of the warning shown while warn. |
value |
value |
string |
'' |
ISO yyyy-mm-dd (the start date in range mode). |
name |
name |
string |
'' |
Reflected: form-associated elements submit under the name attribute. |
range |
range |
boolean |
false |
Two fields sharing one calendar (Carbon datePickerType="range"). |
end-value |
endValue |
string |
'' |
Range mode: the end date, ISO yyyy-mm-dd. |
end-name |
endName |
string |
'' |
Range mode: form entry name of the end date. Without it the range submits as one name entry start/end. |
end-label |
endLabel |
string |
'' |
Range mode: label of the end field. |
min |
min |
string |
'' |
Earliest selectable date, ISO yyyy-mm-dd. |
max |
max |
string |
'' |
Latest selectable date, ISO yyyy-mm-dd. |
format |
format |
DateFormat |
'dd/mm/yyyy' |
|
locale |
locale |
string |
'' |
Locale for names, labels and messages. Defaults to the nearest lang: the element's own, an ancestor's, then <html>'s, else the browser language. |
era |
era |
Era | '' |
'' |
Year era shown and typed: be (พ.ศ.) or ce (ค.ศ.). Defaults to be for Thai locales. |
first-day |
firstDay |
number |
0 |
0 = Sunday … 6 = Saturday. |
disabled |
disabled |
boolean |
false |
Disables the control; a disabled <fieldset> ancestor does the same. |
required |
required |
boolean |
false |
Blocks form submission while the field is empty. |
readonly |
readonly |
boolean |
false |
Shows and submits the value but blocks changes. |
fluid |
fluid |
boolean |
false |
Carbon FluidDatePicker: each date box is a 64px box with its label inside. <ui-fluid-form> sets it for every field inside. |
picker |
picker |
'auto' | 'custom' | 'sheet' | 'native' |
'auto' |
Which picker opens: auto (default) = our calendar, in a bottom sheet on a phone; custom = our calendar as a popover on every device; sheet = in a bottom sheet on every device; native = the OS date picker. |
clearable |
clearable |
boolean |
false |
Shows a clear button inside the field while it has text. |
show-today |
showToday |
boolean |
false |
Adds a "Today" button under the calendar. |
months |
months |
number |
1 |
Months to show side by side in the calendar, 1 to 12 (default 1, e.g. 2 for range picking). |
page-by |
pageBy |
'months' | 'single' |
'months' |
With more than one month, ‹ › turn a whole page (months) or one month (single): the calendar's page-by. |
show-outside-days |
showOutsideDays |
boolean |
false |
Show the days of the months before and after (by default they are blank): the calendar's show-outside-days. |
show-week-numbers |
showWeekNumbers |
boolean |
false |
A column of ISO week numbers in the calendar: its show-week-numbers. |
weekday-format |
weekdayFormat |
'narrow' | 'short' | '' |
'' |
Weekday headings narrow or short: the calendar's weekday-format. |
today |
today |
string |
'' |
The day the calendar marks as today, ISO (default the real today). |
size |
size |
'sm' | 'md' | 'lg' |
'md' |
Field height, same scale as ui-text-input. |
Property
| Property | ชนิด | คำอธิบาย |
|---|---|---|
getDayParts |
(date: Date) => string | undefined |
Extra part names for a calendar day, e.g. holiday: the calendar's getDayParts; the picker exports each name it returns, so ui-date-picker::part(holiday) styles those days. |
isDateDisabled |
(date: Date) => boolean | string | undefined |
Property only. Return true for days that can't be chosen (weekends, holidays…), or a string to show that reason instead of the generic message. |
willValidate |
(อ่านอย่างเดียว) Whether the field takes part in constraint validation (not while disabled), as natively. | |
labels |
(อ่านอย่างเดียว) The <label>s that point at this field. |
Method
| Method | คำอธิบาย |
|---|---|
setCustomValidity(message) |
Like <input>.setCustomValidity(): a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''. |
Event
| Event | React | คำอธิบาย |
|---|---|---|
change |
onChange |
When a committed value (start or end) changes: blur, Enter, a calendar pick or clear. |
ui-range-start |
onUiRangeStart |
Detail { date }, range: a calendar pick began a range (its start), as Cally's rangestart; change waits for the end |
ui-range-end |
onUiRangeEnd |
Detail { date }, range: a calendar pick finished a range (its end), as Cally's rangeend A typed date outside min/max is still committed, with the field reporting the range error. |
Slot
| Slot | คำอธิบาย |
|---|---|
label |
Label content with markup; the label attribute is the plain-text fallback |
helper-text |
Helper text with markup (links, bold); overrides helper-text |
warn-text |
Warning text shown while warn; overrides warn-text |
invalid-text |
Error text shown while invalid; overrides invalid-text |
end-label |
Label of the end field in range mode; overrides end-label |
CSS part
| Part | คำอธิบาย |
|---|---|
base |
The field box (range: also start-base / end-base; same for every field part) |
label |
The label |
input |
The text box |
clear-button |
The × button |
toggle |
The calendar icon (decorative, as Carbon) |
status-icon |
The error / warning icon |
helper-text |
The helper line |
warning-text |
The warning line |
warn-text |
Same line as warning-text (named after the warn-text attribute / slot) |
error-text |
The error line |
invalid-text |
Same line as error-text (named after the invalid-text attribute / slot) |
calendar |
The popover shell (in the bottom sheet: the sheet's panel) |
sheet |
The bottom sheet <dialog> on a phone (picker="auto" / sheet; style its scrim with ::part(sheet)::backdrop) |
sheet-grip |
The sheet's top bar, which a swipe down closes |
sheet-close |
The sheet's × button |
header |
Calendar month / year row |
nav |
Previous / next month buttons |
heading |
The month and year selects' row |
month-select |
The month select (<ui-calendar-select-month>'s select) |
year-select |
The year select (<ui-calendar-select-year>'s select) |
month-title |
A month's name over its grid when several show |
grid |
The table of days |
day |
Each day button (its state also: selected, today, outside, disabled, disallowed, range-start, range-end, in-range, and the names getDayParts returns) |
weeknumber |
A week-number cell (show-week-numbers) |
today-button |
The optional "Today" button |
CSS custom property
| Custom property | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|
--ui-field-border |
Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline) | |
--ui-field-disabled-border-color |
Border colour when disabled (default: the underline transparent) | |
--ui-field-readonly-border-color |
Border colour when read-only (default: a hairline underline) | |
--ui-field-radius |
Corner radius of the box (default 0; Kanok: 6px) | |
--ui-field-background |
Fill of the box (default --ui-surface-1; Kanok: transparent) |
|
--ui-label-font |
Font of the label (default --ui-font-caption; Kanok: 14px semibold) |
|
--ui-label-color |
Colour of the label (default --ui-ink-muted; Kanok: --ui-ink) |
|
--ui-menu-radius |
/ --ui-menu-border / --ui-menu-shadow - Corners, border and shadow of the calendar (the menu settings) | |
--ui-sheet-radius |
The bottom sheet's top corners (default: the menu radius) | |
--ui-modal-scrim |
The bottom sheet's scrim, as the modal's (default Carbon's overlay) | |
--ui-calendar-day-radius |
Corner radius of a day (default 0; Kanok: 6px) | |
--ui-calendar-today-dot-radius |
Corner radius of today's dot (default 0, a square; Kanok: 50%, a dot) | |
--ui-field-readonly-background |
The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled) | |
--ui-fluid-background |
/ --ui-fluid-gap - A fluid box's fill and the space under it (default the layer's fill, 0: boxes that touch; Kanok: transparent, 8px) | |
--ui-icon-control-radius |
Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round) | |
--ui-focus-offset |
outline-offset of the month arrows' and Today's focus ring (default -2px: inside; Kanok: 2px outside) |
<ui-calendar> · React UiCalendar
Attribute
| Attribute | Property | ชนิด | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|---|
value |
value |
string |
'' |
Chosen day (start day in range mode), ISO yyyy-mm-dd. |
end-value |
endValue |
string |
'' |
Range mode: chosen end day, ISO yyyy-mm-dd. |
range |
range |
boolean |
false |
Whether range selection is enabled. |
multi |
multi |
boolean |
false |
Multi-date selection mode: select multiple individual dates (like Cally's calendar-multi). |
values |
values |
string[] | string |
[] |
Selected dates in multi mode (array or comma/space-separated ISO string). |
months |
months |
number |
1 |
Months on show side by side, 1 to 12 (default 1; 12 paged by the page is a calendar year, from January). |
page-by |
pageBy |
'months' | 'single' |
'months' |
With more than one month, ‹ › and the keys turn a whole page (months, the default) or one month (single), as Cally's page-by. |
show-outside-days |
showOutsideDays |
boolean |
false |
Show the days of the months before and after, in six weeks (Cally show-outside-days); by default they are blank and only the weeks the month needs show. Several months never show them. |
show-week-numbers |
showWeekNumbers |
boolean |
false |
A column of ISO week numbers before the weeks (Cally show-week-numbers). |
weekday-format |
weekdayFormat |
'narrow' | 'short' | '' |
'' |
Weekday headings narrow (S / อา) or short (Sun / อา.); by default narrow in Thai, short otherwise (Cally format-weekday). |
today |
today |
string |
'' |
The day marked as today, ISO (default the real today): for tests, demos and another time zone (Cally today). |
active-field |
activeField |
'start' | 'end' |
'start' |
Range mode: which end a pick will set; drives the preview highlight. |
min |
min |
string |
'' |
Minimum selectable ISO date. |
max |
max |
string |
'' |
Maximum selectable ISO date. |
locale |
locale |
string |
'' |
BCP 47 locale for names and labels. Defaults to the nearest lang. |
era |
era |
Era | '' |
'' |
Year era: be (พ.ศ.) or ce (ค.ศ.). Defaults to be for Thai locales. |
first-day |
firstDay |
number |
0 |
0 = Sunday … 6 = Saturday. |
show-today |
showToday |
boolean |
false |
Whether to display the "Today" footer shortcut button. |
Property
| Property | ชนิด | คำอธิบาย |
|---|---|---|
getDayParts |
(date: Date) => string | undefined |
Extra part names for a day, e.g. holiday (Cally getDayParts). |
focusDate |
Day that holds the roving tab stop; its month is shown. | |
isDateDisabled |
(date: Date) => boolean | string | undefined |
Callback to disable individual dates (e.g. weekends, holidays). |
multiValues |
string[] |
(อ่านอย่างเดียว) Selected dates as clean ISO array in multi mode. |
Method
| Method | คำอธิบาย |
|---|---|
focusDay() |
Puts DOM focus on the day that holds the roving tab stop. |
tabStops() |
The calendar's Tab stops in order: ‹, its own month and year selects (not when heading is slotted), ›, the day that holds the tab stop and Today. |
focus(options) |
Focus on the day with the tab stop, or with { target: 'previous' | 'next' } on a month arrow (Cally's focus()). |
Event
| Event | React | คำอธิบาย |
|---|---|---|
ui-page-change |
onUiPageChange |
Detail { start, end }, the first and last day shown after the months on show changed (Cally pagechange) |
ui-multi-pick |
onUiMultiPick |
Detail { date, values }, in multi mode when a day is toggled |
change |
ไม่มี (ใช้ ref) | Detail { value, endValue, values }, native-like change event on a pick (with range, once both ends are picked) |
ui-pick |
onUiPick |
Detail { date }, when a day is activated |
ui-focus-change |
onUiFocusChange |
Detail { date }, when keyboard or navigation moves the focused date |
ui-range-start |
onUiRangeStart |
Detail { date }, with range: the first end was picked (Cally rangestart) |
ui-range-end |
onUiRangeEnd |
Detail { date }, with range: the second end was picked (Cally rangeend) |
Slot
| Slot | คำอธิบาย |
|---|---|
previous |
Replaces the previous button's arrow icon |
next |
Replaces the next button's arrow icon |
heading |
Replaces the month and year selects; <ui-calendar-select-month> / <ui-calendar-select-year> put here follow the calendar |
CSS part
| Part | คำอธิบาย |
|---|---|
months |
Multi-month layout container |
month-view |
Container of a single month |
month-title |
A month's name above its grid when two months show (the header then has the year only) |
header |
Month / year row container |
nav |
Previous / next navigation buttons |
prev-button |
The previous month button |
next-button |
The next month button |
heading |
The month and year selects' row (the heading slot) |
month-select |
The default heading's month select (<ui-calendar-select-month>'s select) |
year-select |
The default heading's year select (<ui-calendar-select-year>'s select) |
grid |
The table grid of days |
table |
The table grid of days |
thead |
The table header row with weekday labels |
th |
Individual weekday heading cell (also day-N, 0 = Sunday; the week-number heading also weeknumber) |
weeknumber |
A week-number cell (show-week-numbers) |
tbody |
The table body of weeks |
row |
Each week table row |
cell |
Each day table cell |
day |
Each day button; its state adds day-N (0 = Sunday), selected, today, outside (another month), disabled (before min / after max), disallowed (refused by isDateDisabled), range-start, range-end, in-range, and the names getDayParts returns |
today-button |
The optional "Today" footer button |
footer |
The footer container |
CSS custom property
| Custom property | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|
--ui-calendar-day-radius |
Corner radius of a day button (default 9999px for circular days) | |
--ui-calendar-today-dot-radius |
Corner radius of today's indicator dot (default 50%) | |
--ui-calendar-day-focus |
The keyboard focus ring on a day | |
--ui-calendar-selected-focus |
Focus ring on a selected day |