Skip to content

better support for keyboard accessibility  #6006

Closed

Description

@roeycohen

In general using "Enter" on a toolbar that makes changes to lexical is problematic.

Lets say I have a button that toggles "bold" and it's triggered using the "Enter" key on the mouse-down event which calls dispatchCommand(FORMAT_TEXT_COMMAND...) - this causes lexical to get focus and then handle the Enter key which can replace the selected text with a new line.

adding the e.preventDefault to the event solves this problem but the focus still moves from the toolbar to the editor.

I'm not sure how to handle this...

Activity

  1. added
    enhancement
    on May 2, 2024
  2. added
    good first issue
    contribution-week
    on May 2, 2024
  3. simon0x1800 commented on May 3, 2025

    @simon0x1800

    @roeycohen Hey Can I get Assigned to this issue

  4. etrepum commented on May 3, 2025

    @etrepum
    Collaborator

    When/if you have a fix for the issue, simply submit a PR. No need for assignment.

  5. KaiPrince commented on Sep 3, 2025

    @KaiPrince
    Contributor

    I'm also noticing a lack of focus indicators on the toolbar items. I can address that as part of this issue.

    The other thing I'm thinking about is how to tab to the toolbar and the popover menu once inside the rich text editor. Currently once you're in the editor, there's no way to tab out of it, since it just inserts or removes tab characters. Pressing escape resets focus to the top of the page, but perhaps we could use the escape key to move focus to the content editable element itself, or to the toolbar?

    We should also make sure it's possible to tab past the editor without getting trapped by it. WCAG 2.1.2 No Keyboard Trap (Level A) would seem to apply. For situations where the editor is not the main use of the page, such as a comment box, we'd want to make sure the user can navigate past it to other items further down the page.

  6. etrepum commented on Sep 3, 2025

    @etrepum
    Collaborator

    Keyboard trap isn't even the default behavior, the TabIndentationPlugin takes over the tab key's default behavior. If you want tab to work like other html inputs then just don't use that plugin.

    If you want tab or escape to do something other than their default behaviors, then you can write a command listener to handle that according to your editor's needs.

  7. KaiPrince commented on Sep 4, 2025

    @KaiPrince
    Contributor

    Ah, I see about the tab plugin, explains a lot. I think ideally the TabIndentationPlugin could still be modified to support keyboard-only users. If you'd be willing to entertain a PR for that as part of this or a separate issue, I can look into implementing that.

    I also notice the toolbar isn't managing focus around dropdown menus, i.e. returning focus when closing or clicked. Same with modals.

    We might also consider switching the toolbar to an arrow key navigation pattern, and use role="toolbar" as a best practice.

  8. etrepum commented on Sep 4, 2025

    @etrepum
    Collaborator

    I think any improvements would be welcome, especially if they don't break compatibility (e.g. opt-in to changes in the tab plugin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contribution-weekenhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions