Skip to content

Commit

Permalink
Allow useAnchorRef to return null
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 6, 2022
1 parent b179e5b commit 1bc3b66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/rich-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ _Parameters_

_Returns_

- `Element|VirtualAnchorElement|undefined`: The active element or selection range.
- `Element|VirtualAnchorElement|undefined|null`: The active element or selection range.

<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
7 changes: 3 additions & 4 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|undefined} The active element or selection range.
* @return {Element|VirtualAnchorElement|undefined|null} The active element or selection range.
*/
export function useAnchorRef( { ref, value, settings = {} } ) {
const { tagName, className, name } = settings;
Expand Down Expand Up @@ -67,9 +67,8 @@ export function useAnchorRef( { ref, value, settings = {} } ) {
element = element.parentNode;
}

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

0 comments on commit 1bc3b66

Please sign in to comment.