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

Radio button

Radio button ใช้เลือกหนึ่งรายการพอดีจากตัวเลือกชุดเล็ก ๆ ที่เห็นครบทุกตัว เมื่อเลือกแล้ว ผู้ใช้เปลี่ยนได้แต่ล้างทิ้งไม่ได้

โอนผ่านธนาคาร บัตรเครดิต เงินสดที่สาขา
HTMLReactReact + Tailwind<ui-radio-group label="วิธีชำระเงิน" name="payment" value="transfer"> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> <ui-radio value="card">บัตรเครดิต</ui-radio> <ui-radio value="cash">เงินสดที่สาขา</ui-radio> </ui-radio-group> <UiRadioGroup label="วิธีชำระเงิน" name="payment" value="transfer"> <UiRadio value="transfer">โอนผ่านธนาคาร</UiRadio> <UiRadio value="card">บัตรเครดิต</UiRadio> <UiRadio value="cash">เงินสดที่สาขา</UiRadio> </UiRadioGroup> <RadioGroup label="วิธีชำระเงิน" name="payment" defaultValue="transfer"> <Radio value="transfer">โอนผ่านธนาคาร</Radio> <Radio value="card">บัตรเครดิต</Radio> <Radio value="cash">เงินสดที่สาขา</Radio> </RadioGroup>

ติดตั้ง

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

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

วิธีใช้

HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/radio';</script> <ui-radio-group label="วิธีชำระเงิน" name="payment"> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> <ui-radio value="card">บัตรเครดิต</ui-radio> </ui-radio-group> import { UiRadio, UiRadioGroup } from '@purpurabog/ui/react'; <UiRadioGroup label="วิธีชำระเงิน" name="payment"> <UiRadio value="transfer">โอนผ่านธนาคาร</UiRadio> <UiRadio value="card">บัตรเครดิต</UiRadio> </UiRadioGroup> import { Radio, RadioGroup } from '@/components/ui/react-tw/radio-group'; <RadioGroup label="วิธีชำระเงิน" name="payment"> <Radio value="transfer">โอนผ่านธนาคาร</Radio> <Radio value="card">บัตรเครดิต</Radio> </RadioGroup>

Radio ต้องอยู่ในกลุ่มเสมอ กลุ่มเป็นตัวเก็บ label, name และค่า และส่ง value ของตัวเลือกที่ติ๊กไว้ไปกับฟอร์ม ถ้ามีมากกว่าห้าตัวเลือกหรือที่ไม่พอ ให้ใช้ Select หรือ Dropdown

ค่าเริ่มต้นและการเปลี่ยนค่า

value ของกลุ่มคือตัวเลือกที่ติ๊กไว้ ถ้าไม่มี <ui-radio checked> จะเป็นค่าเริ่มต้น ถ้าไม่มีทั้งสองอย่างก็ไม่มีตัวไหนถูกติ๊ก การ reset จะกลับไปที่ค่าเริ่มต้น event change ยิงที่กลุ่มเมื่อผู้ใช้เลือกตัวเลือกอื่น

โอนผ่านธนาคาร บัตรเครดิต เงินสดที่สาขา

ค่า:

HTMLReactReact + Tailwind<ui-radio-group id="radio-payment" label="วิธีชำระเงิน" name="payment" value="card"> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> <ui-radio value="card">บัตรเครดิต</ui-radio> <ui-radio value="cash">เงินสดที่สาขา</ui-radio> </ui-radio-group> <p>ค่า: <output id="radio-payment-out"></output></p> <script type="module"> const payment = document.getElementById('radio-payment'); const out = document.getElementById('radio-payment-out'); out.value = payment.value; payment.addEventListener('change', () => (out.value = payment.value)); </script> import type { UiRadioGroup as RadioGroupElement } from '@purpurabog/ui'; const [payment, setPayment] = useState('card'); <UiRadioGroup label="วิธีชำระเงิน" name="payment" value={payment} onChange={(e) => setPayment((e.target as RadioGroupElement).value)}>…</UiRadioGroup> <p>ค่า: <output>{payment}</output></p> const [payment, setPayment] = useState('card'); <RadioGroup label="วิธีชำระเงิน" name="payment" value={payment} onValueChange={setPayment}>…</RadioGroup> <p>ค่า: <output>{payment}</output></p>

แนวการเรียง

กลุ่มเรียงแนวตั้งเป็นค่าเริ่มต้น orientation="horizontal" เรียงตัวเลือกเป็นแถวแนวนอน ใช้กับตัวเลือกสั้น ๆ สองสามตัว

6 เดือน 1 ปี 3 ปี
HTMLReactReact + Tailwind<ui-radio-group label="ระยะเวลาสัญญา" name="length" orientation="horizontal" value="12"> <ui-radio value="6">6 เดือน</ui-radio> <ui-radio value="12">1 ปี</ui-radio> <ui-radio value="36">3 ปี</ui-radio> </ui-radio-group> <UiRadioGroup label="ระยะเวลาสัญญา" name="length" orientation="horizontal" value="12"> <UiRadio value="6">6 เดือน</UiRadio> <UiRadio value="12">1 ปี</UiRadio> <UiRadio value="36">3 ปี</UiRadio> </UiRadioGroup> <RadioGroup label="ระยะเวลาสัญญา" name="length" orientation="horizontal" defaultValue="12"> <Radio value="6">6 เดือน</Radio> <Radio value="12">1 ปี</Radio> <Radio value="36">3 ปี</Radio> </RadioGroup>

ตำแหน่งของ label

label-position="left" วางข้อความของแต่ละตัวเลือกไว้ก่อนวงกลม (คือ labelPosition ของ Carbon) กลุ่มแนวตั้งจะจัดวงกลมให้ตรงกันที่ปลายด้านท้าย ตั้งที่ radio ตัวเดียวถ้าต้องการย้ายแค่ตัวนั้น

ภายในก่อน พร้อมกัน ภายนอกก่อน
HTMLReactReact + Tailwind<ui-radio-group label="ลำดับการลงนาม" name="order" label-position="left" value="internal"> <ui-radio value="internal">ภายในก่อน</ui-radio> <ui-radio value="parallel">พร้อมกัน</ui-radio> <ui-radio value="external">ภายนอกก่อน</ui-radio> </ui-radio-group> <UiRadioGroup label="ลำดับการลงนาม" name="order" labelPosition="left" value="internal"> <UiRadio value="internal">ภายในก่อน</UiRadio> <UiRadio value="parallel">พร้อมกัน</UiRadio> <UiRadio value="external">ภายนอกก่อน</UiRadio> </UiRadioGroup> <RadioGroup label="ลำดับการลงนาม" name="order" labelPosition="left" defaultValue="internal"> <Radio value="internal">ภายในก่อน</Radio> <Radio value="parallel">พร้อมกัน</Radio> <Radio value="external">ภายนอกก่อน</Radio> </RadioGroup>

ข้อความช่วยเหลือ คำเตือน และ error

กลุ่มมีบรรทัดข้อความหนึ่งบรรทัดใต้ตัวเลือก คือ helper-text, warn คู่กับ warn-text ที่ไม่บล็อกการส่ง และ invalid คู่กับ invalid-text error มาก่อนคำเตือน และคำเตือนมาก่อนข้อความช่วยเหลือ

ภายในก่อน ภายนอกก่อน อีเมล ไปรษณีย์ลงทะเบียน กฎหมายไทย กฎหมายสิงคโปร์
HTMLReactReact + Tailwind<ui-radio-group label="ลำดับการลงนาม" name="order1" value="internal" helper-text="ใครลงนามก่อน"> <ui-radio value="internal">ภายในก่อน</ui-radio> <ui-radio value="external">ภายนอกก่อน</ui-radio> </ui-radio-group> <ui-radio-group label="การส่งสำเนาที่ลงนามแล้ว" name="delivery" value="post" warn warn-text="ไปรษณีย์ลงทะเบียนใช้เวลา 3 ถึง 5 วันทำการ"> <ui-radio value="email">อีเมล</ui-radio> <ui-radio value="post">ไปรษณีย์ลงทะเบียน</ui-radio> </ui-radio-group> <ui-radio-group label="กฎหมายที่ใช้บังคับ" name="law" invalid invalid-text="เลือกกฎหมายที่ใช้บังคับกับสัญญา"> <ui-radio value="th">กฎหมายไทย</ui-radio> <ui-radio value="sg">กฎหมายสิงคโปร์</ui-radio> </ui-radio-group> <UiRadioGroup label="ลำดับการลงนาม" name="order1" value="internal" helperText="ใครลงนามก่อน">…</UiRadioGroup> <UiRadioGroup label="การส่งสำเนาที่ลงนามแล้ว" name="delivery" value="post" warn warnText="ไปรษณีย์ลงทะเบียนใช้เวลา 3 ถึง 5 วันทำการ">…</UiRadioGroup> <UiRadioGroup label="กฎหมายที่ใช้บังคับ" name="law" invalid invalidText="เลือกกฎหมายที่ใช้บังคับกับสัญญา">…</UiRadioGroup> <RadioGroup label="ลำดับการลงนาม" name="order1" defaultValue="internal" helperText="ใครลงนามก่อน">…</RadioGroup> <RadioGroup label="การส่งสำเนาที่ลงนามแล้ว" name="delivery" defaultValue="post" warn warnText="ไปรษณีย์ลงทะเบียนใช้เวลา 3 ถึง 5 วันทำการ">…</RadioGroup> <RadioGroup label="กฎหมายที่ใช้บังคับ" name="law" invalid invalidText="เลือกกฎหมายที่ใช้บังคับกับสัญญา">…</RadioGroup>

ตัวเลือกที่ปิดใช้งาน อ่านอย่างเดียว และปิดใช้งาน

  • disabled ที่ radio ตัวเดียวจะข้ามตัวนั้น ถ้าใส่ที่กลุ่มจะปิดทุกตัวเลือกและกลุ่มไม่ถูกส่งไปกับฟอร์ม
  • readonly (readOnly ใน React + Tailwind) คงค่าไว้และส่งไปกับฟอร์ม ปุ่มลูกศรยังย้ายโฟกัสเพื่ออ่านตัวเลือกได้ แต่ไม่มีอะไรเปลี่ยน
โอนผ่านธนาคาร เงินสดที่สาขา โอนผ่านธนาคาร เงินสดที่สาขา
HTMLReactReact + Tailwind<ui-radio-group label="วิธีชำระเงิน" value="transfer" readonly> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> <ui-radio value="cash" disabled>เงินสดที่สาขา</ui-radio> </ui-radio-group> <ui-radio-group label="วิธีชำระเงิน" value="transfer" disabled> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> <ui-radio value="cash">เงินสดที่สาขา</ui-radio> </ui-radio-group> <UiRadioGroup label="วิธีชำระเงิน" value="transfer" readonly> <UiRadio value="transfer">โอนผ่านธนาคาร</UiRadio> <UiRadio value="cash" disabled>เงินสดที่สาขา</UiRadio> </UiRadioGroup> <UiRadioGroup label="วิธีชำระเงิน" value="transfer" disabled>…</UiRadioGroup> <RadioGroup label="วิธีชำระเงิน" defaultValue="transfer" readOnly> <Radio value="transfer">โอนผ่านธนาคาร</Radio> <Radio value="cash" disabled>เงินสดที่สาขา</Radio> </RadioGroup> <RadioGroup label="วิธีชำระเงิน" defaultValue="transfer" disabled>…</RadioGroup>

แสดงช่องเพิ่มสำหรับบางตัวเลือก

บางตัวเลือกต้องการรายละเอียดเพิ่มที่ใช้กับตัวเลือกนั้นเท่านั้น เช่น เลขที่บัญชีเมื่อเลือกโอน ให้ฟัง change แล้วแสดงช่องเพิ่มเฉพาะตอนเลือกตัวนั้น

เงินสดที่สาขา โอนผ่านธนาคาร
HTMLReactReact + Tailwind<ui-radio-group id="radio-refund" label="คืนเงินประกันโดย" name="refund" value="cash"> <ui-radio value="cash">เงินสดที่สาขา</ui-radio> <ui-radio value="transfer">โอนผ่านธนาคาร</ui-radio> </ui-radio-group> <div id="radio-refund-account" hidden> <ui-text-input label="เลขที่บัญชี" name="account" helper-text="บัญชีของผู้เช่าเอง"></ui-text-input> </div> <script type="module"> const refund = document.getElementById('radio-refund'); const account = document.getElementById('radio-refund-account'); refund.addEventListener('change', () => (account.hidden = refund.value !== 'transfer')); </script> const [refund, setRefund] = useState('cash'); <UiRadioGroup label="คืนเงินประกันโดย" name="refund" value={refund} onChange={(e) => setRefund((e.target as RadioGroupElement).value)}> <UiRadio value="cash">เงินสดที่สาขา</UiRadio> <UiRadio value="transfer">โอนผ่านธนาคาร</UiRadio> </UiRadioGroup> {refund === 'transfer' && <UiTextInput label="เลขที่บัญชี" name="account" helperText="บัญชีของผู้เช่าเอง" />} const [refund, setRefund] = useState('cash'); <RadioGroup label="คืนเงินประกันโดย" name="refund" value={refund} onValueChange={setRefund}> <Radio value="cash">เงินสดที่สาขา</Radio> <Radio value="transfer">โอนผ่านธนาคาร</Radio> </RadioGroup> {refund === 'transfer' && <TextInput label="เลขที่บัญชี" name="account" helperText="บัญชีของผู้เช่าเอง" />}

บังคับเลือกในฟอร์ม

required ที่กลุ่มทำให้ส่งฟอร์มไม่ได้จนกว่าจะเลือก โดยมีข้อความในตัว (required-text ใช้เปลี่ยนข้อความ) ที่เหลือดูที่ ฟอร์มและการตรวจค่า ลองกดส่งโดยยังไม่เลือกเพื่อดูข้อความ

ซื้อขาย เช่า
ส่ง

ค่าที่ส่ง:

HTMLReactReact + Tailwind<form id="radio-form" style="display: grid; gap: 16px"> <ui-radio-group label="ประเภทสัญญา" name="type" required required-text="เลือกประเภทสัญญา"> <ui-radio value="sale">ซื้อขาย</ui-radio> <ui-radio value="lease">เช่า</ui-radio> </ui-radio-group> <div><ui-button type="submit">ส่ง</ui-button></div> </form> <p>ค่าที่ส่ง: <output id="radio-form-out"></output></p> <script type="module"> const form = document.getElementById('radio-form'); form.addEventListener('submit', (event) => { event.preventDefault(); document.getElementById('radio-form-out').value = [...new FormData(form)].map(([key, value]) => `${key}=${value}`).join(', '); }); </script> <form onSubmit={submit}> <UiRadioGroup label="ประเภทสัญญา" name="type" required requiredText="เลือกประเภทสัญญา"> <UiRadio value="sale">ซื้อขาย</UiRadio> <UiRadio value="lease">เช่า</UiRadio> </UiRadioGroup> <UiButton type="submit">ส่ง</UiButton> </form> <p>ค่าที่ส่ง: <output>{sent}</output></p> // การตรวจค่าเป็นของแอป: `tried` เป็น true หลังกดส่งครั้งแรก <form onSubmit={submit}> <RadioGroup label="ประเภทสัญญา" name="type" value={type} onValueChange={setType} required invalid={tried && !type} invalidText="เลือกประเภทสัญญา"> <Radio value="sale">ซื้อขาย</Radio> <Radio value="lease">เช่า</Radio> </RadioGroup> <Button type="submit">ส่ง</Button> </form> <p>ค่าที่ส่ง: <output>{sent}</output></p>

submit กันไม่ให้หน้าเปลี่ยน แล้วเก็บ new FormData(form) ไว้ใน sent เหมือนใน HTML

Radio tile

กลุ่มเดียวกันนี้ใส่ radio tile (<ui-radio-tile> จาก @purpurabog/ui/selection-tiles) ได้ด้วย เมื่อแต่ละตัวเลือกต้องการพื้นที่มากขึ้น เช่น หัวข้อกับคำอธิบายหนึ่งบรรทัด เครื่องหมายถูกแสดงเฉพาะที่ tile ที่เลือก

ลายมือชื่ออิเล็กทรอนิกส์
ลงนามออนไลน์ได้ในไม่กี่นาที
กระดาษ
พิมพ์ ลงนาม แล้วสแกน
แบบผสม
เร็ว ๆ นี้
HTMLReactReact + Tailwind<ui-radio-group label="วิธีลงนาม" name="method" orientation="horizontal" value="esign"> <ui-radio-tile value="esign"><b>ลายมือชื่ออิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</ui-radio-tile> <ui-radio-tile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</ui-radio-tile> <ui-radio-tile value="hybrid" disabled><b>แบบผสม</b><br />เร็ว ๆ นี้</ui-radio-tile> </ui-radio-group> import { UiRadioTile } from '@purpurabog/ui/react'; <UiRadioGroup label="วิธีลงนาม" name="method" orientation="horizontal" value="esign"> <UiRadioTile value="esign"><b>ลายมือชื่ออิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</UiRadioTile> <UiRadioTile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</UiRadioTile> <UiRadioTile value="hybrid" disabled><b>แบบผสม</b><br />เร็ว ๆ นี้</UiRadioTile> </UiRadioGroup> // npx shadcn@4 add @kanok-ui/tw-tile import { RadioTile } from '@/components/ui/react-tw/tile'; <RadioGroup label="วิธีลงนาม" name="method" orientation="horizontal" defaultValue="esign"> <RadioTile value="esign"><b>ลายมือชื่ออิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</RadioTile> <RadioTile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</RadioTile> <RadioTile value="hybrid" disabled><b>แบบผสม</b><br />เร็ว ๆ นี้</RadioTile> </RadioGroup>

Skeleton

ระหว่างโหลดตัวเลือก ให้แสดง ui-radio-skeleton ตัวเลือกละหนึ่งตัว เป็นแถบ label (Carbon ไม่วาดวงกลม) skeleton ถูกซ่อนจาก screen reader จึงต้องบอกว่ากำลังโหลดที่ container เช่น aria-busy

HTMLReactReact + Tailwind<div aria-busy="true"> <ui-radio-skeleton></ui-radio-skeleton> <ui-radio-skeleton></ui-radio-skeleton> <ui-radio-skeleton></ui-radio-skeleton> </div> import { UiRadioSkeleton } from '@purpurabog/ui/react'; <div aria-busy="true"> <UiRadioSkeleton /> <UiRadioSkeleton /> <UiRadioSkeleton /> </div> import { RadioSkeleton } from '@/components/ui/react-tw/radio-group'; <div aria-busy="true"> <RadioSkeleton /> <RadioSkeleton /> <RadioSkeleton /> </div>

ใน web component ให้ import จาก @purpurabog/ui/radio-skeleton

คีย์บอร์ด

ปุ่ม ทำอะไร
Tab เข้ากลุ่มที่ตัวเลือกที่ติ๊กไว้ (ถ้าไม่มีก็ตัวแรก) และออกจากกลุ่มเมื่อกด Tab อีกครั้ง
↓ / → ย้ายไปตัวเลือกถัดไปและติ๊ก วนจากตัวสุดท้ายกลับไปตัวแรก
↑ / ← ย้ายไปตัวเลือกก่อนหน้าและติ๊ก วนจากตัวแรกไปตัวสุดท้าย
Space ติ๊กตัวเลือกที่โฟกัสอยู่

Accessibility

  • กลุ่มเป็น role="radiogroup" ที่ใช้ label เป็นชื่อ และมีจุดหยุดของ Tab จุดเดียวตาม pattern radio group ของ WAI-ARIA ตัวเลือกที่ปิดใช้งานจะถูกข้าม
  • ข้อความช่วยเหลือ คำเตือน หรือ error ของกลุ่มเป็นคำอธิบายของกลุ่ม และ radio แต่ละตัวทวน error ซ้ำ screen reader จึงได้ยินที่ตัวเลือกที่ไปถึง
  • ใช้ hide-label เฉพาะเมื่อบริบทรอบ ๆ บอกอยู่แล้วว่ากลุ่มนี้คืออะไร label จะยังอยู่ให้ screen reader อ่าน

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

API

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

<ui-radio-group> · React UiRadioGroup

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
label label string '' Group label (rendered like a fieldset legend).
hide-label hideLabel boolean false Keep the group label for screen readers but don't show it.
name name string '' Reflected: form-associated elements submit under the name attribute.
value value string ''
orientation orientation 'vertical' | 'horizontal' 'vertical'
label-position labelPosition RadioLabelPosition 'right' Carbon labelPosition: left puts each radio's text before its circle (default right, after it).
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.
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.
required-text requiredText string '' Error text for an empty required group.

Property

Property ชนิด คำอธิบาย
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 คำอธิบาย
input ไม่มี (ใช้ ref)
change ไม่มี (ใช้ ref) When the user picks an option

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) <ui-radio> options
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 group box holding the radios
label The group label
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)

<ui-radio> · React UiRadio

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
value value string ''
checked checked boolean false
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
label-position labelPosition RadioLabelPosition | undefined Carbon labelPosition: left puts the text before the circle; unset, the group's label-position applies.

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Label text

CSS part

Part คำอธิบาย
circle The drawn radio circle
label The text beside it

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-radio-border Ring colour (default --ui-ink; Kanok: --ui-ink-subtle)
--ui-radio-checked Ring and dot when chosen (default --ui-ink; Kanok: --ui-primary)

<ui-radio-tile> · React UiRadioTile

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
value value string ''
checked checked boolean false
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
label-position labelPosition RadioLabelPosition | undefined Carbon labelPosition: left puts the text before the circle; unset, the group's label-position applies.

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Tile content (title, description…)

CSS part

Part คำอธิบาย
circle The drawn radio circle
label The text beside it

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-tile-border-color Border of an unchosen tile (default transparent; Kanok: a hairline); --ui-card-radius its corners
--ui-card-background Its fill (default --ui-surface-1; Kanok paper: a cool grey that sets it apart from the page, no border)
--ui-tile-selected-border Border of the chosen tile (default --ui-layer-selected-inverse; Kanok: primary blue); --ui-tile-selected-mark its check mark (default --ui-icon-primary)
--ui-tile-selected-background Fill of the chosen tile (default --ui-card-background; Kanok: soft highlight wash)
--ui-tile-mark-space End padding kept clear for the mark (default 48px, Carbon's); e.g. 16px lets the content run under the mark in the top-end corner (beyond Carbon)
--ui-radio-border Ring colour (default --ui-ink; Kanok: --ui-ink-subtle)
--ui-radio-checked Ring and dot when chosen (default --ui-ink; Kanok: --ui-primary)