Skip to content

Commit 66127fe

Browse files
committed
Improve scrollIntoView
1 parent 6c5dd6a commit 66127fe

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

src/DOMAPI/Element.res

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,46 @@ When supplied, options's navigationUI member indicates whether showing navigatio
388388
external scrollBy2: (T.t, ~x: float, ~y: float) => unit = "scrollBy"
389389

390390
/**
391+
`scrollIntoView()`
392+
393+
Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
394+
395+
```res
396+
element->Element.scrollIntoView()
397+
```
398+
399+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
400+
*/
401+
@send
402+
external scrollIntoView: T.t => unit = "scrollIntoView"
403+
404+
/**
405+
`scrollIntoView(true)`
406+
407+
Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
408+
409+
```res
410+
element->Element.scrollIntoView_alignToTop()
411+
```
412+
391413
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
392414
*/
393415
@send
394-
external scrollIntoView: (T.t, ~arg: bool=?) => unit = "scrollIntoView"
416+
external scrollIntoView_alignToTop: (T.t, @as(json`true`) _) => unit = "scrollIntoView"
395417

396418
/**
419+
`scrollIntoView({ behavior: "smooth" })`
420+
421+
Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
422+
423+
```res
424+
element->Element.scrollIntoView_withOptions({ behavior: DOMAPI.Smooth })
425+
```
426+
397427
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
398428
*/
399429
@send
400-
external scrollIntoView2: (T.t, ~arg: scrollIntoViewOptions=?) => unit = "scrollIntoView"
430+
external scrollIntoView_withOptions: (T.t, scrollIntoViewOptions) => unit = "scrollIntoView"
401431

402432
/**
403433
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollTo)

tests/DOMAPI/HTMLElement__test.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/DOMAPI/HTMLElement__test.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
open WebAPI
2+
open WebAPI.Global
3+
4+
document
5+
->Document.querySelector("form")
6+
->Null.toOption
7+
->Option.forEach(form => {
8+
form->Element.scrollIntoView_withOptions({behavior: DOMAPI.Smooth})
9+
})

0 commit comments

Comments
 (0)