قائمة منسدلة (Select)

يعرض مكوّن قائمة منسدلة (Select) عنصر select الأصلي بتنسيق مخصص.

التثبيت

bash
npx @smicolon/fasla-ui@latest add select

قبل إضافة أي مكوّن، شغّل الأمر init مرة واحدة في مشروعك. التفاصيل في صفحة التثبيت.

معاينة

الأحجام

الحالات

الخصائص (props)

الخاصيةالنوعالافتراضيالوصف
optionsSelectOption[]لا يوجدالخيارات المتاحة للاختيار.
placeholderstringلا يوجدنص يظهر قبل الاختيار.
selectSize"sm" | "default" | "lg""default"حجم القائمة.
errorbooleanfalseيعلّم القائمة بأنها غير صالحة.
disabledbooleanfalseيعطّل القائمة ويُظهرها باهتة.
valuestringلا يوجدالقيمة المحددة، وتُستخدم مع onChange.
namestringلا يوجدالاسم الذي يُرسَل مع النموذج.
onChange(event) => voidلا يوجدتُستدعى عند تغيير الاختيار.
classNamestringلا يوجدأصناف (class) إضافية للمكوّن.

الاستخدام

قائمة منسدلة بسيطة

tsx
import { Select } from "@/components/ui/select"

const cities = [
  { value: "riyadh", label: "الرياض" },
  { value: "jeddah", label: "جدة" },
  { value: "dammam", label: "الدمام" },
]

export function CitySelect() {
  return (
    <Select
      name="city"
      aria-label="المدينة"
      options={cities}
      placeholder="اختر مدينة"
    />
  )
}

أحجام مختلفة

tsx
import { Select } from "@/components/ui/select"

const cities = [
  { value: "riyadh", label: "الرياض" },
  { value: "jeddah", label: "جدة" },
  { value: "dammam", label: "الدمام" },
]

export function CitySelectSizes() {
  return (
    <div className="flex flex-col gap-4">
      <Select aria-label="المدينة" options={cities} selectSize="sm" />
      <Select aria-label="المدينة" options={cities} selectSize="default" />
      <Select aria-label="المدينة" options={cities} selectSize="lg" />
    </div>
  )
}

حالة الخطأ

tsx
import { Select } from "@/components/ui/select"

const cities = [
  { value: "riyadh", label: "الرياض" },
  { value: "jeddah", label: "جدة" },
  { value: "dammam", label: "الدمام" },
]

export function CitySelectWithError() {
  return <Select name="city" aria-label="المدينة" options={cities} error aria-invalid />
}