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

Support for inner width and height. #102

Open
AnthonyPanchenko opened this issue Dec 5, 2016 · 10 comments
Open

Support for inner width and height. #102

AnthonyPanchenko opened this issue Dec 5, 2016 · 10 comments

Comments

@AnthonyPanchenko
Copy link

It should be possible to track inner width and height.

@ctrlplusb
Copy link
Owner

Hey @nixegend can you please expand upon your requirements here. I am not quite following you. Thanks!

@jcrben
Copy link

jcrben commented Apr 17, 2017

Perhaps he's asking about a height calculation which includes the height of children?

I have an parent component with a height of about 1000px and it contains a child which has a height of 1800px. The parent component is actually https://github.com/STRML/react-grid-layout and these children are absolute, so it seems that I need to calculate the size of the grid and set its height to allow elements to flow after it (see also https://stackoverflow.com/questions/9061520/auto-height-on-parent-container-with-absolute-fixed-children).

Are you familiar with this issue? If not, maybe I can create a small demonstration repo.

@felthy
Copy link
Contributor

felthy commented May 3, 2017

I came here looking for an option to track width without padding, a la box-sizing: content-box - perhaps that’s what @nixegend meant? It's what I want anyway! So in the example below (screenshot from Chrome devtools) I want sizeme to report width: 420, not width: 460.

image

@ctrlplusb
Copy link
Owner

Hey @felthy that makes sense yeah. I don't know the specifics on box-sizing behaviour and the element-resize-detector. Will have to see what options we have to us here.

@felthy
Copy link
Contributor

felthy commented May 3, 2017

Oh sorry the box-sizing thing was not really relevant, I only mentioned it to try and explain which width I meant. element-resize-detector is already working fine for me, but for what I'm doing the width within the padding would be more useful. I've just been reading the code, I see you're using getBoundingClientRect() internally, so we’d probably need to subtract padding or something like that. I’m going to look and see how jQuery does it (in jQuery terms this is the difference between jQuery.outerWidth() and jQuery.width()).

@pinkynrg
Copy link

+1 It would be really nice to have this feature!

@xiechao06
Copy link

+1, I think the SizeMe component's children function could be provided one more argument: the dom element to be measured, using this element it could be easy to get the paddings. namely:

<SizeMe>
  {({ size, el }) => ... }
<SizeMe>

@larrydahooster
Copy link

larrydahooster commented Apr 8, 2020

Need this as well. Is this project still maintained @ctrlplusb ? might work on an implementation of this anyway in near future causeI need it for a project

@ctrlplusb
Copy link
Owner

Yep, still maintained, just haven't need to update it very often as it's quite stable. ☺️

Happy to consider a discussion / PR on the subject. If it doesn't affect performance adversely we can include it.

@larrydahooster
Copy link

larrydahooster commented Apr 14, 2020

Thanks for your reply. I will do some research on it. Regarding performance I think it can cause a second render-cycle. It needs to be ensured that it does not result in a endless loop.

The reason for this is:

  1. You render the parent content with placeholder (no scrollbars)
  2. you render the child content with outer dimeninsions - scrollbars appear,
  3. the parent updates it's dimensions -> old width - scrollbar = new width; old height + newly gained height (because of width reduction turning into height gain) = new heigth.

Haven't thought further through it but whenever the child manipulates the parent, I guess an endless cycle can occure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants