Skip to content

Commit

Permalink
fix: cannot read properties of null (reading 'getBoundingClientRect ')(
Browse files Browse the repository at this point in the history
  • Loading branch information
imzbf committed Jul 2, 2023
1 parent 0bdab59 commit d490f35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/MdEditor/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default defineComponent({
const triggerEle = triggerRef.value as HTMLElement;
const overlayEle = overlayRef.value as HTMLElement;

// 尝试移除元素不存在的潜在问题(https://github.com/imzbf/md-editor-v3/issues/308)
if (!triggerEle || !overlayEle) {
return;
}

const triggerInfo = triggerEle.getBoundingClientRect();

const triggerTop = triggerEle.offsetTop;
Expand Down
5 changes: 5 additions & 0 deletions packages/MdEditor/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export const splitKatexValue = (str: string, key = '$'): Array<string> => {
* @returns
*/
export const getRelativeTop = (element: HTMLElement, container: HTMLElement): number => {
// 尝试移除元素不存在的潜在问题(https://github.com/imzbf/md-editor-v3/issues/308)
if (!element || !container) {
return 0;
}

const eleRect = element?.getBoundingClientRect();

if (container === document.documentElement) {
Expand Down

0 comments on commit d490f35

Please sign in to comment.