rosen-group / ngx-onboarding

Onboarding module for Angular applications
Other
52 stars 13 forks source link

Wrong position of onboarding item #14

Closed SDohle closed 5 years ago

SDohle commented 6 years ago

In a DevExreme modal dialog the onboarding item appears on a wrong position.

miller45 commented 5 years ago

Maybe position can be retrieved with this method: https://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element

MichaelKirchner commented 5 years ago

same like #17

miller45 commented 5 years ago

I just tested it with elements that have transform: translate... the getBoundingClientRect takes that into consideration and returns the correct position. See https://stackblitz.com/edit/js-a58qrv

miller45 commented 5 years ago

Ok Internet explorer is returning a different object (ClientRect): https://caniuse.com/#search=getBoundingClientRect But as we have a access to the position encapsulated in OnboardingHtmlElementHelper getPosition we can simply write a our own "polyfix":

public static getPosition(htmlElement: HTMLElement) {
        const rect: ClientRect | DOMRect = htmlElement.getBoundingClientRect();
        if ((window as any).DOMRect && rect instanceof DOMRect) {
            return {
                x: rect.x,
                y: rect.y,
                width: rect.width,
                height: rect.height
            };
        }
        return {
            x: rect.left,
            y: rect.top,
            width: rect.width,
            height: rect.height
        };
    }

The check if ((window as any).DOMRect looks useless but as Internet Explorer doesnt know about DOMRect it would throw an exception when we call rect instanceof DOMRect directly.

miller45 commented 5 years ago

another check which avoids access to window looks like this if (typeof DOMRect !== 'undefined' && rect instanceof DOMRect)