ui
ธีม รูปแบบ CarbonKanok ภาษา English
ภาพรวมติดตั้งการย้ายไป 1.0ธีมและ layerดีไซน์ Kanokปรับแต่งหน้าตาไอคอนฟอร์มและการตรวจค่าใช้กับ frameworkใช้กับ AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeแนะนำText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place

Number input

ช่องกรอกตัวเลข เช่น จำนวน ยอดเงิน หรือเปอร์เซ็นต์ มีปุ่ม − และ + แบบ Carbon อยู่ท้ายช่อง และกด ↑ / ↓ เพื่อเพิ่มลดค่าจากคีย์บอร์ดได้

HTMLReactReact + Tailwind<ui-number-input label="จำนวนห้อง" name="units" value="1" min="1" max="20"></ui-number-input> <UiNumberInput label="จำนวนห้อง" name="units" value="1" min={1} max={20} /> <NumberInput label="จำนวนห้อง" name="units" defaultValue={1} min={1} max={20} />

ติดตั้ง

npmshadcn · Web componentshadcn · React + Tailwindคัดลอกเองnpm install @purpurabog/ui npx shadcn@4 add @kanok-ui/number-input npx shadcn@4 add @kanok-ui/tw-number-input # Web component # 1. ติดตั้ง dependency npm install lit@^3.3.0 # 2. คัดลอก "content" ของแต่ละไฟล์จาก # https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/number-input.json # ไปไว้ที่ target ของมัน: # components/ui/primitives/number-input/number-input-skeleton.ts # components/ui/primitives/number-input/number-input.styles.ts # components/ui/primitives/number-input/number-input.ts # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # core-number-format, shared-affixes, shared-element, shared-field, shared-form-control, shared-localize, shared-skeleton, shared-slots, tokens # React + Tailwind # 1. ติดตั้ง dependency npm install @purpurabog/ui@^2.3.0 # 2. คัดลอก "content" ของแต่ละไฟล์จาก # https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-number-input.json # ไปไว้ที่ target ของมัน: # components/ui/react-tw/number-input.tsx # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # core-field, tw-affix, tw-field, tw-i18n, tw-refs, tw-skeleton, tw-theme, tw-utils

npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง

วิธีใช้

HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/number-input';</script> <ui-number-input label="จำนวนห้อง" name="units" min="1" max="20"></ui-number-input> import { UiNumberInput } from '@purpurabog/ui/react'; <UiNumberInput label="จำนวนห้อง" name="units" min={1} max={20} onChange={(e) => setUnits((e.target as HTMLInputElement).value)} /> import { NumberInput } from '@/components/ui/react-tw/number-input'; <NumberInput label="จำนวนห้อง" name="units" min={1} max={20} value={units} onChange={setUnits} />
  • ค่าเป็นข้อความ ช่องจึงว่างได้: "12", "0.5" หรือ "" ส่วน valueAsNumber ของ element ให้ค่าเป็นตัวเลข (NaN เมื่อช่องว่าง)
  • element ยิง input ทุกครั้งที่พิมพ์หรือกดเพิ่มลด และ change เมื่อค่าถูกยืนยัน (ออกจากช่อง กด Enter หรือกดเพิ่มลด) wrapper ของ React จึงมี onInput กับ onChange
  • onChange ของ React + Tailwind ได้ค่าใหม่เป็นข้อความ ไม่ใช่ event

ระยะเพิ่มลด ค่าต่ำสุด และค่าสูงสุด

step (ค่าเริ่มต้น 1) คือระยะที่ − / + และ ↑ / ↓ เพิ่มหรือลด ค่าจะอยู่ในช่วง min ถึง max เสมอ และปุ่มที่ปลายช่วงจะกดไม่ได้ ถ้าพิมพ์ค่านอกช่วงจะเป็น error

ถ้าช่องว่าง การกดครั้งแรกจะไปที่ step-start-value ถ้าตั้งไว้ ถ้าไม่ได้ตั้งและมีแค่ min จะไปที่ min นอกนั้นไปที่ 1 หรือ −1 แบบ Carbon

