نظرة عامة
استخدمPopover للمعلومات السياقية أو عناصر التحكم البسيطة. أنشئ البوابة الخاصة به، وغلاف التموضع، والنافذة المنبثقة بشكل منفصل. استخدم Dropdown للقوائم والمنتقيات واللوحات ذات التنقل عالي المستوى.
استخدام
حالة غير متحكم بها.
استخدمdefaultOpen لتعيين مستوى الظهور الأولي. تدير النافذة المنبثقة التغييرات اللاحقة من مشغّلها وعناصر تحكم الإغلاق وتفاعلات الإخفاء.
defaultOpen هي false، لذا يمكن حذفه. استخدم Title وDescription لتعريف النافذة المنبثقة. يعرض المشغّل زرًا افتراضيًا؛ يتيح لك render توفير عنصر متوافق.
مقارنة المواضع
قارن الجوانب المدعومة مع سهم وبدونه. تُبقي هذه الأمثلة المفتوحة كل نافذة منبثقة بجانب المُشغِّل الخاص بها للفحص؛ استخدم مثال العرض لتجربة فتح نافذة منبثقة وإغلاقها.البنية التشريحية
أبقِ المشغّل والنافذة المنبثقة داخلPopover.Root. يمكن أن تحتوي النافذة المنبثقة على نص وعناصر تحكم في النموذج وإجراءات.
تدعم جميع الأجزاء المعروضة سمات Base UI الأصلية المثبتة ومعالجاتها ومراجعها وتركيب
render للعناصر/الدوال. يجب أن تمرر المكونات المخصصة الخصائص والمرجع المقدمين. لكل جزء نوع Popover\<Part>Props ونوع Popover\<Part>State عامّان. يحافظ PopoverRootProps وPopoverTriggerProps على الأنواع العامة للحمولة. يُصدَّر أيضًا كل من PopoverHandle وPopoverRootActions وPopoverRootChangeEventDetails وPopoverRootChangeEventReason من twenty-ui/primitives/surfaces.
حالة متحكَّم بها
مرّرopen وحدّثه باستخدام onOpenChange لإدارة ظهور النافذة المنبثقة نفسها في حالة React.
onOpenChange القيمة المنطقية التالية وتفاصيل الحدث، بما في ذلك التغييرات التي يطلبها المشغّل وعناصر تحكم الإغلاق ومفتاح Escape والتفاعل الخارجي.
التركيب باستخدام الأزرار
مرّرButton من واجهة Twenty عبر render لاستخدامه كمشغّل أو عنصر تحكم للإغلاق. تحافظ النافذة المنبثقة على حالة فتحها وسلوك لوحة المفاتيح ومعالجة التركيز.
render السلوك إلى الزر المقدم. يجب أن تقوم مكونات الغلاف المخصصة بتمرير الخصائص والمرجع المقدمين للحفاظ على هذا السلوك.
الموضع والتركيز
القيم الافتراضية لـPositioner هي side="bottom" وalign="center" وsideOffset={8}. يقبل عقد Base UI المثبت كاملًا، بما في ذلك مراسي العناصر/المراجع/الدوال/الافتراضية، والإزاحات الوظيفية، وpositionMethod وcollisionBoundary وcollisionPadding وcollisionAvoidance وarrowPadding وsticky وdisableAnchorTracking. يتحكم DirectionProvider في التموضع المنطقي ويوفر اتجاه DOM. يمكن لـdir صريح تجاوز السمة الأصلية؛ استخدم الموفر لتغيير موضع الجانب المنطقي.
Popup.initialFocus وPopup.finalFocus أهداف التركيز واستدعاءات رد الاتصال من المصدر. يحتفظ Root.modal بأوضاع Base UI الافتراضية غير المشروطة والمشروطة وحبس التركيز للاستخدام المستقل.
وجهات البوابة والسمة
عيّنcontainer وkeepMounted في Portal:
تحافظ الوجهة الافتراضية ذات النطاق على رموز CSS ونظام الألوان الخاصين بها. ترث الوجهة الصريحة CSS من نطاق DOM الفعلي الخاص بها. ضعها داخل نطاق السمة المقصود، أو وفر أنماط السمة هناك. تحتاج أهداف ShadowRoot إلى CSS الخاصة بالمكتبة وأنماط السمة في شجرة الظل تلك. يبقى سياق سمة React واتجاه النص المقدم متاحين عبر البوابات. لا توسع واجهة برمجة التطبيقات هذه وجهات البوابة المسموح بها للعارض.
المشغلات والحمولات المنفصلة
يربطPopover.createHandle\<TPayload>() المشغلات المنفصلة بجذر ويكشف open(triggerId) وclose() وisOpen. Popover.Handle هو منشئ المقبض من المصدر المثبت. تتلقى دالة العرض الخاصة بالجذر الحمولة النشطة. استدعِ الإجراءات الحتمية من معالجات الأحداث أو التأثيرات.
onOpenChange على reason وevent وtrigger وcancel() وpreventUnmountOnClose(). تحتفظ الجذور المتحكم بها بـtriggerId؛ وتحتفظ الجذور غير المتحكم بها بـdefaultTriggerId. يكشف actionsRef عن إجراءات الإغلاق/إلغاء التحميل من المصدر.
الترحيل
انقلcontainer وkeepMounted من Popup إلى Portal. انقل خصائص الموضع والمرساة والتصادم إلى Positioner. استبدل Popup.arrow بابن Popover.Arrow صريح. تستمر الخصائص الأصلية لـPopup ومعالجاته وخصائص التركيز والمرجع في استهداف عنصر المحتوى. يحتفظ Dropdown.Content بتجميعه الملائم الحالي.
داخل المكونات الأمامية، استخدم تركيبًا غير مشروط ضمن سياسة البوابة الحالية ذات النطاق. تُحظر النوافذ المنبثقة/مربعات الحوار الأصلية للمتصفح والوضعية المملوكة مباشرةً للتطبيق؛ استخدم واجهة برمجة تطبيقات مربع حوار مضيف SDK لمربعات الحوار. يبقى عمل قدرات بوابة العارض والهندسة والتمرير والرفض منفصلًا عن واجهة برمجة التطبيقات الأولية هذه.
الخصائص
يتم إنشاء المرجع من أنواع المكونات العامة. تُقبل أيضًا السمات الأصلية، بما فيها الأسماء التي يمكن الوصول إليها ومعالجات الأحداث، في الأجزاء التي تعرض عناصر.Popover.Root
RefObject<PopoverRootActions | null>
A ref to imperative actions.
unmount: Ends the closing phase of the popover after an externally controlled closing animation finishes. CallpreventUnmountOnClose()inonOpenChangefirst, otherwise the popover completes closing on its own. Whether it leaves the DOM is decided bykeepMountedon the portal.close: Closes the popover imperatively when called.
ReactNode | PayloadChildRenderFunction<Payload>
Parts or a render function receiving the active trigger payload. Root renders no DOM element.
boolean
افتراضي:"false"
Whether the popover is initially open.To render a controlled popover, use the
open prop instead.string | null
ID of the trigger that the popover is associated with.
This is useful in conjunction with the
defaultOpen prop to create an initially open popover.PopoverHandle<Payload>
Connects detached triggers and imperative open/close actions.
boolean | "trap-focus"
افتراضي:"false"
Determines if the popover enters a modal state when open.
true: user interaction is limited to the popover: document page scroll is locked, and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed.'trap-focus': focus is trapped inside the popover, but document page scroll is not locked and pointer interactions outside of it remain enabled.
true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.When modal is true, focus trapping is enabled only if <Popover.Close> is rendered
inside <Popover.Popup>. It can be visually hidden with your own CSS if needed, such as
Tailwind’s sr-only utility.When modal is 'trap-focus', render <Popover.Close> inside <Popover.Popup> so touch
screen readers can escape the popup.((open: boolean, eventDetails: PopoverRootChangeEventDetails) => void)
Receives the requested open state and Base UI event details, including reason, event, trigger, cancel() and preventUnmountOnClose().
((open: boolean) => void)
Event handler called after any animations complete when the popover is opened or closed.
boolean
Whether the popover is currently open.
string | null
ID of the trigger that the popover is associated with.
This is useful in conjunction with the
open prop to create a controlled popover.
There’s no need to specify this prop when the popover is uncontrolled (that is, when the open prop is not set).Popover.Trigger
string | ((state: PopoverTriggerState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
number
افتراضي:"0"
How long to wait before closing the popover that was opened on hover.
Specified in milliseconds.Requires the
openOnHover prop.number
افتراضي:"300"
How long to wait before the popover may be opened on hover. Specified in milliseconds.Requires the
openOnHover prop.PopoverHandle<Payload>
A handle to associate the trigger with a popover.
string
ID of the trigger. In addition to being forwarded to the rendered element,
it is also used to specify the active trigger for the popover in controlled mode (with the PopoverRoot
triggerId prop).boolean
افتراضي:"true"
Whether the component renders a native
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (e.g. <div>).boolean
افتراضي:"false"
Whether the popover should also open when the trigger is hovered.
Payload
A payload to pass to the popover when it is opened.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Portal
string | ((state: PopoverPortalState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null
When omitted, uses the scoped theme container, then the Base UI parent portal or document body. Explicit null delays rendering until a target is supplied. Explicit elements, ShadowRoots and refs are forwarded unchanged; their DOM scope supplies CSS tokens.
boolean
افتراضي:"false"
Whether to keep the portal mounted in the DOM while the popup is hidden.
Ref<HTMLDivElement>
Ref to the portal div. Native props, handlers and render target this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverPortalState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverPortalState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Positioner
"center" | "end" | "start"
افتراضي:"center"
How to align the popup relative to the specified side.
number | OffsetFunction
افتراضي:"0"
Additional offset along the alignment axis in pixels.
Also accepts a function that returns the offset to read the dimensions of the anchor
and positioner elements, along with its side and alignment.The function takes a
data object parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null
An element to position the popup against.
By default, the popup will be positioned against the trigger.
number
افتراضي:"5"
Minimum distance to maintain between the arrow and the edges of the popup.Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
string | ((state: PopoverPositionerState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
CollisionAvoidance
Determines how to handle collisions when positioning the popup.
side controls overflow on the preferred placement axis (top/bottom or left/right):'flip': keep the requested side when it fits; otherwise try the opposite side (topandbottom, orleftandright).'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.'none': do not correct side-axis overflow.
align controls overflow on the alignment axis (start/center/end):'flip': keep side, but swapstartandendwhen the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.'none': do not correct alignment-axis overflow.
fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit:'start': allow perpendicular fallback and try the logical start side first (topbeforebottom, orleftbeforerightin LTR).'end': allow perpendicular fallback and try the logical end side first (bottombeforetop, orrightbeforeleftin LTR).'none': do not fallback to the perpendicular axis.
side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'.Boundary
افتراضي:"clipping-ancestors"
An element or a rectangle that delimits the area that the popup is confined to.
Padding
افتراضي:"5"
Additional space to maintain from the edge of the collision boundary.
boolean
افتراضي:"false"
Whether to disable the popup from tracking any layout shift of its positioning anchor.
"absolute" | "fixed"
افتراضي:"absolute"
Determines which CSS
position property to use.Ref<HTMLDivElement>
Ref to the positioning div. Accepts the complete Base UI anchor, collision and positioning contract.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverPositionerState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render."bottom" | "inline-end" | "inline-start" | "left" | "right" | "top"
افتراضي:"bottom"
Which side of the anchor element to align the popup against.
May automatically change to avoid collisions.
number | OffsetFunction
افتراضي:"8"
Distance from the anchor. Defaults to 8. Accepts a number or positioning function.
boolean
افتراضي:"false"
Whether to maintain the popup in the viewport after
the anchor element was scrolled out of view.
CSSProperties | ((state: PopoverPositionerState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Popup
ReactNode
Popup content. Compose Portal, Positioner and Arrow separately.
string | ((state: PopoverPopupState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)
Determines the element to focus when the popover is closed.
false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior,nullto fall back to the default behavior, orfalse/undefinedto do nothing.
boolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)
Determines the element to focus when the popover is opened.
By default, focus moves to the first tabbable element inside the popup, except when the popover
is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard.
false: Do not move focus.true: Move focus based on the default behavior (first tabbable element or popup).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior,nullto fall back to the default behavior, orfalse/undefinedto do nothing.
Ref<HTMLDivElement>
Ref to the popup div. Focus props, native attributes, handlers and render target this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverPopupState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverPopupState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Arrow
string | ((state: PopoverArrowState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Ref<HTMLDivElement>
Ref to the arrow div. Compose inside Popup.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverArrowState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverArrowState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Backdrop
string | ((state: PopoverBackdropState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Ref<HTMLDivElement>
Ref to the optional backdrop div. Compose inside Portal.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverBackdropState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverBackdropState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Title
string | ((state: PopoverTitleState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTitleState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverTitleState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Description
string | ((state: PopoverDescriptionState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverDescriptionState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverDescriptionState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Close
string | ((state: PopoverCloseState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
boolean
افتراضي:"true"
Whether the component renders a native
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverCloseState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverCloseState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.
Popover.Viewport
ReactNode
The content to render inside the transition container.
string | ((state: PopoverViewportState) => string | undefined)
CSS class applied to the element, or a function that
returns a class based on the component’s state.
Ref<HTMLDivElement>
Ref to the content-transition div for changing trigger payloads.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverViewportState>
Allows you to replace the component’s HTML element
with a different tag, or compose it with another component.Accepts a
ReactElement or a function that returns the element to render.CSSProperties | ((state: PopoverViewportState) => CSSProperties | undefined)
Style applied to the element, or a function that
returns a style object based on the component’s state.