fix(suggestion): 🐛 make clientrect prop optional as it can potentially be undefined (#2813)
This commit makes the clientRect prop optional - this means that this value can be null. This allows developers using the suggestion extension to know that they have to implement a check for the clientRect before using it. #2795
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Editor, Range } from '@tiptap/core'
|
||||
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
|
||||
|
||||
import { Editor, Range } from '@tiptap/core'
|
||||
|
||||
import { findSuggestionMatch } from './findSuggestionMatch'
|
||||
|
||||
export interface SuggestionOptions<I = any> {
|
||||
@@ -44,7 +46,7 @@ export interface SuggestionProps<I = any> {
|
||||
items: I[],
|
||||
command: (props: I) => void,
|
||||
decorationNode: Element | null,
|
||||
clientRect: (() => DOMRect) | null,
|
||||
clientRect?: (() => DOMRect | null) | null,
|
||||
}
|
||||
|
||||
export interface SuggestionKeyDownProps {
|
||||
@@ -123,8 +125,7 @@ export function Suggestion<I = any>({
|
||||
const { decorationId } = this.key?.getState(editor.state)
|
||||
const currentDecorationNode = document.querySelector(`[data-decoration-id="${decorationId}"]`)
|
||||
|
||||
// @ts-ignore-error
|
||||
return currentDecorationNode.getBoundingClientRect()
|
||||
return currentDecorationNode?.getBoundingClientRect() || null
|
||||
}
|
||||
: null,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user