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

Gallery: Move "Add new" action to Toolbar #25321

Closed
wants to merge 5 commits into from

Conversation

obenland
Copy link
Member

@obenland obenland commented Sep 14, 2020

Description

Adds a block control to add/upload images to existing galleries.
Removes the dropzone appender at the end of galleries.

Fixes #21247.

How has this been tested?

Screenshots

Before After
Screen Shot 2020-09-14 at 4 10 18 PM Screen Shot 2020-09-14 at 4 10 54 PM

Types of changes

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.

@obenland obenland added [Type] Enhancement A suggestion for improvement. [Block] Gallery Affects the Gallery Block - used to display groups of images labels Sep 14, 2020
@obenland obenland self-assigned this Sep 14, 2020
@obenland obenland marked this pull request as draft September 14, 2020 23:17
@obenland
Copy link
Member Author

Next steps:

  • Update CSS classes
  • Separate out dropdown control into its own component

@github-actions
Copy link

github-actions bot commented Sep 14, 2020

Size Change: +763 B (0%)

Total Size: 1.18 MB

Filename Size Change
build/annotations/index.js 3.52 kB -1 B
build/autop/index.js 2.72 kB +1 B
build/block-editor/index.js 129 kB +15 B (0%)
build/block-library/index.js 136 kB +736 B (0%)
build/components/index.js 169 kB +2 B (0%)
build/date/index.js 31.9 kB +2 B (0%)
build/edit-navigation/index.js 10.7 kB +1 B
build/edit-post/index.js 306 kB +3 B (0%)
build/editor/index.js 45.5 kB +1 B
build/format-library/index.js 7.49 kB +1 B
build/html-entities/index.js 622 B +1 B
build/i18n/index.js 3.54 kB -1 B
build/list-reusable-blocks/index.js 3.02 kB -1 B
build/notices/index.js 1.69 kB -1 B
build/redux-routine/index.js 2.85 kB -2 B (0%)
build/server-side-render/index.js 2.6 kB +2 B (0%)
build/url/index.js 4.06 kB -1 B
build/viewport/index.js 1.74 kB +2 B (0%)
build/warning/index.js 1.13 kB +3 B (0%)
ℹ️ 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/blob/index.js 620 B 0 B
build/block-directory/index.js 8.55 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 10.9 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/editor-rtl.css 8.6 kB 0 B
build/block-library/editor.css 8.6 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/blocks/index.js 47.5 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.4 kB 0 B
build/compose/index.js 9.42 kB 0 B
build/core-data/index.js 12 kB 0 B
build/data-controls/index.js 685 B 0 B
build/data/index.js 8.6 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.42 kB 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/index.js 20.4 kB 0 B
build/edit-site/style-rtl.css 3.83 kB 0 B
build/edit-site/style.css 3.83 kB 0 B
build/edit-widgets/index.js 21.1 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/element/index.js 4.44 kB 0 B
build/escape-html/index.js 734 B 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/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.39 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/media-utils/index.js 5.12 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.34 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/rich-text/index.js 13 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@obenland obenland marked this pull request as ready for review September 15, 2020 19:01
@obenland
Copy link
Member Author

Not sure if the suggested way to do this is the best, any feedback you have I'd love to hear.
Another area of uncertainty is naming 🙂
MediaAddButton sounds a bit awkward but feels close to the existing media-* nomenclature.

Copy link
Contributor

@cpapazoglou cpapazoglou left a comment

Choose a reason for hiding this comment

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

Tested by test instructions and LGTM!

  • Removes the trailing appender
  • Introduces an "Add" button with a text label
  • "Add" button invokes a dropdown menu with "Open Media Library" and "Upload" options

Naming wise, I would argue that media-add-flow and MediaAddFlow would follow the pattern of media-replace-flow and MediaReplaceFlow. In that sense, it may also best fit under packages/block-editor/src/components/media-add-flow/ dir serving as a component which may be reused from other media galleries perhaps (in the future)?

Should we consider exploring the fact that MediaReplaceFlow may be reused with some minor changes? It already accepts a Name attribute which can be set to Add and it seems we just need to return an array of media instead of a single media item. Apart from that, they seem functioning almost the same (I may be wrong of course). In that case, it could be also renamed to MediaFlow.

<MediaReplaceFlow
	mediaId={ ids }
	allowedTypes={ ALLOWED_MEDIA_TYPES }
	accept="image/*"
	name={ __( 'Add' ) }
	onSelect={ this.onSelectImages }
	onError={ this.onUploadError }
/>

@obenland
Copy link
Member Author

I wonder if MediaReplaceFlow is a little too opinionated to be extendable like that. Putting MediaAdd alongside it might be a better option

@ZebulanStanphill ZebulanStanphill added the Needs Accessibility Feedback Need input from accessibility label Sep 18, 2020
@cpapazoglou
Copy link
Contributor

I wonder if MediaReplaceFlow is a little too opinionated to be extendable like that. Putting MediaAdd alongside it might be a better option

Can't find an evidence of being opinionated, it seems that both add and replace do the same exact thing with different labelling. Not 100% sure though!

Copy link
Contributor

@afercia afercia left a comment

Choose a reason for hiding this comment

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

From an a11y perspective:

  1. The "Add" button should have an aria-haspopup="true" to announce it opens an additional UI, like the "More options" button on its right. See also Fix the usage of aria-haspopup  #24796 for the general issue.
  2. Since there's a lot of space in the toolbar, can we make the "Add" text more explicit to better differentiate this button from all the other "Add block", "Add this", "Add that" ones?

Screenshot 2020-09-18 at 15 02 20

Changing the text tp "Add image" would be great.

General:

  1. When opening the media modal, the dropdown menu stays on top of the media modal content (higher z-index I guess), at least for me. Screenshot:

Screenshot 2020-09-18 at 15 01 58

  1. I see the input type="file" is hidden with display: none;. Though this relates to the specific component, are we sure it works correctly with all browsers? Recently there has been a similar issue in core where with old Edge and iOS the upload button didn't work. Also, this seems inconsistent with what core does. See https://core.trac.wordpress.org/changeset/47834 and https://core.trac.wordpress.org/ticket/49753 Cc @tellthemachines and @azaozz who know more about this issue.

First pass.

This will at least make it functional. Next: Cleanup.
obenland and others added 3 commits October 2, 2020 11:26
Props @ZebulanStanphill

Co-authored-by: Zebulan Stanphill <zebulanstanphill@protonmail.com>
@obenland
Copy link
Member Author

obenland commented Oct 2, 2020

@afercia Thank you for this excellent review and feedback!

I added the a11y improvements you pointed out (I was not aware of aria-haspopup, TIL!).

The dropdown menu staying on top of the media model is a mystery to me. I have no idea how I missed that during initial development, and I'm not sure how to best go about that. It looks like the z-index values for both components haven't changed in years, so I wonder if there's something that changed with toggling that dropdown open and close?
@ellatrix Do you happen to have any advice for me on how to fix that?

In regards to the input type="file" being hidden, yes, that style is being set within the component. Since this PR doesn't really change anything in FormFileUpload, would you mind if we kept that separate for now?

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

@obenland with the merging of the gallery refactor, the packages/block-library/src/gallery/edit.js has radically changed, so it will be easier to reapply your changes onto the new file instead of trying to resolve the conflicts.

Do you want to do that on this PR, or will it be easier to close this and create a new PR for it?

@glendaviesnz
Copy link
Contributor

Going to close this for now. The original issue has been added the the gallery refactor project board and we will reimplement this in a new PR against the refactored gallery block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move Gallery "Add new / Media Library" actions to the Toolbar
5 participants