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

WIP: Try new api for in toolbar editing (and fix image block toolbar focus loss issue). #25890

Closed
wants to merge 15 commits into from

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Oct 7, 2020

Note: this PR currently includes the reversion changes from #25854. Ideally that will be merged first before this is code reviewed.

Description

Fixes #24676, Fixes #23721, related #23375

Using the image block's crop tool from the keyboard resulted in a focus loss.

This PR fixes the issue, introducing a new in-toolbar editing system.

The system works like this:

  • A new slot/fill is introduced __experimentalBlockToolbarInlineEdit.
  • This slot is rendered in the BlockPopover as a sibling to the BlockContextualToolbar
  • When a fill is rendered in this slot, an action is triggered that visually hides the block contextual toolbar (applying a classname to it) and the fill is displayed in a PopoverWrapper.

The advantage of this system compared to #23613 is that it doesn't require as many changes to the toolbar, the only change is an additional classname that hides the toolbar.

It also follows the advice provided by the @enriquesanchez and @afercia in using a popover for the content that 'replaces' the toolbar.

TODO:

  • Improve styling
  • Come up with a way to get the top toolbar working
  • Improve DevEx, hide some of the implementation, possibly wrap this up in a component similar to <Dropdown>
  • Ensure any new APIs are experimental
  • Documentation

How has this been tested?

Prerequisite: Ensure top toolbar is not active (this doesn't work yet for the top toolbar).

  1. Add an image block and upload or choose an image from the media library
  2. Shift tab to the toolbar and use the right arrow key to move to the crop button
  3. Use space/enter to select the crop button, observe that crop tools are shown with focus moved to the first button
  4. Press escape, observe that the crop tools are hidden and focus moves back to the crop button

Other things to test

  • Cancel and Apply buttons work correctly
  • Moving focus outside the crop tools should close them

Screenshots

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@talldan talldan self-assigned this Oct 7, 2020
@talldan talldan added [a11y] Keyboard & Focus [Block] Image Affects the Image Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Oct 7, 2020
@github-actions
Copy link

github-actions bot commented Oct 7, 2020

Size Change: -5.3 kB (0%)

Total Size: 1.17 MB

Filename Size Change
build/annotations/index.js 3.52 kB +6 B (0%)
build/block-directory/index.js 8.55 kB +1 B
build/block-editor/index.js 123 kB -5.28 kB (4%)
build/block-editor/style-rtl.css 10.9 kB -61 B (0%)
build/block-editor/style.css 10.9 kB -58 B (0%)
build/block-library/index.js 135 kB +12 B (0%)
build/blocks/index.js 47.5 kB +4 B (0%)
build/components/index.js 169 kB -42 B (0%)
build/compose/index.js 9.42 kB -3 B (0%)
build/core-data/index.js 12.1 kB +23 B (0%)
build/data/index.js 8.61 kB +6 B (0%)
build/date/index.js 31.9 kB +2 B (0%)
build/dom-ready/index.js 569 B +1 B
build/dom/index.js 4.42 kB +1 B
build/edit-navigation/index.js 10.6 kB -7 B (0%)
build/edit-post/index.js 306 kB +32 B (0%)
build/edit-site/index.js 20.5 kB -1 B
build/edit-widgets/index.js 21.4 kB -1 B
build/editor/index.js 45.5 kB +3 B (0%)
build/element/index.js 4.45 kB +8 B (0%)
build/escape-html/index.js 733 B -1 B
build/format-library/index.js 7.49 kB +2 B (0%)
build/html-entities/index.js 622 B +1 B
build/i18n/index.js 3.55 kB +2 B (0%)
build/is-shallow-equal/index.js 711 B +1 B
build/keyboard-shortcuts/index.js 2.39 kB +3 B (0%)
build/list-reusable-blocks/index.js 3.02 kB +3 B (0%)
build/media-utils/index.js 5.12 kB +3 B (0%)
build/nux/index.js 3.27 kB +2 B (0%)
build/plugins/index.js 2.44 kB +1 B
build/primitives/index.js 1.34 kB -1 B
build/priority-queue/index.js 789 B -1 B
build/redux-routine/index.js 2.85 kB +4 B (0%)
build/rich-text/index.js 13 kB +25 B (0%)
build/server-side-render/index.js 2.61 kB +3 B (0%)
build/token-list/index.js 1.24 kB -1 B
build/warning/index.js 1.14 kB +7 B (0%)
build/wordcount/index.js 1.17 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/editor-rtl.css 8.65 kB 0 B
build/block-library/editor.css 8.65 kB 0 B
build/block-library/style-rtl.css 7.66 kB 0 B
build/block-library/style.css 7.65 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.78 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/data-controls/index.js 685 B 0 B
build/deprecated/index.js 772 B 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/style-rtl.css 6.29 kB 0 B
build/edit-post/style.css 6.27 kB 0 B
build/edit-site/style-rtl.css 3.71 kB 0 B
build/edit-site/style.css 3.72 kB 0 B
build/edit-widgets/style-rtl.css 3 kB 0 B
build/edit-widgets/style.css 3 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.74 kB 0 B

compressed-size-action

@talldan
Copy link
Contributor Author

talldan commented Oct 7, 2020

@enriquesanchez Top toolbar mode for the in-toolbar editing idea is a bit problematic. The trouble is that all of this is considered one toolbar:
Screenshot 2020-10-07 at 2 02 00 pm

So we'd be proposing to hide everything shown in the screenshot above when the user enables crop tools.

A possible interim solution might be to use a normal popover for the crop tools when the top toolbar is active, it'd look a bit similar to the Heading block's options:
Screenshot 2020-10-07 at 2 07 33 pm

Though I think this would mean you end up with multiple popovers if you Crop and then change the Aspect Ratio or Zoom.

Copy link
Contributor

@enriquesanchez enriquesanchez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good, @talldan! 🎉 Thank you!

I found a couple of issues during my testing.

  1. The 'Apply'/'Cancel' buttons are not aligned with the rest of the image editing popover. A few pixels up should fix it.

Screen Shot 2020-10-08 at 15 54 37

  1. I found it a bit disorienting that, coming from the block toolbar that uses the roving tabindex pattern, I can't move focus through the image editing options with my Left and Right keys. I assume this is happening because I'm technically no longer inside a toolbar and instead this is a popover, but I wonder if something can be done to match the behavior?

Other than that, this feels pretty good to my focus was preserved and predictable at all times 👍

@enriquesanchez
Copy link
Contributor

A possible interim solution might be to use a normal popover for the crop tools when the top toolbar is active

Ah, this is a tricky one. If it's not too much trouble, I'd love to give your suggestion a try and test to see how it feels and behaves.

On the other hand, I wonder how much of an issue it'll really be if we hide the whole toolbar area. After all, the user is in the middle of an image editing operation and contextually they only need the image editing tools in that specific moment. I'm trying to think of a scenario where doing so will have a negative repercussion and I can't come up with anything. What do you think?

@tellthemachines
Copy link
Contributor

What's the status of this? It would be good to get a fix for #24676 into 5.6, but this PR is looking a bit feature-heavy for a backport, especially this close to RC1 😅

Is there any simpler fix we could try?

@talldan
Copy link
Contributor Author

talldan commented Nov 23, 2020

@tellthemachines Sorry, I thought I wrote a response to this, but just re-checking and there's nothing here.

My feeling was/is that we should bump this to 5.7 because of the complexity (I don't think there's a simple fix). It is unfortunate that the bug will have been in both 5.5 and 5.6. I started working on a refactor of the image editing tools that should make any solution easier (#27089), but even that is a fairly sizeable code change.

There are quite a lot of pieces that need to come together for this 'in-toolbar' editing thing to work. You're right, it's a big change and affects some important pieces in the editor:

  1. Revert the previous attempt at this (Revert "[Try] Customizable toolbar contents (#23613)" #25854)
  2. Come up with a solution for how in-toolbar editing might work in top toolbar mode (WIP: Try new api for in toolbar editing (and fix image block toolbar focus loss issue). #25890 (comment)).
  3. Refactor the image editing tools to make the range of solutions wider (Refactor image block's image editing tools into separate components. #27089), this one is blocking my idea for the top toolbar.
  4. Refine the API proposed in this PR. Finalise an implementation and ship it.

@tellthemachines
Copy link
Contributor

Definitely let's push this to 5.7; we're in RC stage now so we should only be fixing regressions in 5.6.

@paaljoachim
Copy link
Contributor

Can we get a status update?
Thanks.

@talldan
Copy link
Contributor Author

talldan commented Feb 11, 2021

I don't really have time to work on this at the moment. I've unassigned myself from the associated issues. The PR can be kept open as a draft in case anyone wants to reference it or take it over.

Base automatically changed from master to trunk March 1, 2021 15:44
@Mamaduka
Copy link
Member

Mamaduka commented Jun 2, 2021

Hi, @talldan

Did the top toolbar problem get resolved via #31134?

P.S. How can I help to move things forward for this feature?

@talldan
Copy link
Contributor Author

talldan commented Jun 8, 2021

@Mamaduka Yep, I think that's resolved now. The top toolbar could now potentially behave the same way as the normal block toolbar.

I don't plan on picking this up again any time soon, so happy for someone else to take over or start fresh, and can assist with reviews or advice.

@Mamaduka
Copy link
Member

Mamaduka commented Jun 8, 2021

Thanks for the reply, @talldan.

I can take over/start fresh in a week or two.

Reviews/advice would be much appreciated.

@talldan talldan closed this May 13, 2022
@Mamaduka Mamaduka deleted the try/new-api-for-in-toolbar-editing branch November 26, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing image block's crop tools with keyboard results in focus loss Improve UX of image crop/edit tools
5 participants