Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape on Block Toolbar returns focus to Editor Canvas #55712

Merged
merged 8 commits into from Nov 2, 2023

Commits on Nov 2, 2023

  1. Move lastFocus into redux store

    Stores the element that had last focus from the editor when focus leaves the editor canvas
    jeryj committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    8123cc4 View commit details
    Browse the repository at this point in the history
  2. ForwardRef for selected block tools

    Adding the escape keypress from the navigable block tools will require forwarding the ref from the BlockTools all the way down to the NavigableToolbar.
    jeryj committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    3f5ceb3 View commit details
    Browse the repository at this point in the history
  3. Handle escape on toolbar via toolbar event listener

    This method requires forwarding a ref from the editor level down to the navigable toolbar so that the escape unselect shortcut can be blocked and the navigable toolbar event listener will still fire.
    
    Blocking the global escape event shouldn't be necessary, but we have a combination of a few things all combining to create a situation where:
    - Because the block toolbar uses createPortal to populate the block toolbar fills, we can't rely on the React event bubbling to hit the onKeyDown listener for the block toolbar
    - Since we can't use the React tree, we use the DOM tree which _should_ handle the event bubbling correctly from a `createPortal` element.
    - This bubbles via the React tree, which hits this `unselect` escape keypress before the block toolbar DOM event listener has access to it.
    
    Also, this is better than attaching it to all of the children in the block toolbar because when new items are attached to the toolbar (such as via the bubblesVirtually slots or the apply/cancel buttons when cropping an image) we can still catch the events. Otherwise, those buttons are added after the mount, and the children don't receive the listener.
    jeryj committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    e50fd49 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5718fdf View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    dfc5f6d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    7eece08 View commit details
    Browse the repository at this point in the history
  7. Remove onIndexChange from useEffect dependency array

    I added it since it was passed in, but it is a callback and doesn't change. It was causing unnecssary rerenders that was messing with the focus position when selecting an item from a dropdown, such as when changing the heading level on a site title block.
    jeryj committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    ad87967 View commit details
    Browse the repository at this point in the history
  8. linting fix

    scruffian committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    8558e69 View commit details
    Browse the repository at this point in the history