mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(@vant/use): useRect should awalys return DOMRect
This commit is contained in:
parent
a746ded63e
commit
d2e00ac275
@ -4,6 +4,17 @@ function isWindow(val: unknown): val is Window {
|
|||||||
return val === window;
|
return val === window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeDOMRect(width: number, height: number) {
|
||||||
|
return {
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: width,
|
||||||
|
bottom: height,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
} as DOMRect;
|
||||||
|
}
|
||||||
|
|
||||||
export const useRect = (
|
export const useRect = (
|
||||||
elementRef: (Element | Window) | Ref<Element | Window | undefined>
|
elementRef: (Element | Window) | Ref<Element | Window | undefined>
|
||||||
) => {
|
) => {
|
||||||
@ -12,27 +23,12 @@ export const useRect = (
|
|||||||
if (isWindow(element)) {
|
if (isWindow(element)) {
|
||||||
const width = element.innerWidth;
|
const width = element.innerWidth;
|
||||||
const height = element.innerHeight;
|
const height = element.innerHeight;
|
||||||
|
return makeDOMRect(width, height);
|
||||||
return {
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: width,
|
|
||||||
bottom: height,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element && element.getBoundingClientRect) {
|
if (element && element.getBoundingClientRect) {
|
||||||
return element.getBoundingClientRect();
|
return element.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return makeDOMRect(0, 0);
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user