123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172open!CoreopenVirtual_domletlock_body_scroll_testing_attr_name="data-lock-body-scroll-for-testing"letlock_body_scroll_attr=(* Unfortunately, locking scroll by setting [overflow: hidden] results in a small layout
shift, because of the scrollbar disappearing / reappearing.
Setting[:root]'s [scrollbar-gutter] to [stable] or [stable both-edges] fixes this if
content is overflowing at time of modal open, but if it is not, that will create a
layout shift for adding the gutter. We don't want to set [scrollbar-gutter] for all
apps, because that unconditionally wastes ~16px on each side.
It might be possible to reimplement this locking via JS code that runs on modal
activate / deactivate, but the semantics would be very difficult to get right,
because:
- Content might change while the page is opened
- We can't get the scrollbar width while we have set [overflow: hidden]
For now, the best path forward seems to be for apps that care about the layout shift
to set up [scrollbar-gutter] themselves
*)letactual_attr=Inline_css.Private.Dynamic.attr[%string{| @layer kado.app { body { overflow: hidden !important; } }|}]inmatcham_running_testwith|false->actual_attr|true->Vdom.Attr.combineactual_attr(Vdom.Attr.createlock_body_scroll_testing_attr_name"");;(* We need this only on modals because they are not constrained automatically by floating
UI's size middleware. *)letrestrict_height_to_viewport={%css|max-height: 100vh;|}lettesting_modal_attr_name="data-testing-modal"lettesting_modal_attr=matcham_running_testwith|true->Vdom.Attr.createtesting_modal_attr_name""|false->Vdom.Attr.empty;;letnode?(modal_attrs=[])?(lock_body_scroll=false)?(restore_focus_on_close=Popover_dom.Restore_focus_on_close.Yes{prevent_scroll=false})?(overflow_auto_wrapper=false)contents=letscroll_attr=iflock_body_scrollthenlock_body_scroll_attrelseVdom.Attr.emptyinPopover_dom.node~restore_focus_on_close~overflow_auto_wrapper~extra_attrs:(Popover_dom.show_on_mount::Inertness_management.for_modal::scroll_attr::restrict_height_to_viewport::testing_modal_attr::modal_attrs)~kind:`Manualcontents;;moduleFor_testing_bonsai_web_toplayer=structletmodal_attr_name=testing_modal_attr_nameletlock_body_scroll_attr_name=lock_body_scroll_testing_attr_nameend