payload icon indicating copy to clipboard operation
payload copied to clipboard

Some items in the fixed toolbar appear initially enabled even before the editor receives focus

Open LimChorngUan opened this issue 1 year ago • 2 comments

Describe the Bug

Toolbar items in FixedToolbarFeature are not disabled when the lexical editor is not in focused.

Actual Behavior:

  • Dropdown items are correctly disabled initially, but after focusing and unfocusing the editor, no items are disabled.
  • Some toolbar items are not disabled at all (e.g. X₂ and X² features)

Expected Behavior: All toolbar items should be disabled when the editor is unfocused.

Reproduction Steps

  1. Enable lexicalEditor in the e.g. PostCollection with FixedToolbarFeature and other features
     editor: lexicalEditor({
        features: [
          ParagraphFeature(),
          OrderedListFeature(),
          UnorderedListFeature(),
          SubscriptFeature(),
          SuperscriptFeature(),
          FixedToolbarFeature(),
        ]
      }),
  1. Observe the initial state:
  • Dropdown items are disabled when the editor is not on focused. ✅
  • Other toolbar items (e.g., X₂ and X² buttons) are not disabled initially. ❌
  1. Once the editor gains focus, and even after losing focus (when there's no cursor in the editor at all): No toolbar items are disabled anymore, including the dropdown items. ❌

Which area(s) are affected? (Select all that apply)

area: ui, plugin: richtext-lexical

Environment Info

Payload: 3.0.0-beta.116 Node.js: ^18.20.2 || >=20.9.0 Next.js: 15.0.0-canary.173

LimChorngUan avatar Oct 21 '24 16:10 LimChorngUan

Clearing selection onBlur is a known issue for Lexical, and I've opened this issue to track it there: https://github.com/facebook/lexical/issues/6622

However, some buttons appearing initially enabled even before the editor receives focus seems like a bug on our end. I'm going to rename this issue to track that part of the problem.

Thanks for reporting!

GermanJablo avatar Oct 21 '24 17:10 GermanJablo

Awesome thanks so much!

LimChorngUan avatar Oct 21 '24 18:10 LimChorngUan

I just looked at this issue again. When you talked about enabled and disabled I thought you meant active and inactive (the color that appears when the selection has, for example, subscript, or bold, etc.).

The current behavior is that the X₂ and X² buttons appear enabled even if nothing has been selected yet, because in case the button is pressed the editor is focused and the formatting is applied on the first paragraph, which seems to me a reasonable heuristic and that I think other text editors follow.

I do recognize that the dropdown and buttons could follow the same behavior for consistency, but I don't think this reaches “bug” status. I'm going to close this issue, but I can check a PR if this is important to you and you want to contribute. 😁

GermanJablo avatar Nov 27 '24 19:11 GermanJablo

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Nov 29 '24 04:11 github-actions[bot]