Skip to content

Allow using the modal exclusively within an element other than the HTML body #32

Open
@flekschas

Description

@flekschas

Currently, svelte-simple-modal assume that it's used globally. I.e., it overlays the body element. However, sometimes it can be useful to just use it within another (scrollable) container.

To support this we could traverse the DOM tree and find the first parent that is scrollable using for instance:

const isScrollable = (element) =>
  element.scrollHeight > element.clientHeight && window.getComputedStyle(element).overflowY.indexOf('hidden') === -1;

const getScrollableParent = (element) =>
  !element || element === document.body
    ? document.body
    : (isScrollable(element) ? element : getScrollableParent(element.parentNode));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions