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

Blocks: Unselect the block when clicking outside the current block #730

Merged
merged 3 commits into from
May 12, 2017

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented May 9, 2017

closes #723

This PR changes the way we trigger the "deselect" action, leveraging the react-click-outside library instead of the onBlur event handler.

This should fix the issues seen in #723
The fix here also fix the auto focus on link input closes #679

@youknowriad youknowriad added [Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended labels May 9, 2017
@youknowriad youknowriad self-assigned this May 9, 2017
@youknowriad youknowriad requested review from jasmussen and aduth May 9, 2017 12:11
@jasmussen
Copy link
Contributor

Wow, you work fast!

I'm still seeing some issues though, let me know if you can't reproduce them:

https://cloudup.com/cCb3hTHs7xh

@youknowriad
Copy link
Contributor Author

@jasmussen I'm not seeing these errors. Which browser is this?

@jasmussen
Copy link
Contributor

Woot you're right — it was aggressive cache on my part. Can confirm that this seems to fix it! 👍

aduth
aduth previously requested changes May 9, 2017
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

This creates a global click handler for every block visible on the page. When you click anywhere on the page, the Redux store is flooded with TOGGLE_BLOCK_SELECTED. At the very least I think we should only call onDeselect if the block is currently selected.

@youknowriad youknowriad dismissed aduth’s stale review May 10, 2017 08:28

Good catch @aduth Should be fixed now

aduth
aduth previously requested changes May 10, 2017
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

On second review, I'm worried that detecting click outside is flawed in how it's moving further away from reacting to the focus behaviors themselves. For example, try clicking the borders of a block and tabbing, or focusing the first block and then shift-tabbing. Focus is no longer transitioned cleanly because it relies on the click behavior (though sometimes it does because of the next block "stealing" selected).

I think we should try to understand the challenges with focus that led to the issues observed in #723 and see if we can resolve them while still using focus events instead of click events.

@youknowriad
Copy link
Contributor Author

@aduth I couldn't find why the "blur" event is not triggered in the current approach in master. Should we rely on both "onBlur" and "onClickOutside"?

@aduth
Copy link
Member

aduth commented May 12, 2017

I managed to track it to focus shifting to body after clicking up causes the mover button to become disabled (because it's first in the list). I'm not sure why this is the behavior (especially without calling blur on the block) but "faking" the disable seems to allow focus to stay within the block so that the next click outside causes a real blur:

diff --git a/editor/components/block-mover/index.js b/editor/components/block-mover/index.js
index e872113..fe484c9 100644
--- a/editor/components/block-mover/index.js
+++ b/editor/components/block-mover/index.js
@@ -17,13 +17,13 @@ function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast } ) {
                                className="editor-block-mover__control"
                                onClick={ onMoveUp }
                                icon="arrow-up-alt2"
-                               disabled={ isFirst }
+                               aria-disabled={ isFirst }
                        />
                        <IconButton
                                className="editor-block-mover__control"
                                onClick={ onMoveDown }
                                icon="arrow-down-alt2"
-                               disabled={ isLast }
+                               aria-disabled={ isLast }
                        />
                </div>
        );
diff --git a/editor/components/block-mover/style.scss b/editor/components/block-mover/style.scss
index a93bcef..a7b6970 100644
--- a/editor/components/block-mover/style.scss
+++ b/editor/components/block-mover/style.scss
@@ -19,9 +19,10 @@
                color: $dark-gray-900;
        }
 
-       &[disabled] {
+       &[aria-disabled="true"] {
                cursor: default;
                color: $light-gray-300;
+               pointer-events: none;
        }
 
        .dashicon {

@youknowriad youknowriad force-pushed the fix/deselect-block branch from c838211 to 7bfc809 Compare May 12, 2017 08:01
@youknowriad youknowriad force-pushed the fix/deselect-block branch from 7bfc809 to 7c48392 Compare May 12, 2017 08:02
@youknowriad
Copy link
Contributor Author

youknowriad commented May 12, 2017

@aduth Awesome, how did you track this :P

In the second commit, I've fixed the "link" focus issue by auto-focusing the input (which was required in #679 ). I had to disable a lint error for this.

About jsx-a11y I'm starting to question whether we really need it because it doesn't detect the "real" accessibility issues.

@notnownikki
Copy link
Member

Works well for me 👍

@aduth
Copy link
Member

aduth commented May 12, 2017

@aduth Awesome, how did you track this :P

With some not-so-clever hackery 😄 I figured the focus must be moving somewhere if the next click on the body after moving the block up wasn't unselecting it. Since focus is fickle, I added some basic logging to see which element was active along the way:

setInterval( () => console.log( document.activeElement ), 500 );

Based on what I saw, it seems that because we cause the button to become disabled while it has focus, it reverts the page to an unfocused state. What is still baffling to me however is that this doesn't cause a blur event to fire on the block. Unsure if this is expected DOM behavior or perhaps a React bug.

@aduth
Copy link
Member

aduth commented May 12, 2017

About jsx-a11y I'm starting to question whether we really need it because it doesn't detect the "real" accessibility issues.

For me at least, I find it helps surface better understanding of where pain points with accessibility can arise. Following the rule doc to the guideline warning, it seems to be an issue of disorientation from moving focus around. In this case, the focus change is a result of an intentional action (activating the link button), so I'd imagine the user should expect the change. Maybe we can also hint to this on the button (aria-haspopup?).

@aduth
Copy link
Member

aduth commented May 12, 2017

In fd2658f I documented why we're using a non-standard approach to disabling the button, and also changed onClick behaviors to account for the disabled effect. I wasn't able to recreate it, but I worried that if the button still had focus when disabled, even if we prohibit pointer events, keyboard action could still occur.

@youknowriad youknowriad merged commit d3c4425 into master May 12, 2017
@youknowriad youknowriad deleted the fix/deselect-block branch May 12, 2017 13:08
@afercia afercia mentioned this pull request Sep 26, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deselecting blocks doesn't work in some circumstances Set focus on link box when button clicked
4 participants