diff --git a/src/DOMAPI/Document.res b/src/DOMAPI/Document.res index 9c0c84c..2a338ca 100644 --- a/src/DOMAPI/Document.res +++ b/src/DOMAPI/Document.res @@ -84,7 +84,7 @@ Returns the first element that is a descendant of node that matches selectors. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/querySelector) */ @send -external querySelector: (document, string) => element = "querySelector" +external querySelector: (document, string) => Null.t = "querySelector" /** Returns all element descendants of node that match selectors. diff --git a/src/DOMAPI/DocumentFragment.res b/src/DOMAPI/DocumentFragment.res index b52239e..46bd822 100644 --- a/src/DOMAPI/DocumentFragment.res +++ b/src/DOMAPI/DocumentFragment.res @@ -66,7 +66,7 @@ Returns the first element that is a descendant of node that matches selectors. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DocumentFragment/querySelector) */ @send - external querySelector: (T.t, string) => element = "querySelector" + external querySelector: (T.t, string) => Null.t = "querySelector" /** Returns all element descendants of node that match selectors. diff --git a/src/DOMAPI/Element.res b/src/DOMAPI/Element.res index fd2cbd8..697cd9d 100644 --- a/src/DOMAPI/Element.res +++ b/src/DOMAPI/Element.res @@ -267,7 +267,7 @@ Returns the first element that is a descendant of node that matches selectors. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Document/querySelector) */ @send - external querySelector: (T.t, string) => element = "querySelector" + external querySelector: (T.t, string) => Null.t = "querySelector" /** Returns all element descendants of node that match selectors. @@ -388,16 +388,46 @@ When supplied, options's navigationUI member indicates whether showing navigatio external scrollBy2: (T.t, ~x: float, ~y: float) => unit = "scrollBy" /** +`scrollIntoView()` + +Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user. + +```res +element->Element.scrollIntoView() +``` + +[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView) +*/ + @send + external scrollIntoView: T.t => unit = "scrollIntoView" + + /** +`scrollIntoView(true)` + +Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user. + +```res +element->Element.scrollIntoView_alignToTop() +``` + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView) */ @send - external scrollIntoView: (T.t, ~arg: bool=?) => unit = "scrollIntoView" + external scrollIntoView_alignToTop: (T.t, @as(json`true`) _) => unit = "scrollIntoView" /** +`scrollIntoView({ behavior: "smooth" })` + +Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user. + +```res +element->Element.scrollIntoView_withOptions({ behavior: DOMAPI.Smooth }) +``` + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView) */ @send - external scrollIntoView2: (T.t, ~arg: scrollIntoViewOptions=?) => unit = "scrollIntoView" + external scrollIntoView_withOptions: (T.t, scrollIntoViewOptions) => unit = "scrollIntoView" /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollTo) diff --git a/src/Global.res b/src/Global.res index a5b6e66..593312d 100644 --- a/src/Global.res +++ b/src/Global.res @@ -535,7 +535,7 @@ The event listener is appended to target's event listener list and is not append [Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ external addEventListener: ( - ~type_: string, + ~type_: eventType, ~callback: eventListener<'event>, ~options: addEventListenerOptions=?, ) => unit = "addEventListener" @@ -556,10 +556,10 @@ If an AbortSignal is passed for options's signal, then the event listener will b The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ -external addEventListener2: ( - ~type_: string, +external addEventListener_useCapture: ( + ~type_: eventType, ~callback: eventListener<'event>, - ~options: bool=?, + @as(json`true`) _, ) => unit = "addEventListener" /** @@ -576,10 +576,10 @@ external removeEventListener: ( Removes the event listener in target's event listener list with the same type, callback, and options. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ -external removeEventListener2: ( - ~type_: string, +external removeEventListener_useCapture: ( + ~type_: eventType, ~callback: eventListener<'event>, - ~options: bool=?, + @as(json`true`) _, ) => unit = "removeEventListener" /** diff --git a/tests/DOMAPI/HTMLElement__test.js b/tests/DOMAPI/HTMLElement__test.js new file mode 100644 index 0000000..be285fc --- /dev/null +++ b/tests/DOMAPI/HTMLElement__test.js @@ -0,0 +1,12 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Option from "rescript/lib/es6/Option.js"; +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; + +Option.forEach(Primitive_option.fromNullable(document.querySelector("form")), form => { + form.scrollIntoView({ + behavior: "smooth" + }); +}); + +/* Not a pure module */ diff --git a/tests/DOMAPI/HTMLElement__test.res b/tests/DOMAPI/HTMLElement__test.res new file mode 100644 index 0000000..fdd1a38 --- /dev/null +++ b/tests/DOMAPI/HTMLElement__test.res @@ -0,0 +1,9 @@ +open WebAPI +open WebAPI.Global + +document +->Document.querySelector("form") +->Null.toOption +->Option.forEach(form => { + form->Element.scrollIntoView_withOptions({behavior: DOMAPI.Smooth}) +})