-
Notifications
You must be signed in to change notification settings - Fork 160
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
Avoid the FocusTrap wrapping div by default #40
Conversation
6aa5b3e
to
c5b77d7
Compare
I agree there should be no need to render an extra wrapping
Note the HoC api might (subjectively) achieve this much more elegantly (again would still need to forward the mentioned props). |
c5b77d7
to
63131e4
Compare
Thanks for the feedback. I understand, I have changed the PR so that the The API change is that the |
9b80985
to
43eec23
Compare
This changes the API so that by default the FocusTrap doesn't wrap the children and therefore there must only be a single child element under HotKeys. In such a case there is no tabIndex manipulation unless used explicitly. In order to wrap the contents one needs to explicitly define the component property as follows: <HotKeys> <p>This is NOT going to get wrapped with a div</p> </HotKeys> <HotKeys component="div"> <p>This is going to get wrapped around with a div</p> </HotKeys>
43eec23
to
dec5d3d
Compare
I'm looking at integrating this package into my project, but this issue is a major pain point. Is there any reason not to merge this PR and generate a new release? |
@@ -11,22 +13,52 @@ const FocusTrap = React.createClass({ | |||
|
|||
getDefaultProps() { | |||
return { | |||
component: 'div' | |||
component: DOCUMENT_FRAGMENT |
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.
is "documentFragment"
a new React thing? Not familiar.
|
||
const child = React.Children.only(children); | ||
if (child.onBlur) { | ||
child.onBlur(...args); |
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.
Calling methods on children is a bit anti-react as it breaks the direction of data.
I'm gonna spend a little time on #24 tomorrow at work (finally) and I'll incorporate the work here. Can sync post that investigation but hopefully I'll have something finished and released this weekend. Serious apologies for the lack of activity around here! |
Can I raise a hand and ask for this? We really need |
Meanwhile, I am trying to get by using
but that doesn't avoid wrapping the children, as the code in this PR had led me to hope; it just means they get wrapped in a Is that expected? |
It is good that somebody took the responsibility for the lib maintenance. It is also good to note that there should be no need for wrapping anymore with React v16. |
The onFocus/onBlur handling is delegated to the only HotKeys child element which gets elementClone()d in the render method.
Fixes #23