package virtual_dom_toplayer

  1. Overview
  2. Docs

The Floating_positioning library is for positioning an element relative to a reference element. It is intended for component authors, and generally should not be used directly in implementations of web UIs.

These are used to implement positioning for `lib/vdom_toplayer`.

Config Types

module Position : sig ... end
module Alignment : sig ... end
module Offset : sig ... end
module Strategy : sig ... end

Anchoring

module Anchor : sig ... end
type auto_update_handle

Positioning Primitives

val update_position : ?arrow_selector:string -> anchor:Anchor.t -> floating:Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t -> Position.t -> Alignment.t -> Offset.t -> Strategy.t -> unit

Sets the position of the floating element relative to the anchor. Can be useful for one-off positioning calls or virtual positioning. For real DOM anchors, you'll generally want to use auto_update_position.

arrow_selector can be used to indicate a child element of floating that should be a positioning indicator: https://floating-ui.com/docs/arrow.

val auto_update_position : ?arrow_selector:string -> anchor:Anchor.t -> floating:Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t -> Position.t -> Alignment.t -> Offset.t -> Strategy.t -> auto_update_handle

Like update_position, but automatically repositions the floating element when the anchor changes.

This can be expensive, don't use it to position elements with display:none while they are not visible.

Known bug: popovers attached to moving elements might disconnect when positioning params change due to some weird interactions between vdom diffing and floating_ui's use of IntersectionObserver. This could be fixed by running auto-update on every frame, but isn't currently implemented because it's not a likely use case.

val cancel_auto_update : auto_update_handle -> unit

Control and positioning hooks

val position_me : ?arrow_selector:string -> ?position:Position.t -> ?alignment:Alignment.t -> ?offset:Offset.t -> Anchor.t -> Virtual_dom.Vdom.Attr.t

position_me returns an attr which, when added to a vdom node, will automatically position it relative to the anchor, with auto-update.

Accessors for positioning data provided by floating_positioning

module Accessors : sig ... end
OCaml

Innovation. Community. Security.