رفع الملفّات

FileUpload

رفع ملفّات في React بالسحب والإفلات، مع التحقّق من النوع والحجم، وحالة وتقدّم لكل ملف، ونمط زر مضغوط. متحكَّم به بالكامل وجاهز للاتجاه العربي.

FileUpload خاضع للتحكم بالكامل: أنت تملك مصفوفة files وتنفذ الرفع بنفسك وتحدث status لكل ملف. يتم التحقق عبر accept وmaxSize وmaxFiles.

متى تستخدمه

استخدم FileUpload للمرفقات مثل صور الهوية والعقود والمستندات الداعمة. اضبط accept وmaxSize وmaxFiles بحسب قواعد الخدمة، وحدّث status كل ملف مع تقدّم الرفع.

استخدم نمط الزر داخل النماذج الكثيفة ومنطقة الإفلات حين تكون الملفّات المهمّة الرئيسية. أبقِ القواعد ظاهرة في النص المساعد.

أمثلة

منطقة سحب وإفلات

ملف واحد (نمط الزر)

التحقق والرفض

الخصائص

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

الخاصيةالنوعالافتراضيالوصف
variant"button" | "dropzone"
filesإلزاميUploadFile[]Controlled list of files to render. The consumer is the source of truth.
onFilesAddedإلزامي(accepted: File[]) => voidCalled with the files that passed validation. The consumer wraps each in an {@link UploadFile} (assigning an id) and starts the upload.
onFilesRejected(rejections: FileRejection[]) => voidCalled with files that failed validation. Never enter files.
onRemove(id: string) => voidPer-row remove handler. Omit to hide the remove button.
acceptstringNative accept string (e.g. 'image/*,.pdf'). Also drives validation.
maxSizenumberMaximum size per file, in bytes.
maxFilesnumberMaximum total files (existing + incoming). When multiple is false this is forced to 1.
multiplebooleanAllow selecting/dropping more than one file. Defaults to true.
disabledbooleanDisables the drop zone / button and the picker.
requiredbooleanMarks the field required: renders the asterisk and sets the input's required attribute.
labelreact.ReactNodeVisible field label, auto-associated to the input.
titlereact.ReactNode
descriptionreact.ReactNode
buttonLabelreact.ReactNode
errorMessagereact.ReactNodeMessage shown below the field when error is true.
errorbooleanMarks the field invalid: sets aria-invalid and error styling.
removeLabelstringAccessible label for the per-row remove button. Defaults to 'Remove'.
idstring
classNamestring
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.

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

منطقة الإفلات زر أيضًا، فيفتح مستخدم لوحة المفاتيح منتقي الملفّات بـ Enter أو Space. تُعلن حالات الرفض عبر قائمة role="alert" مع سبب كل ملف.

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