@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 604 B
JavaScript
/**
* 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{useLexicalComposerContext as l}from"@lexical/react/LexicalComposerContext";import{getActiveElement as o}from"lexical";import{useEffect as t}from"react";function e({defaultSelection:e}){const[n]=l();return t(()=>{n.focus(()=>{const l=n.getRootElement(),t=null!==l?o(l):null;null===l||null!==t&&l.contains(t)||l.focus({preventScroll:!0})},{defaultSelection:e})},[e,n]),null}export{e as AutoFocusPlugin};