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

Use of <div> fails validateDOMNesting check in certain elements #48

Closed
exogen opened this issue Oct 6, 2018 · 4 comments
Closed

Use of <div> fails validateDOMNesting check in certain elements #48

exogen opened this issue Oct 6, 2018 · 4 comments

Comments

@exogen
Copy link

exogen commented Oct 6, 2018

(xposting to react-size-observer as it's an issue there as well ☹️)

Apologies if someone has brought this up before. I've tried both react-resize-detector and react-resize-observer, and I'm using them in a way where I need it to live inside elements like <p> and <span> sometimes.

But React complains about this since it's against the HTML spec:

index.js:2178 Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.

It seems like the same functionality could be done with span as long as it's set to display: block. AFAIK spans are valid everywhere. Would it be worthwhile to switch?

@maslianok
Copy link
Owner

Hi @exogen ,

Thanks for this suggestion.
To be honest I'm afraid that this change will break something :)

I suggest to test it a bit before push a new release to npm. Can you maybe fork the repo, make this change and test it in your app?
You need to change 1 line of code in src/index.js
screen shot 2018-11-13 at 3 10 31 pm

wdyt?

@ai212983
Copy link

I'd suggested to make this configurable, because spans are NOT valid everywhere (try to put them into 'table', for example)

@maslianok
Copy link
Owner

hmmm...
We can use React.createElement feature to create a configurable react element. Instead of using a hardcoded div element.

And we can pass the node type as a prop, right?

It will look like this

<ReactResizeDetector nodeType="tr" ... />
// or
<ReactResizeDetector nodeType="span" ... />

I think it may work. Thanks for the idea, @ai212983 !
Can someone make a PR on this?

@maslianok
Copy link
Owner

Thanks everyone for discussion and ideas.

Deployed in v3.4.0.

Use nodeType prop to change the node's type. div by default.

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

No branches or pull requests

3 participants