HTMLReactReact + Tailwind<ui-number-input label="อัตราขึ้นค่าเช่า" name="increase" value="3" min="0" max="10" step="0.5" suffix-text="%"></ui-number-input> <ui-number-input label="ชั้น" name="floor" min="1" step-start-value="10"></ui-number-input> <UiNumberInput label="อัตราขึ้นค่าเช่า" name="increase" value="3" min={0} max={10} step={0.5} suffixText="%" /> <UiNumberInput label="ชั้น" name="floor" min={1} stepStartValue={10} /> <NumberInput label="อัตราขึ้นค่าเช่า" name="increase" defaultValue={3} min={0} max={10} step={0.5} suffixText="%" /> <NumberInput label="ชั้น" name="floor" min={1} stepStartValue={10} />

ทศนิยม

การเพิ่มลดจะปัดตามจำนวนตำแหน่งทศนิยมของค่าหรือของ step แล้วแต่อันไหนมากกว่า 0.1 + 0.2 จึงได้ 0.3 ไม่ใช่ 0.30000000000000004 ใน type="number" (ค่าเริ่มต้น) step ยังเป็นความละเอียดที่เบราว์เซอร์ยอมรับด้วย ถ้า step="0.01" ค่า 12.345 จะเป็น error

HTMLReactReact + Tailwind<ui-number-input label="อัตราดอกเบี้ย" name="rate" value="2.75" step="0.01" min="0" suffix-text="% ต่อปี"></ui-number-input> <UiNumberInput label="อัตราดอกเบี้ย" name="rate" value="2.75" step={0.01} min={0} suffixText="% ต่อปี" /> <NumberInput label="อัตราดอกเบี้ย" name="rate" defaultValue="2.75" step={0.01} min={0} suffixText="% ต่อปี" />

สกุลเงิน หน่วย และรูปแบบตัวเลข

prefix-text และ suffix-text ใส่ข้อความไว้ในช่อง หน้าหรือหลังตัวเลข เช่น ฿, กก., บาท/เดือน ข้อความนี้อยู่ให้เห็นตลอดระหว่างพิมพ์และไม่เป็นส่วนของค่า Carbon ไม่มีสิ่งนี้

ถ้าต้องการช่องจัดรูปแบบแบบ Carbon ให้ตั้ง type="text" คู่กับ format-options ซึ่งรับ option ของ Intl.NumberFormat ได้ทั้งหมด เช่น ตัวคั่นหลักพัน สกุลเงิน เปอร์เซ็นต์ หน่วย ระหว่างพิมพ์ผู้ใช้พิมพ์อะไรก็ได้ แล้วช่องจะจัดรูปแบบให้เมื่อออกจากช่อง ค่ายังคงเป็นตัวเลขธรรมดา: ฿1,234.50 ส่งค่า 1234.5 และรูปแบบเปอร์เซ็นต์ให้ค่าเป็นเศษส่วน (0.5 สำหรับ 50%) locale ใช้ภาษาของหน้า หรือกำหนดด้วย locale

HTMLReactReact + Tailwind<ui-number-input label="เงินมัดจำ" name="deposit" value="45000" min="0" prefix-text="฿"></ui-number-input> <ui-number-input label="ค่าเช่าต่อเดือน" name="rent" type="text" value="18500" format-options='{"style":"currency","currency":"THB"}'></ui-number-input> <UiNumberInput label="เงินมัดจำ" name="deposit" value="45000" min={0} prefixText="฿" /> <UiNumberInput label="ค่าเช่าต่อเดือน" name="rent" type="text" value="18500" formatOptions={{ style: 'currency', currency: 'THB' }} /> <NumberInput label="เงินมัดจำ" name="deposit" defaultValue={45000} min={0} prefixText="฿" /> <NumberInput label="ค่าเช่าต่อเดือน" name="rent" type="text" defaultValue={18500} formatOptions={{ style: 'currency', currency: 'THB' }} />

เปอร์เซ็นต์และหน่วย

เมื่อใช้ format-options เครื่องหมายเปอร์เซ็นต์หรือหน่วยจะเป็นส่วนหนึ่งของข้อความที่จัดรูปแบบ ซึ่งเป็นวิธีของ Carbon รูปแบบเปอร์เซ็นต์เก็บค่าเป็นเศษส่วน: 7.5% คือ 0.075 จึงต้องใส่ step, min และ max เป็นเศษส่วนด้วย ใช้ locale เมื่อต้องการรูปแบบตัวเลขที่ไม่ตามภาษาของหน้า

HTMLReactReact + Tailwind<ui-number-input label="ส่วนลด" name="discount" type="text" value="0.075" step="0.005" min="0" max="1" format-options='{"style":"percent","maximumFractionDigits":1}' helper-text="7.5% ส่งค่า 0.075"></ui-number-input> <ui-number-input label="น้ำหนักสินค้า" name="weight" type="text" value="1250.5" step="0.5" min="0" format-options='{"style":"unit","unit":"kilogram"}'></ui-number-input> <UiNumberInput label="ส่วนลด" name="discount" type="text" value="0.075" step={0.005} min={0} max={1} formatOptions={{ style: 'percent', maximumFractionDigits: 1 }} helperText="7.5% ส่งค่า 0.075" /> <UiNumberInput label="น้ำหนักสินค้า" name="weight" type="text" value="1250.5" step={0.5} min={0} formatOptions={{ style: 'unit', unit: 'kilogram' }} /> <NumberInput label="ส่วนลด" name="discount" type="text" defaultValue={0.075} step={0.005} min={0} max={1} formatOptions={{ style: 'percent', maximumFractionDigits: 1 }} helperText="7.5% ส่งค่า 0.075" /> <NumberInput label="น้ำหนักสินค้า" name="weight" type="text" defaultValue={1250.5} step={0.5} min={0} formatOptions={{ style: 'unit', unit: 'kilogram' }} />

ช่องว่าง

แบบ Carbon ช่องตัวเลขที่ว่างถือว่ายังไม่ได้กรอก แม้ไม่ได้ตั้ง required ฟอร์มจะส่งไม่ได้จนกว่าจะมีตัวเลข ช่องที่ปล่อยว่างได้ให้ตั้ง allow-empty

HTMLReactReact + Tailwind<ui-number-input label="ที่จอดรถ (ไม่บังคับ)" name="parking" min="0" allow-empty></ui-number-input> <UiNumberInput label="ที่จอดรถ (ไม่บังคับ)" name="parking" min={0} allowEmpty /> <NumberInput label="ที่จอดรถ (ไม่บังคับ)" name="parking" min={0} allowEmpty />

ปุ่มเพิ่มลดและล้อเมาส์

  • hide-steppers เอาปุ่ม − / + ออก แต่ ↑ / ↓ ยังใช้ได้
  • disable-wheel ไม่ให้ล้อเมาส์เปลี่ยนค่าในช่องที่โฟกัสอยู่ ซึ่งเกิดขึ้นง่ายเวลาเลื่อนดูฟอร์มยาว ๆ
  • decrement-label และ increment-label เปลี่ยนชื่อปุ่มที่ screen reader อ่าน (ค่าเริ่มต้นคือ "ลดค่า" และ "เพิ่มค่า" ตามภาษาของหน้า)
HTMLReactReact + Tailwind<ui-number-input label="ปีที่สร้าง" name="year" value="2019" min="1900" max="2026" hide-steppers disable-wheel></ui-number-input> <UiNumberInput label="ปีที่สร้าง" name="year" value="2019" min={1900} max={2026} hideSteppers disableWheel /> <NumberInput label="ปีที่สร้าง" name="year" defaultValue={2019} min={1900} max={2026} hideSteppers disableWheel />

ขนาด ข้อความ อ่านอย่างเดียว และปิดใช้งาน

  • size: sm 32px, md 40px (ค่าเริ่มต้น), lg 48px
  • helper-text, warn + warn-text และ invalid + invalid-text ทำงานเหมือน text input ค่าที่อยู่นอก min / max จะได้ข้อความของเบราว์เซอร์หรือข้อความในตัว เว้นแต่ตั้ง invalid-text ไว้ ดูเพิ่มที่ ฟอร์มและการตรวจค่า
  • readonly แสดงและส่งค่าไปกับฟอร์ม และปุ่มเพิ่มลดจะกดไม่ได้ ส่วน disabled ทำให้ช่องเป็นสีเทาและไม่ส่งค่า
HTMLReactReact + Tailwind<ui-number-input label="จำนวนแขก" name="guests" value="12" warn warn-text="ห้องนี้นั่งได้ 10 คน"></ui-number-input> <ui-number-input label="จำนวนคนในทีม" name="team" value="42" min="1" max="30" invalid invalid-text="ไม่เกิน 30 คน"></ui-number-input> <ui-number-input label="ระยะเวลาสัญญา" name="months" value="24" suffix-text="เดือน" readonly></ui-number-input> <ui-number-input label="จำนวนชั้น" name="floors" value="3" size="sm" disabled></ui-number-input> <UiNumberInput label="จำนวนแขก" name="guests" value="12" warn warnText="ห้องนี้นั่งได้ 10 คน" /> <UiNumberInput label="จำนวนคนในทีม" name="team" value="42" min={1} max={30} invalid invalidText="ไม่เกิน 30 คน" /> <UiNumberInput label="ระยะเวลาสัญญา" name="months" value="24" suffixText="เดือน" readonly /> <UiNumberInput label="จำนวนชั้น" name="floors" value="3" size="sm" disabled /> <NumberInput label="จำนวนแขก" name="guests" defaultValue={12} warn warnText="ห้องนี้นั่งได้ 10 คน" /> <NumberInput label="จำนวนคนในทีม" name="team" defaultValue={42} min={1} max={30} invalid invalidText="ไม่เกิน 30 คน" /> <NumberInput label="ระยะเวลาสัญญา" name="months" defaultValue={24} suffixText="เดือน" readOnly /> <NumberInput label="จำนวนชั้น" name="floors" defaultValue={3} size="sm" disabled />

แบบ fluid

fluid (FluidNumberInput ของ Carbon) หรือการครอบด้วย <ui-fluid-form> ย้าย label เข้าไปในกล่องสูง 64px error หรือคำเตือนแสดงในกล่อง และไม่มี helper text ดู ฟอร์มแบบ fluid

HTMLReactReact + Tailwind<ui-number-input label="ค่าเช่าต่อเดือน" name="rent" value="18500" min="0" step="500" prefix-text="฿" fluid></ui-number-input> <UiNumberInput label="ค่าเช่าต่อเดือน" name="rent" value="18500" min={0} step={500} prefixText="฿" fluid /> <NumberInput label="ค่าเช่าต่อเดือน" name="rent" defaultValue={18500} min={0} step={500} prefixText="฿" fluid />

แบบมีขอบ (ดีไซน์ Kanok)

ในดีไซน์ Kanok ช่องกรอกเป็นแบบ filled โดยปกติ คือพื้นเทาอ่อน ไม่มีขอบ ใส่ data-field-variant="outlined" ที่ element ที่ครอบช่อง (เช่น <form> หรือ <html> ถ้าต้องการทั้งแอป) จะเปลี่ยนเป็นขอบ 1px บนพื้นใส ส่วน focus ยังเป็นวงแสงสีฟ้าเหมือนเดิม attribute นี้ไม่มีผลในดีไซน์ Carbon ตัวอย่างด้านล่างจึงครอบด้วย data-design="kanok" ดูรายละเอียดทั้งหมดที่ ดีไซน์ Kanok

HTMLReactReact + Tailwind<div data-design="kanok" data-theme="paper" data-field-variant="outlined"> <ui-number-input label="จำนวนห้อง" name="units" value="1" min="1" max="20"></ui-number-input> </div> <div data-field-variant="outlined"> <UiNumberInput label="จำนวนห้อง" name="units" value="1" min={1} max={20} /> </div> <div data-field-variant="outlined"> <NumberInput label="จำนวนห้อง" name="units" defaultValue={1} min={1} max={20} /> </div>

คำนวณยอดรวม

ฟัง input เพื่ออัปเดตยอดรวมทุกครั้งที่พิมพ์หรือกดเพิ่มลด valueAsNumber ให้ค่าเป็นตัวเลข หรือ NaN เมื่อช่องว่าง

ยอดรวม:

HTMLReactReact + Tailwind<ui-number-input id="number-input-qty" label="จำนวน" name="qty" value="2" min="1" max="50"></ui-number-input> <ui-number-input id="number-input-price" label="ราคาต่อหน่วย" name="price" value="1500" min="0" step="100" prefix-text="฿"></ui-number-input> <p>ยอดรวม: <output id="number-input-total"></output></p> <script type="module"> const qty = document.getElementById('number-input-qty'); const price = document.getElementById('number-input-price'); const baht = new Intl.NumberFormat('th', { style: 'currency', currency: 'THB' }); const update = () => { const total = qty.valueAsNumber * price.valueAsNumber; document.getElementById('number-input-total').textContent = Number.isNaN(total) ? '–' : baht.format(total); }; qty.addEventListener('input', update); price.addEventListener('input', update); update(); </script> <UiNumberInput label="จำนวน" name="qty" value={qty} min={1} max={50} onInput={(e) => setQty((e.target as HTMLInputElement).value)} /> <UiNumberInput label="ราคาต่อหน่วย" name="price" value={price} min={0} step={100} prefixText="฿" onInput={(e) => setPrice((e.target as HTMLInputElement).value)} /> <p>ยอดรวม: {baht.format(Number(qty) * Number(price))}</p> <NumberInput label="จำนวน" name="qty" value={qty} min={1} max={50} onChange={setQty} /> <NumberInput label="ราคาต่อหน่วย" name="price" value={price} min={0} step={100} prefixText="฿" onChange={setPrice} /> <p>ยอดรวม: {baht.format(Number(qty) * Number(price))}</p>

ใช้ในฟอร์ม

เมื่อใส่ name ช่องจะส่งค่าเป็นตัวเลขธรรมดา: ค่าเช่าที่แสดงเป็น ฿18,500.00 ด้านล่างส่งค่า 18500 ค่าที่อยู่นอก min / max หรือช่องว่างที่ไม่ได้ตั้ง allow-empty จะทำให้ส่งฟอร์มไม่ได้และแสดง error ลองใส่ 72 เดือน

บันทึกเงื่อนไข

ส่งค่า:

HTMLReactReact + Tailwind<form id="number-input-form" method="dialog" style="display: grid; gap: 16px"> <ui-number-input label="ค่าเช่าต่อเดือน" name="rent" type="text" value="18500" min="0" format-options='{"style":"currency","currency":"THB"}'></ui-number-input> <ui-number-input label="ระยะเวลาสัญญา" name="months" value="12" min="1" max="60" suffix-text="เดือน"></ui-number-input> <div><ui-button type="submit" size="md">บันทึกเงื่อนไข</ui-button></div> </form> <p>ส่งค่า: <output id="number-input-form-out"></output></p> <script type="module"> const form = document.getElementById('number-input-form'); form.addEventListener('submit', (event) => { event.preventDefault(); document.getElementById('number-input-form-out').textContent = [...new FormData(form)].map(([key, value]) => `${key}=${value}`).join(', '); }); </script> <form onSubmit={(e) => { e.preventDefault(); saveTerms(new FormData(e.currentTarget)); }}> <UiNumberInput label="ค่าเช่าต่อเดือน" name="rent" type="text" value="18500" min={0} formatOptions={{ style: 'currency', currency: 'THB' }} /> <UiNumberInput label="ระยะเวลาสัญญา" name="months" value="12" min={1} max={60} suffixText="เดือน" /> <UiButton type="submit" size="md">บันทึกเงื่อนไข</UiButton> </form> <form onSubmit={(e) => { e.preventDefault(); saveTerms(new FormData(e.currentTarget)); }}> <NumberInput label="ค่าเช่าต่อเดือน" name="rent" type="text" defaultValue={18500} min={0} formatOptions={{ style: 'currency', currency: 'THB' }} /> <NumberInput label="ระยะเวลาสัญญา" name="months" defaultValue={12} min={1} max={60} suffixText="เดือน" /> <Button type="submit" size="md">บันทึกเงื่อนไข</Button> </form>

Skeleton

ระหว่างที่ข้อมูลของฟอร์มกำลังโหลด <ui-number-input-skeleton> จองที่ของช่องไว้ เป็นแถบ label กับแถบช่องสูงตาม size หรือเป็นกล่องแบบ fluid เมื่อใส่ fluid screen reader ข้ามแถบนี้ จึงต้องบอกว่า "กำลังโหลด" ที่ฟอร์มแทน (เช่น aria-busy="true")

HTMLReactReact + Tailwind<ui-number-input-skeleton></ui-number-input-skeleton> <ui-number-input-skeleton fluid></ui-number-input-skeleton> import { UiNumberInputSkeleton } from '@purpurabog/ui/react'; <UiNumberInputSkeleton /> <UiNumberInputSkeleton fluid /> import { NumberInputSkeleton } from '@/components/ui/react-tw/number-input'; <NumberInputSkeleton /> <NumberInputSkeleton fluid />

คีย์บอร์ด

ปุ่ม ผล
↑ / ↓ เพิ่มหรือลดหนึ่ง step ภายในช่วง min / max
Enter ยืนยันค่าและส่งฟอร์มที่ช่องนี้อยู่

ปุ่ม − / + ไม่อยู่ในลำดับ Tab แบบ Carbon เพราะลูกศรในช่องทำงานเดียวกันได้

Accessibility

  • label เป็น <label> จริงที่ผูกกับ <input> ข้างใน ส่วน prefix, suffix และบรรทัดข้อความใต้ช่องเป็นคำอธิบายของมัน
  • ปุ่ม − / + มีชื่อ ("ลดค่า", "เพิ่มค่า") และกดไม่ได้เมื่อถึงปลายช่วง
  • inputmode="decimal" เปิดคีย์บอร์ดที่มีจุดทศนิยมบนมือถือ

ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Number input

API

สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)

<ui-number-input> · React UiNumberInput

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 '' The field text; valueAsNumber gives the parsed number (NaN while empty or invalid).
name name string '' Reflected: form-associated elements submit under the name attribute.
placeholder placeholder string ''
prefix-text prefixText string '' Text inside the field before the value, e.g. a currency (฿); not part of value. Part of the field's description for screen readers.
suffix-text suffixText string '' Text inside the field after the value, e.g. a unit (kg); not part of value. Part of the field's description for screen readers.
min min number | undefined
max max number | undefined
step step number 1 Step of the ± buttons and ↑ / ↓; with type="number" also the allowed precision.
step-start-value stepStartValue number 0 Where the steppers start from an empty field (Carbon stepStartValue); 0 = Carbon's rule: ±1, or min when only a minimum is set.
type type NumberInputType 'number' number: a native number field. text: a text field formatted for locale with format-options (Carbon type="text").
locale locale string '' BCP 47 locale of the formatting with type="text"; empty = the page language (lang on the element, an ancestor or <html>), as ui-date-picker.
format-options formatOptions Intl.NumberFormatOptions {} Intl.NumberFormat options with type="text", e.g. {"style":"currency","currency":"THB"} or {"maximumFractionDigits":2}.
allow-empty allowEmpty boolean false An empty field is valid (Carbon allowEmpty); otherwise empty counts as missing.
hide-steppers hideSteppers boolean false Remove the − / + buttons (keyboard stepping still works).
disable-wheel disableWheel boolean false Ignore mouse-wheel changes while focused (Carbon disableWheel).
size size NumberInputSize 'md' Field height: sm 32px, md 40px, lg 48px (tokens --ui-field-height-*).
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
readonly readonly boolean false Shows and submits the value but blocks changes.
fluid fluid boolean false Carbon FluidNumberInput: the label inside a 64px box, an error / warning inside it. <ui-fluid-form> sets it for every field inside.
required required boolean false Blocks form submission while the field is empty.
decrement-label decrementLabel string '' Accessible name of the − button.
increment-label incrementLabel string '' Accessible name of the + button.

Property

Property ชนิด คำอธิบาย
valueAsNumber (อ่านอย่างเดียว) The parsed value, NaN while empty or not a number.
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 After a committed change (blur / Enter / stepper; with type="text", on blur when the number changed)
input onInput On every keystroke or stepper click

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

CSS part

Part คำอธิบาย
base The field box
label The label
input The native input
prefix The text before the value
suffix The text after the value
controls The stepper group
decrement-button The − button
increment-button The + button
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)

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-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)