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

UI: Adding the selected and hover state for the visual editor #360

Merged
merged 2 commits into from
Apr 5, 2017

Conversation

youknowriad
Copy link
Contributor

In this PR, I'm adding the "selected" and "hover" state for blocks.
For now, hovering a block shows the left border while selecting it shows the full border.
Typing the keyboard inside a block unselect it.

@youknowriad youknowriad added the Framework Issues related to broader framework topics, especially as it relates to javascript label Mar 31, 2017
@youknowriad youknowriad self-assigned this Mar 31, 2017
@youknowriad
Copy link
Contributor Author

@aduth The onClick, and onKeyPress event handlers on the div are causing an issue with the accessibility lint checks. I'll have to use button or ignore these rules to pass the checks. What do you think? Using button seemed inappropriate to me in this case.

@jasmussen
Copy link
Contributor

Love it! 👍

One thing — if you click a block, leave the mouse where you clicked, and start typing, the block gets unselected but it still shows up as hovered. We should fade out everything when you are typing. If that's an easy fix, would be nice to get in this PR, otherwise feel free to merge this and let's revisit later.

@youknowriad
Copy link
Contributor Author

We should fade out everything when you are typing.

@jasmussen When should we trigger the hover state again? When we start moving the mouse again or when we hover out and in?

@youknowriad
Copy link
Contributor Author

@jasmussen I updated and dropped the "hover" state when we start typing and I hover again when we start moving the mouse again.

@jasmussen
Copy link
Contributor

Sorry missed your first ping. Just tried this. Works GREAT. Exactly how I think it should work. Ship it!

aduth
aduth previously requested changes Mar 31, 2017
...blocks.slice( index + 1 )
];

this.setState( { blocks: newBlocks } );
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid the mix of state and props blocks by forcing the component to be used as a controlled component? i.e. all blocks changes go through this.props.onChange and we assume that this.props.blocks is the canonical set of blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was originally like that But I don't know, I think the blocks, selected, hovered and more to come should stay on the same object (The visual editor's state) which could be updated using a "command" pattern (similar to redux) (See the updater in the per-block prototypes.

This allows us to handle undo/redo easily for example. Also having the selected, hovered state values on the parent component is not a good option because they're not needed in the text mode.

Thoughts?

Copy link
Member

@aduth aduth Mar 31, 2017

Choose a reason for hiding this comment

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

This feels similar to what I'd remarked at #348 (comment) , specifically that it becomes a maintenance nightmare to be managing multiple sources of truth, in this case reconciling the blocks of a component's state and the blocks passed from a parent component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me neither of the two solutions is perfect. Time to introduce redux ?

Copy link
Member

Choose a reason for hiding this comment

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

It seems inevitable we'll need some concept of global state which can be accessed and updated from disparate components of the application. Redux is a good solution for this, but I find can be a pain point for new developer onboarding. If this were a path we'd go down, I'd want to make a conscious effort to keep it simple, ideally a single top-level reducer with a few obvious actions (maybe not even action creators or selectors).

Copy link
Member

Choose a reason for hiding this comment

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

Why would Redux be a pain point for onboarding? Currently it's also not that evident where all the state is stored?

Copy link
Member

Choose a reason for hiding this comment

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

Why would Redux be a pain point for onboarding?

Because many of the concepts are not self-evident:

http://redux.js.org/docs/Glossary.html

@aduth aduth dismissed their stale review April 5, 2017 16:40

Authored changes

@aduth
Copy link
Member

aduth commented Apr 5, 2017

I rebased and refactored this pull request with consideration of #368, using global state to track hovered and selected block. This works quite well, even supporting tab-based focus navigation.

The only issue I still need to work through is that after making a change to a text block and clicking out, it becomes focused again. It appears TinyMCE is emitting a focus event on the wrapping element?

@aduth
Copy link
Member

aduth commented Apr 5, 2017

Adding accessibility label because I needed to explicitly disable an accessibility lint rule to support blocks receiving focus while also containing block children (block in the latter case referring to its display style).

https://github.com/WordPress/gutenberg/pull/360/files#diff-5cb891cd3125ad3b221777433a61a524R42

@aduth aduth added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Apr 5, 2017
@aduth
Copy link
Member

aduth commented Apr 5, 2017

I'm going to merge this and create a bug issue tracking the unexpected TinyMCE change + focusout behavior.

Edit: Bug tracked at #370

@aduth aduth merged commit a33cd56 into master Apr 5, 2017
@aduth aduth deleted the add/selected-hover-state branch April 5, 2017 22:20
@intronic intronic mentioned this pull request Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants