0

How to add a default font to a lexical text editor. I have selection-based font family change working. I am trying to figure out how I cans set a default font family.

Anil Kumar
  • 2,223
  • 2
  • 17
  • 22

1 Answers1

1

Upon editor load find the first element under root and apply the default font family to it. All the text post this element will have this font family applied to it.

  useEffect(() => {
    editor.update(() => {
      // set default font
      $getRoot()?.getChildAtIndex(0)?.select();
      const selection = $getSelection();
      if (selection) {
        $patchStyleText(selection as RangeSelection, {
          'font-family': 'fantasy',
        });
      }
    });
  }, [editor]);
Anil Kumar
  • 2,223
  • 2
  • 17
  • 22