-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Accessibility: Add disposable focus Higher Order Component #901
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
Conversation
|
Thanks for working on this. I'm not entirely convinced how to test this exactly, so would appreciate @afercia's eyes as well. The inserter seems to be working well (outside of that focus rectangle which is my fault, and for which I'm opening a separate ticket for soon). Codewise, I like all the red I see this clearing up! |
|
Looks very promising to me, as it's a simple way to get an UI control to return focus to later. Tested on both the Inserter and Sidebar, and focus is correctly moved back to the related buttons. About the Sidebar for example, it solves the focus loss pointed out in #895 I'd like to see this as the first tool of a more complete "focus management" set of tools. Just one thing, I'd consider to don't use a Not sure about the naming 🙂 maybe |
Unfortunately, it's not possible to avoid a wrapper here. The wrapper tagName could be made customizable though (if we need to). We need a wrapper to get a reference to the dom node. |
|
Actually, I was able to drop the wrapper in 74f0dc8 |
|
Sorry, just noticed a drawback: when clicking using the mouse, The previous method used for the inserter worked also when clicking with the mouse, because it was using the click event current target. It would be great to find a way to make this work both with mouse and keyboard! |
|
@afercia Good catch! I found that this happening because when we click on the "Insert" Button for example, the focus is not being moved to the button in Firefox and Safari while it's done in Chrome. I can't find yet why the focus is not moved to buttons when clicking on them. |
|
I found this link showing these differences. thinking how can we make this work the Chrome way everywhere https://gist.github.com/cvrebert/68659d0333a578d75372 |
| } | ||
|
|
||
| componentWillUnmount() { | ||
| const wrapper = findDOMNode( this ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findDOMNode is documented as an escape hatch, though in this case I think a reasonable one. Concerns me to see some conversation in which React maintainers appear inclined to put it on a path toward deprecation.
I noted the earlier point about wrapper components. I think we should keep this as-is, but leave open as options for future consideration:
- Wrap with
spanto reduce layout implications (inline, not block) - Expect the mounted component to define a node getter (similar to
react-click-outside'shandleClickOutside) - Pass callback as prop to the wrapped component, expected to be called on mount with reference to the DOM node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of providing a config object as a parameter to the HoC as an alternative.
disposableFocus({ wrapper: 'span' })(Component)
| @@ -0,0 +1,32 @@ | |||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: Folder placement. This is technically not a component, but rather a function which returns a modified component. Dunno if or how we'd want to distinguish this.
| } | ||
|
|
||
| toggle( event ) { | ||
| // When opening the menu, track reference to the current active element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some of the inline documentation could be adapted for use in the new higher-order variant.
Just tested Firefox on Windows and Ideally, I think it would make sense to try to pair this behaviour across platforms/browsers. |
|
Tested also in: |
|
I'm thinking we should merge this. And try (or not) to fix the browser issue separately. The fact that this issue breaks the |
|
@youknowriad What do we want to do about these review points? |
|
@aduth Oh sorry, I forgot about the documentation comment. About the |
|
Misbehaving hashbang behavior I think 😄 Was referring to the folder placement remark, not |
|
@aduth 😅 I need a good long weekend :P For the placement, I don't know, I'm open to suggestions. I put it in "components" to make it reusable across other WordPress modules (outside Editor/Blocks), maybe we can create a subfolder |
|
Yeah, I don't really have a great answer. It's not a true component, but I don't necessarily want another top-level directory for these functions. I think they're related to components and in that way could belong in the components directory, but I find the |
|
Let's move it to the Also, thinking we should add a |
Yep, this is needed too for exposing components on the global. I was wondering if there might be a way to automate it, so we can avoid this kind of scenario. |
Maybe something about focus being remembered or returned? |
| @@ -0,0 +1,41 @@ | |||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about utilities instead of higher-order? Alternatively, we can just keep them in the root. cc @aduth @youknowriad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a preference here, happy to update to what we'll settle on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find "utilities" to be a meaningless word.
|
Why is this component named |
|
@nylen to make the distinction that it's not a component, it's a component factory. It can't be used like this |
closes #895
This PR adds a generic
disposableFocushigher order component.A component wrapped in the "disposableFocus" hoc will have the following behaviour:
All disposable elements should be wrapped within this HoC: Thinking of inserter, sidebar...