Housekeeping...

This commit is contained in:
Pieter Vander Vennet 2022-12-16 13:44:25 +01:00
parent 339bfab361
commit 9e000d521f
35 changed files with 406 additions and 136 deletions

View file

@ -3,7 +3,7 @@
*
* Assumes a read-only configuration, so it has no 'ListenTo'
*/
import {Utils} from "../Utils";
import { Utils } from "../Utils"
export default abstract class BaseUIElement {
protected _constructedHtmlElement: HTMLElement
@ -43,32 +43,32 @@ export default abstract class BaseUIElement {
this._constructedHtmlElement?.scrollTo(0, 0)
}
public ScrollIntoView(options?: {
onlyIfPartiallyHidden?: boolean
}) {
if(this._constructedHtmlElement === undefined){
public ScrollIntoView(options?: { onlyIfPartiallyHidden?: boolean }) {
if (this._constructedHtmlElement === undefined) {
return
}
let alignToTop = true;
if(options?.onlyIfPartiallyHidden){
let alignToTop = true
if (options?.onlyIfPartiallyHidden) {
// Is the element completely in the view?
const parentRect = Utils.findParentWithScrolling(this._constructedHtmlElement.parentElement).getBoundingClientRect();
const elementRect = this._constructedHtmlElement.getBoundingClientRect();
const parentRect = Utils.findParentWithScrolling(
this._constructedHtmlElement.parentElement
).getBoundingClientRect()
const elementRect = this._constructedHtmlElement.getBoundingClientRect()
// Check if the element is within the vertical bounds of the parent element
const topIsVisible = elementRect.top >= parentRect.top
const bottomIsVisible = elementRect.bottom <= parentRect.bottom
const inView = topIsVisible && bottomIsVisible ;
if(inView){
const inView = topIsVisible && bottomIsVisible
if (inView) {
return
}
if(topIsVisible){
if (topIsVisible) {
alignToTop = false
}
}
this._constructedHtmlElement?.scrollIntoView({
behavior: "smooth",
block: "start"
block: "start",
})
}
/**