Skip to content

Commit

Permalink
fix(): Removes relative styling on temporary div instance.
Browse files Browse the repository at this point in the history
The "position: relative" style that was being applied to the temporary div used to get the first
size was affecting components that were being wrapped and which were using "position: absolute" on
one of their children. Fixes #20
  • Loading branch information
ctrlplusb committed Jul 25, 2016
1 parent 0cb3d8f commit 3ad5a57
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion example/src/MySizeAwareComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ const spanStyle = {
transform: `translateX(-50%) translateY(-50%)`
};

function MyComponent({ size: { width, height }, style }) {
function MyComponent({ children, size: { width, height }, style }) {
return (
<div style={Object.assign({}, rootStyle, style)}>
<span style={spanStyle}>
{Math.round(width)}x{Math.round(height)}<br />
<span style={{ fontWeight: `normal`, fontStyle: `italic` }}>(rounded)</span>
</span>
{children}
</div>
);
}

MyComponent.propTypes = {
children: PropTypes.node,
size: PropTypes.shape({
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
Expand Down
7 changes: 5 additions & 2 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ function App() {

<div style={{ float: `left`, width: `40%` }}>
<MySizeAwareComponent
style={{ height: `250px`, backgroundColor: `rgb(29, 165, 154)` }}
/>
style={{ height: `250px`, backgroundColor: `rgb(29, 165, 154)`, position: `relative` }}
>
<MySizeAwareComponent
style={{ height: `50px`, backgroundColor: `rgb(88, 164, 29)`, position: `absolute`, bottom: 0, left: 0, width: `100%` }} />
</MySizeAwareComponent>
<MySizeAwareComponent
style={{ height: `250px`, backgroundColor: `rgb(252, 181, 193)` }}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/SizeMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Placeholder({ className, style }) {
// container take the full available space.
if (!className && !style) {
phProps.style = {
width: `100%`, height: `100%`, position: `relative`
width: `100%`, height: `100%`
};
} else {
if (className) {
Expand Down
6 changes: 3 additions & 3 deletions test/SizeMe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React from 'react';
import { expect } from 'chai';
import { describeWithDOM } from './jsdom';
import sinon from 'sinon';
import { mount, shallow } from 'enzyme';
import { renderToString } from 'react-dom/server'
import { mount } from 'enzyme';
import { renderToString } from 'react-dom/server';

const html = `
<!doctype html>
Expand All @@ -28,7 +28,7 @@ describeWithDOM(`Given the SizeMe library`, () => {
let SizeMe;
let SizeMeRewireAPI;
let resizeDetectorMock;
const placeholderHtml = `<div style="width: 100%; height: 100%; position: relative;"></div>`;
const placeholderHtml = `<div style="width: 100%; height: 100%;"></div>`;

beforeEach(() => {
SizeMe = require(`../src/index.js`).default;
Expand Down

0 comments on commit 3ad5a57

Please sign in to comment.