انتقل إلى المحتوى
TopClass UI

الحقل

التسمية والتلميح والخطأ حول أي عنصر تحكم في النموذج، مربوطة به بالمعرّفات في HTML الخادم قبل تشغيل أي سكربت.

split - الحجم لم يُقَس بعد

الحقل

split - الحجم لم يُقَس بعد

التسمية والتلميح والخطأ حول أي عنصر تحكم في النموذج، مربوطة به بالمعرّفات في HTML الخادم قبل تشغيل أي سكربت.

تثبيت

الشيفرة

field.tsx
import { Input } from 'topclassui/input'
import { Field } from 'topclassui/field'

/** The label points at the input, and the input is named by it before any script runs. */
export default function Demo() {
  return (
    <div className="grid max-w-sm">
      <Field name="email" label="Email">
        {(control) => <Input {...control} type="email" autoComplete="email" fullWidth />}
      </Field>
    </div>
  )
}

لا يوجد مكوّن Label: التسمية هي هذه الخاصية، والابن ينشر كائن التحكم على عنصر التحكم.

أو استورده من الحزمة

topclassui/field
import { Field } from 'topclassui/field'

ثبّت مرة واحدة:npm i topclassui@beta zod

أمثلة

  • في ملف خادم استخدم Field؛ وفي ملف عميل يعرض FieldLive نفس HTML ويُظهر الخطأ الذي أعاده أقرب FormAction لاسمه name.
  • الابن دالة، (control) => <Input {...control} />. كائن التحكم هو id وname وrequired وسمات ARIA الثلاث، وكل عنصر من عناصر التحكم الأحد عشر يأخذه كما هو.
  • المعرّفات تأتي من id أو useId()، لا من name أبدًا: قد يتشارك حقلان الاسم نفسه. مرّر id حين ترتبط صفحة بالحقل.
  • error رسالة واحدة أو المصفوفة التي يعطيها fieldErrors في Zod؛ ومع رسالة يصبح العنصر غير صالح ما لم يقل invalid غير ذلك.
  • inline يضع عنصر التحكم أولًا والتسمية بجانبه، لمربع الاختيار أو المفتاح.
basic
hint-error
Letters and numbers only
That name is taken
Shown on your profile
Too short
Add at least one sentence
Optional
required
We never share it
inline
About once a month
Turn it on to get the summary
group
You can change it later
controls
Input hint
Input error
Textarea hint
Textarea error
Checkbox hint
Checkbox error
Switch hint
Switch error
RadioGroup hint
RadioGroup error
SegmentedControl hint
SegmentedControl error
Slider hint
Slider error
NumberField hint
NumberField error
OTPField hint
OTPField error
Select hint
Select error
Combobox hint
Combobox error
form
We never share it
live
Shown to other players
Pick the size you ordered
long-content
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
بالعربية، من اليمين إلى اليسار
لن نشاركه مع أحد
هذا البريد مستخدم
اقرأها قبل المتابعة

الخصائص

خصائص Field
الخاصيةالنوعالافتراضيالحدودالوصف
children*(control: FieldControl) => ReactNode--Called with the control object, which the control spreads: (control) => <Input {...control} />. Client-only for FieldLive.
label*ReactNode--The visible name of the control.
name*string--The control's name, and the key of its errors in a FormAction's answer.
errorFieldError--One message or several, read after the hint; with one, the control is invalid unless invalid says otherwise.
hintReactNode--Text under the control that describes it: the first id of the control's aria-describedby.
idstring--The control's id; without it useId() makes one. Pass it when a page links to the field.
inlinebooleanfalse-The control first and the label beside it, the hint and the error under the label: for a Checkbox or a Switch.
invalidboolean--Sets aria-invalid on the control. Without it, true when error holds a message and false when it holds none.
requiredbooleanfalse-Passes required to the control, which tells a screen reader, and shows an asterisk that is only seen.

لوحة المفاتيح وإمكانية الوصول

لوحة مفاتيح Field
المفاتيحما يفعله
Tabينقل التركيز إلى عنصر التحكم؛ والحقل نفسه لا يأخذ التركيز.
  • التسمية تسمّي عنصر التحكم عبر <label for> وaria-labelledby؛ وaria-describedby يقرأ التلميح ثم الخطأ، وما يُعرض منهما فقط.
  • النجمة مرئية فقط: required يصل إلى عنصر التحكم، فيعلن ذلك بنفسه عبر required أو aria-required.
  • الخطأ ليس منطقة حيّة. يصل مع الصفحة، وبعد FormAction ينتقل التركيز إلى أول عنصر غير صالح.

من اليمين إلى اليسار

تبدأ التسمية والتلميح والخطأ من اليمين؛ والنجمة تتبع التسمية، ومربع الاختيار في الوضع inline يقع على اليمين.

الخادم والمتصفح

يُعرض على الخادم، والجزء التفاعلي مكوّن متصفح لا يُرسل إلا عند استخدامه.

الملفات: index.tsx, client.tsx.

على الشارة: split - الحجم لم يُقَس بعد.