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

fix: reposition children when position changed #1033

Merged
merged 11 commits into from
Dec 30, 2021
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions integration_tests/specs/css/css-position/nonstatic-to-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,57 @@ describe('Position non-static', () => {

await snapshot();
});

it('children should reposition when parent position changed from relative to static', async (done) => {
let div;
let item1;
let item2;
div = createElement(
'div',
{
style: {
position: 'relative',
width: '200px',
height: '100px',
display: 'flex',
flexDirection: 'row',
backgroundColor: 'green',
},
},
[
(item1 = createElement('div', {
style: {
position: 'relative',
margin: '30px',
width: '100px',
height: '50px',
backgroundColor: 'yellow',
}
}, [
createElement('div', {
style: {}
}, [
(item2 = createElement('div', {
style: {
position: 'absolute',
top: 0,
left: 0,
width: '30px',
height: '30px',
backgroundColor: 'red'
}
})),
])
])),
]
);

BODY.appendChild(div);

requestAnimationFrame(async () => {
item1.style.position = 'static';
await snapshot();
done();
});
});
});
52 changes: 52 additions & 0 deletions integration_tests/specs/css/css-position/static-to-nostatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,56 @@ describe('Position static', () => {

await snapshot();
});

it('children should reposition when parent position changed from static to relative', async (done) => {
let div;
let item1;
let item2;
div = createElement(
'div',
{
style: {
position: 'relative',
width: '200px',
height: '100px',
display: 'flex',
flexDirection: 'row',
backgroundColor: 'green',
},
},
[
(item1 = createElement('div', {
style: {
margin: '30px',
width: '100px',
height: '50px',
backgroundColor: 'yellow',
}
}, [
createElement('div', {
style: {}
}, [
(item2 = createElement('div', {
style: {
position: 'absolute',
top: 0,
left: 0,
width: '30px',
height: '30px',
backgroundColor: 'red'
}
})),
])
])),
]
);

BODY.appendChild(div);

requestAnimationFrame(async () => {
item1.style.position = 'relative';
await snapshot();
done();
});
});
});
4 changes: 4 additions & 0 deletions kraken/lib/src/css/style_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ class CSSStyleDeclaration {
for (String propertyName in propertyNames) {
String? prevValue = prevValues[propertyName];
String currentValue = pendingProperties[propertyName]!;

// Return if value has not changed.
if (currentValue == prevValue) return;

_emitPropertyChanged(propertyName, prevValue, currentValue);
}
}
Expand Down
Loading