Skip to content

Instantly share code, notes, and snippets.

@baldurh
Created December 3, 2018 22:12
Show Gist options
  • Save baldurh/1f4c333f6a287a5b4bf4019d8f123955 to your computer and use it in GitHub Desktop.
Save baldurh/1f4c333f6a287a5b4bf4019d8f123955 to your computer and use it in GitHub Desktop.
let (left, width) =
Webapi.Dom.(
switch (Js.toOption(node)) {
| Some(element) =>
switch (
element |> Element.querySelector("[aria-selected=\"true\"]")
) {
| Some(element) =>
switch (element |> Element.asHtmlElement) {
| Some(element) => (
element |> HtmlElement.offsetLeft,
element |> HtmlElement.offsetWidth,
)
| _ => (0, 0)
}
| _ => (0, 0)
}
| _ => (0, 0)
}
);
let (left, width) =
Belt.Option.(
Webapi.Dom.(
Js.toOption(node)
->flatMap(Element.querySelector("[aria-selected=\"true\"]"))
->flatMap(Element.asHtmlElement)
->map(element =>
(
element |> HtmlElement.offsetLeft,
element |> HtmlElement.offsetWidth,
)
)
->getWithDefault((0, 0))
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment