UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) • 795 B
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import{FocusTrapExtension as r}from"@lexical/a11y";import{getExtensionDependencyFromEditor as t}from"@lexical/extension/getExtensionDependencyFromEditor";import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useRef as n,useCallback as o}from"react";function c(c,i="firstFocusable",l){const[u]=e(),s=n(null),a=n(l);return a.current=l,o(e=>{if(null!==s.current&&(s.current(),s.current=null),null!==e&&c){const n=t(u,r);s.current=n.output.register(e,{allowOutside:r=>{const t=a.current;return!!t&&t(r)},initialFocus:i})}},[u,c,i])}export{c as useLexicalFocusTrapRef};