الإكمال التلقائي واجهة البرمجة
الخصائص والفتحات والنصوص والتنسيق في الإكمال التلقائي من slotsmith.
الفتحات
في Autocomplete عدد 22 من الفتحات. مرّر بديلًا لأي منها في components، وكل فتحة لا تمرّرها تبقى على بديلها الافتراضي. فتحات العناصر تستقبل خصائص DOM فيناسبها عنصر المكتبة كما هو، وفتحات الأدوات تستقبل خصائص مسمّاة وتحتاج عادة إلى بضعة أسطر من المحوّل.
| الاسم | النوع | الخصائص التي تستقبلها | البديل الافتراضي | سمات data-* |
|---|---|---|---|---|
Root | <element> | خصائص DOM:
| مصدر البديل |
|
Trigger | <element> | خصائص DOM:
| مصدر البديل |
|
TriggerInput | <element> | خصائص DOM:
| مصدر البديل | — |
Toggle | <element> | خصائص DOM:
| مصدر البديل |
|
Value | {widget} |
| مصدر البديل | — |
Tag | {widget} |
| مصدر البديل | — |
Clear | {widget} |
| مصدر البديل | — |
Indicator | {widget} |
| مصدر البديل | — |
Popup | <element> | خصائص DOM:
| مصدر البديل |
|
Search | <element> | خصائص DOM:
| مصدر البديل | — |
List | <element> | خصائص DOM:
| مصدر البديل | — |
Option | <element> | خصائص DOM:
| مصدر البديل |
|
OptionLabel | {widget} |
| مصدر البديل | — |
Check | {widget} |
| مصدر البديل | — |
Group | <element> | خصائص DOM:
| مصدر البديل | — |
GroupLabel | {widget} |
| مصدر البديل | — |
Separator | <element> | خصائص DOM:
| مصدر البديل | — |
Empty | {widget} |
| مصدر البديل | — |
Loading | {widget} |
| مصدر البديل | — |
Error | {widget} |
| مصدر البديل | — |
Create | {widget} |
| مصدر البديل | — |
LoadMore | {widget} |
| مصدر البديل | — |
الخصائص
كل خصائص Autocomplete مجمّعة كما في توثيق المكتبة. الحالة المتحكَّم بها تأتي أزواجًا: مرّر القيمة مع معالج تغييرها، أو القيمة الابتدائية وحدها لتبقى الحالة داخل المكوّن.
| الاسم | النوع | الافتراضي | الوصف |
|---|---|---|---|
| Options | |||
optionsمطلوبة | TOption | — | The options to render. |
get | GetOptionValue< | — | Reads an option's id. Default: |
get | GetOptionLabel< | — | Reads an option's text. Default: |
option | ( | — | Marks an option unselectable. It stays visible but cannot be landed on. |
get | GetOptionGroup< | — | Reads the group an option belongs to, which is also the group's label. The options stay one flat list: groups appear in the order their first option does, an option joins its group wherever it sits (a later page included), and the options with no group form one unlabelled section where the first of them appeared. A group the search empties disappears with its label and separator. Read whenever the options or the search change. |
filter | OptionFilter< | — | How to narrow options against the search. |
selectedsingle mode | TOption | | — | The option behind |
selectedmultiple mode | TOption | — | The options behind |
| Selection | |||
multiplesingle mode | false | — | One value at a time. |
multipleمطلوبةmultiple mode | true | — | Several values, with the popup staying open on each pick. |
valuesingle mode | OptionValue | | — | The selected id, or |
valuemultiple mode | OptionValue | — | The selected ids. |
defaultsingle mode | OptionValue | | — | The selected id while uncontrolled. |
defaultmultiple mode | OptionValue | — | The selected ids while uncontrolled. |
onsingle mode | ( | — | The new id and, where known, the option behind it. |
onmultiple mode | ( | — | The new ids, and the options index-aligned with them. An entry is |
clearable | boolean | — | Whether the clear control is offered. Default |
close | boolean | !multiple | Whether picking closes the popup. Defaults to |
name | string | — | Renders a hidden input per value, so a plain HTML form submits it. |
| Search | |||
searchable | boolean | — | Whether the search box renders. |
search | "popup" | | — | Where the search box sits. |
search | string | — | The search text. With |
default | string | — | The search text while uncontrolled. |
on | ( | — | Told when the search text changes, for remote options. |
min | number | — | Don't search until this many characters are typed. |
| Open state and keyboard | |||
open | boolean | — | Whether the popup is open. |
default | boolean | — | Whether the popup starts open. |
on | ( | — | Told when the popup opens or closes. |
loop | boolean | — | Whether the highlight wraps past the ends. Default |
auto | boolean | — | Highlight the first enabled option whenever the list opens or its contents change, so Enter picks the top match. A highlight the user moved themselves is kept until the search changes. Default |
disabled | boolean | — | Nothing can be opened, picked or cleared. |
invalid | boolean | — | The value failed validation. Sets |
on | ( | — | Told when focus leaves the whole control, for form libraries. |
| Remote options | |||
loading | boolean | — | A first page is in flight. |
error | string | — | The last fetch failed. Replaces the list. |
on | ( | — | Offers a way back from the error. |
has | boolean | — | Another page exists. |
on | ( | — | Asks for the next page. |
loading | boolean | — | That next page is in flight. |
| Creating | |||
creatable | boolean | — | Offers a "create <query>" row when the search matches nothing. |
on | ( | — | Creates the searched name. |
create | boolean | — | The create request is in flight. |
| Rendering | |||
components | Partial< | — | Replace any part; the rest fall back to |
labels | Partial< | — | Override any string. Wins over |
locale | LocaleInput | the provider's | The language: a locale object, or the tag of one given to |
slot | AutocompleteSlotProps | — | Extra DOM props for the element parts. |
placeholder | string | labels. | Trigger text when nothing is selected. Defaults to |
max | number | 2 | Tags shown before the rest collapse into |
virtual | AutocompleteVirtualOptions | — | Renders only the options in view, for lists of thousands: pass the virtualizer hook ( |
| Positioning | |||
placement | PopupPlacement | bottom | Which side of the trigger the popup prefers. Defaults to |
popup | number | 4 | Gap between trigger and popup, in pixels. Defaults to 4. |
match | boolean | true | Make the popup exactly as wide as the trigger. Defaults to |
popup | number | 320 | Upper bound on the popup's height, in pixels. Defaults to 320. |
portal | PortalTarget | false | Renders the popup in a portal: |
تُمرَّر أي خاصية أخرى إلى العنصر الجذر <div>.
النصوص واللغات
كل نص يعرضه Autocomplete أو يعلنه، مع قيمته الافتراضية بالإنجليزية. مرّر labels لتغيير بعضها في مكوّن واحد، أو locale لتحويل كل النصوص إلى لغة أخرى. العرض أدناه يفعل الأمرين.
| المفتاح | النوع | الافتراضي بالإنجليزية | الوصف |
|---|---|---|---|
placeholder | string | "Select…" | Trigger text when nothing is selected. |
search | string | "Search…" | Placeholder for the search box. |
clear | string | "Clear selection" | Accessible name for the clear control. |
toggle | string | "Show options" | Accessible name for the button that opens and closes the list, with |
remove | ( | remove(يطبع | Accessible name for a tag's remove control. |
empty | string | "No results" | Shown when a search returned nothing. |
loading | string | "Loading…" | Shown while a first page is loading. |
min | ( | minChars(يطبع | Shown before |
retry | string | "Retry" | Label for the retry control. |
create | ( | create(يطبع | Label for the create row. |
creating | string | "Creating…" | Label for the create row while the request is in flight. |
more | ( | more(يطبع | The overflow badge in multiple mode. |
load | string | "Load more" | Label for the load-more control. |
results | ( | results(يطبع | Announced to screen readers when the result count changes. |
import { Autocomplete } from "slotsmith/autocomplete";
import { de } from "slotsmith/locales/de";
const cities = [
{ value: "berlin", label: "Berlin" },
{ value: "hamburg", label: "Hamburg" },
{ value: "koeln", label: "Köln" },
{ value: "leipzig", label: "Leipzig" },
{ value: "muenchen", label: "München" },
];
export default function Labels() {
return (
<Autocomplete
options={cities}
// Every string in German, from the ready-made pack…
locale={de}
// …except these two, replaced for this picker only.
labels={{ placeholder: "Stadt wählen…", empty: "Keine Stadt gefunden" }}
aria-label="Stadt"
style={{ maxWidth: 320 }}
/>
);
}حزم اللغات الجاهزة ودعم الكتابة من اليمين إلى اليسار واللغة على مستوى التطبيق موضّحة في صفحة اللغات.
التنسيق
أسماء الأصناف التي تضعها البدائل الافتراضية في Autocomplete على عناصرها، والمتغيرات التي يقرؤها ملف تنسيقه. اضبط متغيرًا على المكوّن أو على أي عنصر يحيط به لتغيير مظهره، واستهدف الصنف فقط لما لا يغطيه متغير.
| الصنف | الفتحة |
|---|---|
.sac | |
.sac__body | — |
.sac__overflow | — |
.sac__sr-only | — |
.sac__chevron | |
.sac__tick | |
.sac__cross | — |
.sac__plus | — |
.sac__tag | |
.sac__tag-label | — |
.sac__tag-remove | — |
.sac__clear | |
.sac__spinner | — |
.sac__label | |
.sac__message | |
.sac__error | |
.sac__button | — |
.sac__create | |
.sac__create-button | — |
.sac__more | |
.sac__more-button | — |
.sac__trigger | |
.sac__trigger-input | |
.sac__toggle | |
.sac__value | |
.sac__value--empty | — |
.sac__popup | |
.sac__search | |
.sac__list | |
.sac__option | |
.sac__group | |
.sac__group-list | — |
.sac__group-label | |
.sac__separator |
| المتغير | الطبقة |
|---|---|
--sac-accent | هذا المكوّن |
--sac-border | هذا المكوّن |
--sac-danger | هذا المكوّن |
--sac-font-size | هذا المكوّن |
--sac-hover | هذا المكوّن |
--sac-muted | هذا المكوّن |
--sac-radius | هذا المكوّن |
--sac-surface | هذا المكوّن |
--sac-text | هذا المكوّن |
--ss-accent | مشترك بين كل المكوّنات |
--ss-border | مشترك بين كل المكوّنات |
--ss-danger | مشترك بين كل المكوّنات |
--ss-font-size | مشترك بين كل المكوّنات |
--ss-hover | مشترك بين كل المكوّنات |
--ss-muted | مشترك بين كل المكوّنات |
--ss-radius | مشترك بين كل المكوّنات |
--ss-surface | مشترك بين كل المكوّنات |
--ss-text | مشترك بين كل المكوّنات |
تنتقل كل المتغيرات إلى قيمها الداكنة تحت .dark, [data-theme="dark"]، على الصفحة أو على أي عنصر يحيط بالمكوّن.