حقل الوسوم

TagInput

حقل وسوم في React يحوّل النص المكتوب إلى شرائح قابلة للإزالة، مع تحقّق وحدّ أقصى ومنع التكرار وربط للحقل. يعمل بلوحة المفاتيح وبالعربية.

يثبت Enter أو الفاصلة النص حبة، ويحذف Backspace آخر واحدة. يزيل التكرار ويدعم max وvalidate.

متى تستخدمه

استخدم TagInput لجمع عدّة قيم قصيرة حرّة: مستلمي بريد، أو كلمات مفتاحية، أو أرقام مرجعية. استخدم validate لرفض المدخلات غير الصحيحة وmax لتحديد العدد.

حين تأتي القيم من قائمة ثابتة، استخدم Dropdown مع multiple ليختار المستخدم بدل أن يكتب.

أمثلة

وسوم مُتحكَّم بها

بحدٍّ أقصى ثلاثة

مستلمو بريد مُتحقَّق منهم

تسميات عربية

الخصائص

الخصائص التي يعرّفها TagInput. سمات العنصر الأصلي تمرّ كما هي.

الخاصيةالنوعالافتراضيالوصف
size"sm" | "md" | "lg"
valuestring[]Controlled tag list.
defaultValuestring[]Uncontrolled initial tag list.
onChange(tags: string[]) => voidFires with the full accepted tag set after every add/remove.
labelreact.ReactNodeVisible field label, associated to the text input.
helperTextreact.ReactNodeHint shown below the field. Hidden while an error message is showing.
errorMessagereact.ReactNodeMessage shown below the field when invalid.
errorbooleanMarks the field invalid: sets aria-invalid and error styling.
maxnumberCaps the number of tags. Adds beyond the cap are no-ops.
allowDuplicatesbooleanAllow the same tag more than once. Off → duplicates are rejected.
caseSensitivebooleanMake duplicate detection case-sensitive. Default: case-insensitive.
validate(tag: string, tags: string[]) => booleanConsumer gate run on each candidate tag. Return false to reject (draft kept).
delimitersstring[]Characters that commit the draft and split a paste. Newline always splits a paste.
chipVariant"primary" | "secondary" | "outline" | "destructive" | "destructive-subtle" | "default" | "success" | "warning" | "info" | "primary-subtle" | "secondary-subtle" | "success-subtle" | "warning-subtle" | "info-subtle" | "on-color"Tag variant used for the chips.
removeLabel(tag: string) => stringAccessible name for each chip's remove button.
formatAnnouncement(tag: string, action: "add" | "remove") => stringLive-region text announced on add/remove (screen readers).

إمكانية الوصول

تُعرض الشرائح قائمةً، فيسمع قارئ الشاشة عدد القيم ويتنقّل بينها. يثبّت Enter أو الفاصلة القيمة ويحذف Backspace آخر واحدة، وتعلن منطقة حيّة الإضافات والحذف.

تُربط تسمية الحقل والنص المساعد والخطأ كما في TextInput. يحمل كل زر إزالة اسم الوسم في تسميته المتاحة.