Skip to content

Commit

Permalink
useAnchorRef: normalize null returns to undefined as it is not a …
Browse files Browse the repository at this point in the history
…valid `anchor` value
  • Loading branch information
ciampo committed Sep 1, 2022
1 parent b2dfde9 commit 7cea8ce
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/rich-text/src/component/use-anchor-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getActiveFormat } from '../get-active-format';
* @param {RichTextValue} $1.value Value to check for selection.
* @param {RichTextFormatType} $1.settings The format type's settings.
*
* @return {Element|VirtualAnchorElement|null|undefined} The active element or selection range.
* @return {Element|VirtualAnchorElement|undefined} The active element or selection range.
*/
export function useAnchorRef( { ref, value, settings = {} } ) {
const { tagName, className, name } = settings;
Expand Down Expand Up @@ -67,8 +67,9 @@ export function useAnchorRef( { ref, value, settings = {} } ) {
element = element.parentNode;
}

return element.closest(
tagName + ( className ? '.' + className : '' )
return (
element.closest( tagName + ( className ? '.' + className : '' ) ) ??
undefined
);
}, [ activeFormat, value.start, value.end, tagName, className ] );
}

0 comments on commit 7cea8ce

Please sign in to comment.