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

CSS styles are applied only after element is revealed #18

Open
joetm opened this issue Mar 25, 2017 · 4 comments
Open

CSS styles are applied only after element is revealed #18

joetm opened this issue Mar 25, 2017 · 4 comments

Comments

@joetm
Copy link

joetm commented Mar 25, 2017

I transition an image into a headline.


class App extends Component {
	constructor() {
		super();
		this.state = {
			loading: true
		};
	}
	componentDidMount() {
		setTimeout(() => {
			this.setState({loading: false});
		}, 2000);
	}
    render() {
	    return (
	      <div className="App">
	        <div className="App-header">
				{this.state.loading && <Overdrive id="content"><img src={logo} className="App-logo" alt="logo" /></Overdrive>}
				{!this.state.loading && <Overdrive id="content"><h2>React-Overdrive Test</h2></Overdrive>}
	        </div>
	      </div>
	    );
    }
}

The basis is the default create-react-app setup: https://github.com/joetm/overdrive-test

What I notice is that the style of the headline is not applied immediately.
I see the headline appear with black text left-aligned. Then it jumps to being center-aligned with white text.

Anything that can be done in this case?

@berzniz
Copy link
Owner

berzniz commented Mar 26, 2017

While the animation takes place, the elements are clones and moved without their wrapping elements. So while it inherits the size & position, it may lose colors, text-alignment that is styled on the parent elements.

I suggest adding the colors and text-align to the element itself (via CSS) (or to the body element).

@mbrookes
Copy link

mbrookes commented Mar 26, 2017

@berzniz Love the concept - this is the first library I've found that could solve the problem of how to achieve complex multi-element transitions such described for Material Design: https://material.io/guidelines/motion/material-motion.html#material-motion-what-makes-a-good-transition

However, passing styling from a parent to child, through props or CSS className is a common pattern, particularly where the child component may be provided by a 3rd party library so can't be styled any other way. (Even within Material-UI we consume and in some cases restyle our own components to build up more complex components.)

This may not be a solvable problem, but just wanted to add some support to the issue.

@berzniz
Copy link
Owner

berzniz commented Mar 27, 2017

@mbrookes - these are some good points.

Since the elements are cloned and attached to the body, they will indeed lose all CSS rules inherited from their parents. Usually frameworks (such as bootstrap) are working on the body level so styles still apply.

There could be a solution to use getComputedStyle on all child elements and capture their styles, but this could be costly (especially for deeply nested DOM trees). I'll try to play with that idea.

@gryzzly
Copy link

gryzzly commented Mar 30, 2017

This could be partly solved by specifying a "root" element to nest the clones under. If the root doesn’t have position applied the absolute positioning should still work, but some CSS cascade would apply.

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

4 participants