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

Writing Flow: Always add an empty at the end of the block list #3623

Merged
merged 6 commits into from Nov 24, 2017

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Nov 23, 2017

closes #3078

This PR

  • Removes the trailing inserter
  • Add an invisible textarea under the block list to add a new text block when needed.

@youknowriad youknowriad self-assigned this Nov 23, 2017
@codecov
Copy link

codecov bot commented Nov 23, 2017

Codecov Report

Merging #3623 into master will decrease coverage by 0.25%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3623      +/-   ##
==========================================
- Coverage   36.95%   36.69%   -0.26%     
==========================================
  Files         268      268              
  Lines        6673     6649      -24     
  Branches     1202     1201       -1     
==========================================
- Hits         2466     2440      -26     
- Misses       3555     3557       +2     
  Partials      652      652
Impacted Files Coverage Δ
editor/components/block-list/index.js 0% <ø> (ø) ⬆️
editor/store-defaults.js 100% <ø> (ø) ⬆️
editor/components/block-list/block.js 0.74% <ø> (ø) ⬆️
editor/reducer.js 90% <ø> (-0.28%) ⬇️
editor/components/block-drop-zone/index.js 0% <ø> (ø)
editor/selectors.js 92.85% <ø> (-0.27%) ⬇️
editor/edit-post/modes/visual-editor/index.js 0% <0%> (ø) ⬆️
editor/components/default-block-appender/index.js 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5ede2e...b8f960c. Read the comment docs.

@jasmussen
Copy link
Contributor

I really, really really love this. I think it's a much better experience without all that trailing chrome, and it's a much clearer way to insert content after non-text blocks. Here's a brief GIF:

click below

I'd love @mtias and @karmatosed's opinion (but I'm crossing my fingers they'll like this as much as I do), and we want to make sure that empty textarea is announced correctly to screen readers (cc: @afercia for a quick test perhaps). Finally it looks like we may in fact need #3485 after all (despite my comment here).

@jasmussen
Copy link
Contributor

Small update — we'll still want the placeholder to look and function like it used to on an empty post:

screen shot 2017-11-23 at 11 55 29

That is — with the "Write your story" prompt, and the border on hover.

The chief reason why the border and text prompt shown at the end of the blocklist on a populated page should be less visible, only indicated by the hover ibeam cursor, is that there isn't actually a block there. I know that's the same at the start of a post, but we do need a prompt and some canvas indication there.

@youknowriad
Copy link
Contributor Author

Updated with the visible placeholder when post is empty

@afercia
Copy link
Contributor

afercia commented Nov 23, 2017

Tested a bit with keyboard only and also with screen readers. Seems the block is announced correctly, as it just uses the default aria-label Add text or type / to insert content. Improvements to the Editable blocks (role and aria-label) are discussed on other issues.

However, there's a big issue 🙂 Right now, it's a keyboard trap. Whatever I do, using only the keyboard with no screen reader running or also with a screen reader, when I tab away from the lazt block I always get a new paragraph and there's no escape. This breaks any attempt to navigate the page using the keyboard.

At each Tab press, a new paragraph gets added:

screen shot 2017-11-23 at 13 14 51

Also, the paragraphs get saved in the content that soon becomes full of empty paragraphs:

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

@youknowriad
Copy link
Contributor Author

@afercia What solution do you propose to this?

The only option I can think of is making this "untabbable" when the post is not empty which make it useless using keyboard but I think it's more targeted towards mouse users?

@youknowriad
Copy link
Contributor Author

Edit: Actually I may have a better option, transform this placeholder to a "button" only actionable on click/enter

@jasmussen
Copy link
Contributor

Forgive me for asking a possibly silly question: why does tabbing away from the placeholder textarea create a block? Shouldn't it just focus whatever element comes next in the flow after the placeholder?

@youknowriad
Copy link
Contributor Author

updated, there's no tab trap anymore but I may be missing some ARIA labels

@jasmussen
Copy link
Contributor

If a button is kosher to use and that works well, then cool — but a followup question: is it then kosher to apply cursor: text; to that button? It's visually important to mouse users to indicate what happens when you click there, and a text/ibeam cursor is the best way to do so.

@afercia
Copy link
Contributor

afercia commented Nov 23, 2017

It's visually important to mouse users to indicate what happens when you click there,

I also think from an usability perspective, there should be some indication when hovering that area. A possible problem is it kinds of overlap the "drop zone"?

@afercia
Copy link
Contributor

afercia commented Nov 23, 2017

Tested with latest commit, there's no more a keyboard trap and that's good 🙂

However, when tabbing from the title to the first "Write your story" there's no indication of focus, so there's a tab stop but I don't know where I am.

Instead, after I add something and tab again, all the following buttons have a light gray border to indicate focus:

screen shot 2017-11-23 at 14 16 58

This is maybe too light and should be improved a bit but I guess it's outside of the scope of this PR. I'd second Joen: maybe the cursor should be a pointer but then maybe there should be some additional visual indication on hover.

@youknowriad youknowriad force-pushed the update/text-placeholdeer-always-visible branch from 021ffe1 to 93a16f9 Compare November 23, 2017 13:29
@youknowriad
Copy link
Contributor Author

maybe the cursor should be a pointer but then maybe there should be some additional visual indication on hover.

I think for mouse users the "text" cursor is a better visual indication than the "hover" style. The "hover" style on an empty area is distracting IMO.

However, when tabbing from the title to the first "Write your story" there's no indication of focus, so there's a tab stop but I don't know where I am.

This is fixed

@youknowriad youknowriad force-pushed the update/text-placeholdeer-always-visible branch from 93a16f9 to 441cfc4 Compare November 23, 2017 13:38
@jasmussen
Copy link
Contributor

Really nice work Riad. Here's a recording:

recording

I think we're 99% there.

There's just one issue now — arrow down from the title to start typing broke, and if you tab from the title, the button has focus but it still needs to be "clicked". Anything we can do here?

@jasmussen
Copy link
Contributor

Possibly related to the "keep typing" thing: #3558

@youknowriad
Copy link
Contributor Author

That's related to the fix for the tab trap, if you want to keep typing it should transform to a text block when it receives the focus.

A middle ground would be to do so only for empty posts.

What do you think?

@jasmussen
Copy link
Contributor

A middle ground would be to do so only for empty posts.

This sounds good to me.

One feature that works in master is that if the image is the last block in the list, and you select it and press Enter, then you can start typing again. Not very discoverable which is why I really like this branch and approach. However can we retain the feature? That is, if you press enter on the last image in a blocklist, you can type?

box-shadow: none;
display: block;
width: 100%;
height: $text-editor-font-size * 6; // 1.5 times the height of an empty paragraph
Copy link
Member

Choose a reason for hiding this comment

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

It's worth considering to introduce new scss variable $empty-paragraph-height to avoid those comments.

}

appendDefaultBlock() {
const newBlock = createBlock( getDefaultBlockName() );
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to update createBlock definition to simplify this call to:

export function createBlock( name = getDefaultBlockName(), blockAttributes = {} ) { ... }

this.props.onInsertBlock( createBlock() );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know :)

<div className={ className }>
<BlockDropZone />
<button onClick={ this.appendDefaultBlock }>
{ count === 0 && __( 'Write your story' ) }
Copy link
Member

Choose a reason for hiding this comment

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

Nice and simple 👍

}
}

export default connect(
Copy link
Member

Choose a reason for hiding this comment

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

it would be nice to have 3 unit tests:

  • count > 0 (snapshot test)
  • count = 1 check if there is class is-visible-placeholder and Write your story text
  • spy on insertBlock

I can add them, just ping me :)

@youknowriad youknowriad force-pushed the update/text-placeholdeer-always-visible branch from 441cfc4 to b8f960c Compare November 24, 2017 08:50
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I reviewed code part and it looks great. This change also removes some more complex logic which I'm always happy about. I will add unit tests for the newly introduced placeholder component. Don't wait for me, this is too nice change to postpone it :D

@youknowriad youknowriad merged commit 42f9b1a into master Nov 24, 2017
@youknowriad youknowriad deleted the update/text-placeholdeer-always-visible branch November 24, 2017 09:00
@mtias
Copy link
Member

mtias commented Nov 24, 2017

Sorry for not replying here earlier, but I think this is a bit rough and would need some further work and polish to be better than what we had, in my opinion.

Empty paragraphs even if you don't write anything.

If you click on the bottom of the post just to deselect something, you end up with an empty paragraph that you need to remove. This is not a great user experience.

image

If you click the bottom area, and then click something else, no paragraph should be left.

Jumpy Container

When you click on the empty area, there is a foucs area that is larger than what the paragraph would end up being, so the visual border jumps after click:

image

image

Preserving the Plus

I think Medium's screenshot in the linked issue strikes a better balance. At the moment it's not clear you can add other stuff other than text. The / command is a power user feature, and there is no indication it works at all until you see an empty paragraph's placeholder.

I strongly suggest retaining the plus, maybe show it when hovering the bottom area, and remove it once you start typing.

Treat it as if isEditing Continues

The other thing that bothers me is that the UI for the bottom block appears as soon as you click. That defeats the effect seeked, in my opinion. Clicking on the bottom area should just place the cursor there without the block UI, meaning it should engage isEditing mode, as you are not selecting a block but trying to continue writing.

@jasmussen
Copy link
Contributor

jasmussen commented Nov 24, 2017

Perhaps this PR was merged a bit quickly, but nothing's so bad that we can't fix it for 1.8 with a little polish here and there:

  • the jumpy container is my fault — I made it bigger, I shouldn't have, easy fix, just undo 29768ab
  • We should also get the arrow-key navigation from the title to the first placeholder block working, I believe that's a regression.
  • "If you click the bottom area, and then click something else, no paragraph should be left" is a good suggestion.

Those seem like good ones to address first.

Treat it as if isEditing Continues and Preserving the plus could potentially be solved together, or at least dictate how they should be implemented.

That is to say, right now the behavior of the trailing placeholder — the one at the end of a non empty post, not the first one on an empty post — is to create a new block when clicked/invoked. Given the model here is that of Medium, which I agree works very well, perhaps this trailing placeholder can be... let's call it "Schrödingers placeholder" — it exists, and doesn't exist, until you take an action on it.

Imagine you have a post with just an image in it. It could then work like this:

  1. Hover below the image block, see the "text" cursor.
  2. Click this area, the caret is now in this spot, and there's an inserter shortcut on the left, but no paragraph block has yet been created
    3a. Start typing — it's now a paragraph block, and you're typing so no borders or chrome are showing.
    3b. Click away — no paragraph block was created.
    3c. Click the inserter — you get the inserter.

Mockups. First you hover near the end:

01 hover near end

Then you click the "textfield", but no paragraph is created yet:

02 placeholder clicked

If you start typing, that's when the paragraph is created:

03 started typing

Edit: Updated the mockups above to have an image instead of text.

Thoughts? @mtias @gziolo @youknowriad @karmatosed

@youknowriad
Copy link
Contributor Author

We should also get the arrow-key navigation from the title to the first placeholder block working, I believe that's a regression.

This was working and got broken in one of the last changes, I'll fix it.

"If you click the bottom area, and then click something else, no paragraph should be left" is a good suggestion.

That's not an easy thing to do, because when we click it's transformed to a text block and we'd have to remove empty text blocks at the end or something and it's not easy to know when to do this exactly.

Click this area, the caret is now in this spot, and there's an inserter shortcut on the left, but no paragraph block has yet been created
3a. Start typing — it's now a paragraph block, and you're typing so no borders or chrome are showing.
3b. Click away — no paragraph block was created.
3c. Click the inserter — you get the inserter.

Same, this is doable but may take some time because typing in a input should transform to a text block and keep the cursor at the right position.

Maybe we should revert this PR and try to address those

@mtias
Copy link
Member

mtias commented Nov 24, 2017

That's not an easy thing to do, because when we click it's transformed to a text block and we'd have to remove empty text blocks at the end or something and it's not easy to know when to do this exactly.

I was thinking it would be a "mode" of the paragraph block that initializes as isEditing on click, and instead of block mover shows an inserter. On blur, if this special paragraph block is empty, we remove it.

Agree on reverting if we need more time to figure out implementation.

readOnly
onFocus={ this.appendDefaultBlock }
onClick={ this.appendDefaultBlock }
onKeyDown={ this.appendDefaultBlock }
Copy link
Member

Choose a reason for hiding this comment

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

In what case could a keydown event occur without the block already being focused? (And therefore triggering the identical focus event handler)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, probably a useless event handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider removing the trailing inserter in favor of a clickable area
6 participants