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

Heading block: move alignment controls to toolbar (#2) #17419

Merged
merged 9 commits into from
Sep 14, 2019

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Sep 12, 2019

Description

An alternative to #16682.

Closes #16648.

Added an alignment toolbar component to the heading block's toolbar.

Screen Shot 2019-09-12 at 13 04 45

Screen Shot 2019-09-12 at 13 05 03

On the implementation side of things, the biggest difference in comparison to #16682, this PR adds an icon for each heading level which removes the need to drill down subscript prop to other components together with CSS styling based on the data attribute.

TODO

  • Provide better icons which have fixed size 20x20

@gziolo gziolo added [Package] Block library /packages/block-library [Block] Heading Affects the Headings Block [Type] Enhancement A suggestion for improvement. labels Sep 12, 2019
@gziolo gziolo force-pushed the update/unify-formatting-tools-icons branch from 4840d7a to 1059774 Compare September 12, 2019 18:53
@gziolo
Copy link
Member Author

gziolo commented Sep 12, 2019

@mapk or @jasmussen - how do you feel about this approach? We would still have to create icons which fit better to make it look solid.

@gziolo gziolo changed the title Update/unify formatting tools icons Heading block: move alignment controls to toolbar (#2) Sep 12, 2019
@gziolo gziolo requested a review from youknowriad September 12, 2019 19:45
icon={ <HeadingLevelIcon level={ selectedLevel } /> }
controls={ range( minLevel, maxLevel ).map(
( index ) => this.createLevelControl( index, selectedLevel, onChange )
) } />
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: /> can be moved to the next line

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed that, sorry :(

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Code wise, this looks good. Design-wise, these svgs might need to be tweaked but I leave that for designers.

@jasmussen
Copy link
Contributor

Not able to test this at the moment, but purely judging by the lovely screenshots, this looks good. The hierarchy is right, heading level first. The dropdowns work well for keeping the toolbar compact. The icons look great and is a good alternative to the previous heading icons, more legible. In that vein and as a design sanity check, 👍👍

Now that the heading level is in a drop-down, there is an open question around the heading levels, though. So as to not keep up this PR, this is fine to look at separately, but worth mentioning. And that is: should we show all heading levels, h1 to h6, in the drop-down? Given the space is there, the absence seems confusing.

I realize the reason they are not there is that we don't want to encourage wrongful usage of the heading levels breaking the semantics. In the past we forced users into the sidebar to choose those levels. At the same time if we show all levels here, we don't need to also have the levels in the sidebar, and we do have tools to help you understand wrongful usage of heading levels, so maybe it's okay?

@gziolo
Copy link
Member Author

gziolo commented Sep 13, 2019

Now that the heading level is in a drop-down, there is an open question around the heading levels, though. So as to not keep up this PR, this is fine to look at separately, but worth mentioning. And that is: should we show all heading levels, h1 to h6, in the drop-down? Given the space is there, the absence seems confusing.
I realize the reason they are not there is that we don't want to encourage wrongful usage of the heading levels breaking the semantics. In the past we forced users into the sidebar to choose those levels. At the same time if we show all levels here, we don't need to also have the levels in the sidebar, and we do have tools to help you understand wrongful usage of heading levels, so maybe it's okay?

I'm open to iterations here. There is one thing to consider, we want to provide tooling which helps to emphasize issues with the semantics of your content. Heading levels is one of the common issues which impacts accessibility. We have this PR proposed: #14889 which adds heading hierarchy checker:

image

So, if we were to consolidate those levels in the toolbar, we would have to find a different way to present this message.

@jasmussen
Copy link
Contributor

Excellent point. That is an argument to move forward with this PR as is, and explore the changes discussed separately.

And regarding those changes, it seems like it should be possible to show such a warning directly in the drop-down, no?

@jasmussen
Copy link
Contributor

GIF:

heading

The icons are a bit small

before

So I increased their size

Screenshot 2019-09-13 at 15 20 04

Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

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

I think we should follow up on showing all heading levels, with warnings for picking the wrong ones, but in a separate PR. As is, this is good from a design perspective. If anyone wants to give additional sanity checks to the code feel free, but otherwise 👍 👍

@jasmussen
Copy link
Contributor

Here's a very rough mockup of what it could look like, to show the warnings for incorrect heading level usage in the menu:

Screenshot 2019-09-13 at 15 26 24

☝️ We would want to either link to more information, or show more information as a tooltip, or rephrase to be more descriptive. Also the h1 icon should be used, obviously. But as an "inspector" mockup, it hopefully gets the point across. What do you think?

@mapk
Copy link
Contributor

mapk commented Sep 13, 2019

As is, it feels good to me too. I agree with @jasmussen that I'd like to see all heading levels in the popover as well. Should we include all headings in this PR right now? And work in the warnings in another PR as mentioned?

@youknowriad
Copy link
Contributor

youknowriad commented Sep 14, 2019

Should we include all headings in this PR right now? And work in the warnings in another PR as mentioned?

I feel we should do both these things at the same time to avoid the potential "regression" of this message not being seen by people using the new dropdown in the meantime.

@gziolo
Copy link
Member Author

gziolo commented Sep 14, 2019

I'm merging this PR as is to avoid lengthy debate about implications of the change in UI. For reference, this is how it would look in the dropdown:

Screen Shot 2019-09-14 at 10 15 06

Code:

diff --git a/packages/block-library/src/heading/edit.js b/packages/block-library/src/heading/edit.js
index 3289fb5a7..b591bca52 100644
--- a/packages/block-library/src/heading/edit.js
+++ b/packages/block-library/src/heading/edit.js
@@ -61,16 +61,12 @@ function HeadingEdit( {
 	return (
 		<>
 			<BlockControls>
-				<HeadingToolbar minLevel={ 2 } maxLevel={ 5 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
+				<HeadingToolbar minLevel={ 1 } maxLevel={ 6 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
 				<AlignmentToolbar value={ align } onChange={ ( nextAlign ) => {
 					setAttributes( { align: nextAlign } );
 				} } />
 			</BlockControls>
 			<InspectorControls>
-				<PanelBody title={ __( 'Heading Settings' ) }>
-					<p>{ __( 'Level' ) }</p>
-					<HeadingToolbar isCollapsed={ false } minLevel={ 1 } maxLevel={ 7 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
-				</PanelBody>
 				<HeadingColorUI
 					setTextColor={ setTextColor }
 					textColorValue={ textColor.color }
diff --git a/packages/block-library/src/heading/edit.native.js b/packages/block-library/src/heading/edit.native.js
index 389791663..961f08832 100644
--- a/packages/block-library/src/heading/edit.native.js
+++ b/packages/block-library/src/heading/edit.native.js
@@ -27,8 +27,8 @@ const HeadingEdit = ( {
 	<View onAccessibilityTap={ onFocus }>
 		<BlockControls>
 			<HeadingToolbar
-				minLevel={ 2 }
-				maxLevel={ 5 }
+				minLevel={ 1 }
+				maxLevel={ 6 }
 				selectedLevel={ attributes.level }
 				onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) }
 			/>
diff --git a/packages/block-library/src/heading/heading-toolbar.js b/packages/block-library/src/heading/heading-toolbar.js
index f3a089a8f..fb85152c0 100644
--- a/packages/block-library/src/heading/heading-toolbar.js
+++ b/packages/block-library/src/heading/heading-toolbar.js
@@ -33,7 +33,7 @@ class HeadingToolbar extends Component {
 			<Toolbar
 				isCollapsed={ isCollapsed }
 				icon={ <HeadingLevelIcon level={ selectedLevel } /> }
-				controls={ range( minLevel, maxLevel ).map(
+				controls={ range( minLevel, maxLevel + 1 ).map(
 					( index ) => this.createLevelControl( index, selectedLevel, onChange )
 				) } />
 		);

@gziolo gziolo merged commit 53f2aea into master Sep 14, 2019
@gziolo gziolo deleted the update/unify-formatting-tools-icons branch September 14, 2019 14:16
@gziolo
Copy link
Member Author

gziolo commented Sep 14, 2019

Continuing on the previous topic of accessibility violations.

Here's a very rough mockup of what it could look like, to show the warnings for incorrect heading level usage in the menu:

Screenshot 2019-09-13 at 15 26 24

The biggest challenge I see is the discovery of this message. As soon as you change the level of heading, you won't see the dropdown anymore so it'd be very likely you would miss it. I'm wondering whether you see an elegant way to extend block's UI to have a space for such warnings. The other example is the contrast warning which is located in the sidebar. In that case, the feedback loop is much better as you need to perform all interactions in the same place.

@youknowriad youknowriad added this to the Gutenberg 6.5 milestone Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Heading Affects the Headings Block [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify text alignment location between Heading and Paragraph blocks
5 participants