Skip to content

Template Part block - add border states in editor.#24498

Merged
noahtallen merged 7 commits intomasterfrom
add/template-part-border-states
Aug 20, 2020
Merged

Template Part block - add border states in editor.#24498
noahtallen merged 7 commits intomasterfrom
add/template-part-border-states

Conversation

@Addison-Stavlo
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo commented Aug 11, 2020

Description

Adding is-selected, has-child-selected, and hover border states to the template part block in the editor. (as requested in #22064)

These borders styles have been intentionally matched visually to fit the style added on the focus state by the block-list component, and change the color appropriately for each state:

&::after {
position: absolute;
z-index: 1;
pointer-events: none;
content: "";
top: $border-width;
bottom: $border-width;
left: $border-width;
right: $border-width;
// 2px outside.
box-shadow: 0 0 0 $border-width-focus var(--wp-admin-theme-color);
border-radius: $radius-block-ui - $border-width; // Border is outset, so so subtract the width to achieve correct radius.
// Show a light color for dark themes.
.is-dark-theme & {
box-shadow: 0 0 0 $border-width-focus $dark-theme-focus;
}
}

How has this been tested?

Screenshots

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.

@Addison-Stavlo Addison-Stavlo changed the title WIP - Template Part block - add border states in editor. Template Part block - add border states in editor. Aug 11, 2020
@Addison-Stavlo Addison-Stavlo marked this pull request as ready for review August 11, 2020 20:59
@github-actions
Copy link

github-actions bot commented Aug 11, 2020

Size Change: +157 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-library/editor-rtl.css 8.44 kB +79 B (0%)
build/block-library/editor.css 8.44 kB +78 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.96 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/index.js 126 kB 0 B
build/block-editor/style-rtl.css 10.7 kB 0 B
build/block-editor/style.css 10.7 kB 0 B
build/block-library/index.js 133 kB 0 B
build/block-library/style-rtl.css 7.45 kB 0 B
build/block-library/style.css 7.45 kB 0 B
build/block-library/theme-rtl.css 729 B 0 B
build/block-library/theme.css 730 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.6 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 11.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.55 kB 0 B
build/date/index.js 5.38 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.47 kB 0 B
build/edit-navigation/index.js 11 kB 0 B
build/edit-navigation/style-rtl.css 1.12 kB 0 B
build/edit-navigation/style.css 1.12 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.61 kB 0 B
build/edit-post/style.css 5.61 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 11.8 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 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 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 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.33 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 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.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@jeyip
Copy link
Contributor

jeyip commented Aug 11, 2020

🚀 Hover state border works displays as expected in Safari, Chrome, Firefox, Edge, and IE11.

Note:
Unrelated to the changes made in this PR, but the left and right borders are cut off on my screen. (Make sure to click on and enlarge the linked image...the preview doesn't seem to be displaying the issue correctly)

Screen Shot 2020-08-11 at 2 11 20 PM

Copy link
Contributor

@jeyip jeyip left a comment

Choose a reason for hiding this comment

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

Thanks for handling the code changes @Addison-Stavlo. I see this as great foundation that we can iterate on and modify in future PRs.

@noahtallen
Copy link
Member

I'll stick a design feedback label on here just to get some ✅ before merging :)

@noahtallen noahtallen added the Needs Design Feedback Needs general design feedback. label Aug 11, 2020
@noahtallen
Copy link
Member

2020-08-11 14 55 45

Here's a gif to see how it looks ^^

Note that in real life, it is more smooth. The frame rate of the gif is just poor. :)

Here is a screenshot of editing a child block in a narrower alignment:
Screen Shot 2020-08-11 at 3 01 07 PM

I'm noticing that in a lot of cases, it takes an extra click to interact with child blocks (and with the inserters). I think this tradeoff is worth it, but it's definitely a consideration. If no block is selected, I'm noticing that some template part child blocks interact directly on first click (including site title and the nav block) but some take that extra click to get into (including paragraph and image blocks). It's kinda weird how that is inconsistent 🤔 And if you have a different block other than the template part selected first, then pretty much nothing will interact without that extra click.

@Addison-Stavlo
Copy link
Contributor Author

Unrelated to the changes made in this PR, but the left and right borders are cut off on my screen. (Make sure to click on and enlarge the linked image...the preview doesn't seem to be displaying the issue correctly)

I noticed this too! I think on my screen I slightly see the border on the right side but not the left. We would see the entire border if we added the inset option to the box-shadow border. But since the current focus style from block-list doesn't do this I haven't changed it here. Since it would feel a bit odd for the border to be different sizes in different states. 🤔

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 11, 2020

I'm noticing that in a lot of cases, it takes an extra click to interact with child blocks (and with the inserters).

I see, I am noticing this too! This is a result of our last change and we are forced to select the template part (clicking on any child block selects the template part first) before being able to select a child.

Maybe we should only disable the pointer events for the block inserters when the template part is not selected, so we can still get to edit existing child blocks in 1 click. 🤔 (edit: actually this does not seem as simple as anticipated.)

I think this tradeoff is worth it, but it's definitely a consideration.

Yeah, im not certain either. It doesn't feel bad though. You click and it selects the template part, then you see the standard cursor options for being able to select everything inside it.

@jeyip
Copy link
Contributor

jeyip commented Aug 11, 2020

Maybe we should only disable the pointer-events for the block inserters when the template part is not selected, so we can still get to edit existing child blocks in 1 click. 🤔 (edit: actually this does not seem as simple as anticipated.)

I've been investigating this as well. It looks like the inserter is not a descendent of the block-list. It's actually rendered in a popover closer to the root of the DOM (it ends up being an ancestor's sibling). This is why we're having trouble selecting it when evaluating the hover state of .block-editor-block-list__block[data-type="core/template-part"].

I'm exploring different ways of selecting ancestor siblings with CSS, but it seems like Javascript may be the most straightforward approach.

@dubielzyk
Copy link

Testing it right now. It feel really nice. The two modes are making it extra complicated to get this feeling right. I love the hover in edit mode, but it feels weird that it doesn't appear everywhere. When I originally outlined this I didn't think we'd have a hover border in Edit mode since that's not how Edit mode behaves. I didn't explain this well in the original design dump though.

I think we should have only the hover border appear in Select mode. And when you have Edit mode we shouldn't have any hover border, but still have the active border as outlined in this comment.

Does that make sense? Would love further thoughts.

@jeyip
Copy link
Contributor

jeyip commented Aug 12, 2020

When I originally outlined this I didn't think we'd have a hover border in Edit mode since that's not how Edit mode behaves.

Ahhhh. I see that in your original design dump now.

I'm playing around with select mode in production while cross-referencing your designs, and it seems like net new work only includes two design proposals. In select mode, a subtle gray hover border appears around a template part:

  1. when a child block is hovered
  2. when a child block is selected.

Does that sound right @dubielzyk ?

Screen Shot 2020-08-12 at 1 22 42 AM

As for edit mode, it's a similar idea. The proposal is that, when focusing a child block, a subtle gray border appears around the template part.

Screen Shot 2020-08-12 at 1 34 54 AM

Let me know if I'm that's more aligned with what you were proposing for hover / focus borders.

@dubielzyk
Copy link

Does that sound right @dubielzyk ?

Exactly. That's the most subtle improvement and the one that would leave it as close to as it is today while also trying to achieve the goal. Once we have that we can build by adding labels, noticed etc. But I think it's important to build something first that tries to work within the parameters.

Once we start adding borders on hover in Edit mode we start ruining the modes themselves and it would then require us to rethink how the modes work.

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 12, 2020

when a child block is hovered

Currently select mode disables the ability to hover child blocks until either the parent is selected or other children have been selected. In case A, the parent is selected and has the blue border and children have the 'grey' border on hover. In case B, the selected child has a blue border and other children have the grey border on hover (and we have the grey border on the template part in this PR from the has-child-selected state).

If our goal is to have the children of the template part hover-able before the template part is selected, that is a diversion from select mode's functionality. Not only would this currently require a bit of a 'hacky' solution (or just an overhaul of select mode itself for everything to remain consistent with other blocks), but would create inconsistencies with the behavior of select mode in the editor. This would also make the children of the template part more easily selectable and editable than children of any other types of blocks, which decreases the concern of which parent they belong to and how that might effect things differently than standard blocks.

@Addison-Stavlo
Copy link
Contributor Author

We removed the hover-state border in edit mode. So now we have:

In edit mode:
borders-edit-mode

In select mode:
select-mode-borders

I think these are subtle, non-intrusive changes that will have a pretty decent effect on visibility. I think it coveres everything from the border designs? Except for the select mode design for:

Screen Shot 2020-08-12 at 1 42 51 PM

Since this type of hover state isn't possible in select mode until the parent or other children have already been selected, and there would be some concerns implementing it for template parts only (outlined more in my comment above).

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

This works well for me. My one nitpick is: is it possible to make the border a slight bit smaller in the "editing an inner block" state? It seems like it could be just a bit less intense, if that makes sense

@jeyip
Copy link
Contributor

jeyip commented Aug 12, 2020

Looks good to me 🙂

Non-blocking
Should the border-color be slightly more understated?

@noahtallen
Copy link
Member

haha, I guess we noticed a similar thing. Either color or width or both could make it less understated, I guess

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 12, 2020

haha, I guess we noticed a similar thing. Either color or width or both could make it less understated, I guess

Yeah, maybe we should try to match its width/color to the grey border applied by select mode hover state. Looking for what that is...

It is matched in size to the border applied by focus/select state on the template part (the blue border). Maybe we want to keep its size matched to that and just lower the level of gray? 🤔

@Addison-Stavlo
Copy link
Contributor Author

So we are really nitpicking at the border now, but these Gifs might help point out the confusion Im having on which style we should conform to in terms of border width:

Notice the border stays the same width as we go from the blue border of the template part to the grey border when the child is selected:
same-width-as-focusmode

Notice how the grey hover-state border in select mode has a slightly smaller border width:
different-border-select-hover

So I wonder if it is better to conform to the border styles of the blue/focus state, or the grey hover state in select mode. 🤔

@noahtallen
Copy link
Member

It is matched in size to the border applied by focus/select state on the template part (the blue border).

In my brain, it makes sense to be less prominent than this, so I can definitely see a case for matching the hover state for select mode

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 12, 2020

In my brain, it makes sense to be less prominent than this, so I can definitely see a case for matching the hover state for select mode

Updated to match the child-selected state gray border to the gray border shown in select mode hover state. (reduced from $border-width-focus to $border-width, and from $gray-700 to $gray-600)

I think it feels better this way too!

@dubielzyk
Copy link

This is looking good to me. Thanks for the context. If we can't select child blocks in Select mode it seems like it'll be harder to use.

I like the GIF where the border widths are the same, so we should aim for that. Can we change the gray color to make it light-gray-700? Or can you point me to the color spec we're relying on and I'll select an appropriate color?

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 13, 2020

Perhaps this is a better way to describe the current state of this PR:

Pre-Existing Borders

  • Border 1 - the blue border on focus of the template part. This appears when you select the template part, but disappears when you start messing with the toolbar (select the re-naming input, etc.), even though the block is still technically selected.
  • Border 2 - the gray border on hover while in select mode.

Added Borders

  • the selected state of template part. Made to match the style of border 1, so border 1 is still apparent at all times that the block is selected.
  • the child-selected state of template part. Made to match the style of border 2 to be consistent (this consistency may not be necessary).

I like the GIF where the border widths are the same, so we should aim for that.

(note the current state described above is slightly different than when those gifs were created)

Gif 1 - where the border widths are the same is the same gray border used in gif 2 where the width is different from the hover border applied by select mode. So having gif 1 causes gif 2 since the 'blue focus border' and the 'gray hover border' from select mode have different widths by default. We had updated since these gifs to match the opposite, so the blue border is the only wide one ($border-width-focus) while the grey border is thinner ($border-width), which seems to make sense in the states they are used given their names. Should we increase the added gray border width to achieve the state shown in those 2 gifs again?

Can we change the gray color to make it light-gray-700? Or can you point me to the color spec we're relying on and I'll select an appropriate color?

We can, although that seems very light? Here is light-gray-700 in contrast to the border applied by the select mode hover state (also notice these are the same widths now in this state, contrary to 'gif2' mentioned above):
light-gray-700-2
The darker border is the default applied by select mode in hover state. The lighter border is our addition using the light-gray-700. I came by gray-600 previously by visually matching these to be the same color (and verified by searching the codebase that gray-600 is indeed the color applied by select mode hover state).

Or can you point me to the color spec we're relying on and I'll select an appropriate color?

Here is where the base colors live - by the comments there is seems gray-200 is the 'standard' border color, but that seems about the same as the light-gray-700 shown above. I figured it was best to match the color to the gray border in select+hover but we can change it around to whatever you feel makes sense.

(Note- selecting another color may require an additional separate color selection for dark themes, $gray-600 seems to be used for both light and dark themes by select mode hover since it is neutral between the two. Ex- if we wanted to go with gray-200, maybe gray-700 would make sense for dark themes as it is roughly equidistant from black as gray-200 is from white, etc.)

@dubielzyk
Copy link

Thanks for the info. Let me have a look and let's tweak the colors at the last stage. There's a few other things I'm wondering:

  • How come Selection mode highlights two things in this video? One for the image itself and one for the container around it, yet the whole thing seems to only be one block element (Site Logo).
  • Is it possible to not have the page jump around when selecting different template parts? See video

@dubielzyk
Copy link

The lighter border is our addition using the light-gray-700. I came by gray-600 previously by visually matching these to be the same color (and verified by searching the codebase that gray-600 is indeed the color applied by select mode hover state).

Quick comment on the color. The reason for wanting a lighter color (~gray300) is so that, in Selection mode, the template hover part border and block hover border isn't the same. With them both the same we end up with this. The goal is to just highlight that you're selecting a block that's part of something bigger (the template part). Does that make sense?

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 17, 2020

How come Selection mode highlights two things in this video? One for the image itself and one for the container around it, yet the whole thing seems to only be one block element (Site Logo).

In that video the block in question is the site logo, which has that external wrapper. Currently the actual block used in this header in the example is an image block, which is not the same as site logo and lacks that outer wrapper, etc.

Is it possible to not have the page jump around when selecting different template parts?

Yeah, but it's not exactly straight forward what is causing it. The Post Content block also seems to do the same thing (and when group blocks nest either of these selecting them seems to do the same). I think it's a separate bug to fix outside of this issue specifically.

Edit - Looking more it seems less of a bug and more of an expected behavior for container blocks. When this type of block is selected, the block appender is added to the bottom of the block so the user has a straight forward way to add another child block to the parent container:

Screen Shot 2020-08-17 at 1 14 01 PM

Then when unselected that appender disappears causing the 'jump around' behavior you noted. But this is more related to the actual block appender system itself and not really specific to the template part block's implementation.

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 17, 2020

Re - the Colors:

Does that make sense?

100%, that makes sense. Give this a spin and see how it feels? There isnt a gray-300 defined for whatever reason, so for now this is set to gray-200 since that was listed as the standard border color in the file. We can change it to light-gray-700 if that makes more sense too. Whatever you think works best sounds good to me.

Also, do you have any idea about what the dark theme color should be for this? I know its kind of an odd question since we don't have a dark block based theme currently. I currently set it to gray-700 since that should be a small contrast to a dark theme? (The other 'wp-admin-blue' border is already taken care of as that consistently turns to white in dark themes, but for our less-apparent border color we probably do need to set something for that circumstance 🤔 ).

@noahtallen
Copy link
Member

But this is more related to the actual block appender system itself and not really specific to the template part block's implementation.

+1. I agree this needs to be drastically improved since it feels very rough, but we can do that in a separate issue :)

@noahtallen noahtallen force-pushed the add/template-part-border-states branch from 83cc4d5 to 5a73f05 Compare August 19, 2020 20:49
Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

cc @MichaelArestad @shaunandrews do you have thoughts about this? Unless there are concerns, I think we can move forward with this!

Current look:

2020-08-19 13 58 18

Regarding code, I think in the future we might want to make this more general. I could see the same style being useful for the post content block, since it is a block container in the same way. I could see us wanting to apply this style if:

  • The block is an inner block controllers
  • Or just if the block has inner blocks in general

But that's a discussion code wise :)

@noahtallen noahtallen merged commit 8f57a1f into master Aug 20, 2020
@noahtallen noahtallen deleted the add/template-part-border-states branch August 20, 2020 19:36
@github-actions github-actions bot added this to the Gutenberg 8.9 milestone Aug 20, 2020
@MichaelArestad
Copy link
Contributor

@noahtallen It's not really clear to me what the border alone represents or why it is there. I know there is work being done with a label as well so I'm waiting to see how the label is implemented before worrying too much about it.

@noahtallen
Copy link
Member

it's representing the area around the block area the user is editing. currently it's almost entirely impossible to tell without clicking all over the place to find where the template part ends and begins. but the label will definitely help things a lot too :)

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

Labels

Needs Design Feedback Needs general design feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants