Skip to content

Commit cc3d80d

Browse files
fix(UIView): Pass style prop through even if no className is specified
- Also refactor style props handling to render function
1 parent 07a03bf commit cc3d80d

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/components/UIView.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,21 @@ export class UIView extends Component<UIViewProps, UIViewState> {
171171
};
172172
}
173173

174+
// attach any style or className to the rendered component
175+
// specified on the UIView itself
176+
const { className, style } = this.props;
177+
const styleProps = { className, style };
178+
const childProps = { ...props, ...styleProps };
179+
174180
let child =
175181
!loaded && isValidElement(children)
176-
? cloneElement(children, props)
177-
: createElement(component, props);
182+
? cloneElement(children, childProps)
183+
: createElement(component, childProps);
178184

179185
// if a render function is passed use that,
180186
// otherwise render the component normally
181187
return typeof render !== 'undefined' && loaded
182-
? render(component, props)
188+
? render(component, childProps)
183189
: child;
184190
}
185191

@@ -262,19 +268,10 @@ export class UIView extends Component<UIViewProps, UIViewState> {
262268
this.uiViewData.config = newConfig;
263269
let props = { ...resolves, transition: trans };
264270

265-
// attach any style or className to the rendered component
266-
// specified on the UIView itself
267-
let styleProps: {
268-
className?: string;
269-
style?: Object;
270-
} = {};
271-
if (this.props.className) styleProps.className = this.props.className;
272-
if (this.props.className) styleProps.style = this.props.style;
273-
274271
this.setState({
275272
component: newComponent || 'div',
276-
props: newComponent ? extend(props, styleProps) : styleProps,
277-
loaded: newComponent ? true : false,
273+
props: newComponent ? props : {},
274+
loaded: !!newComponent,
278275
});
279276
}
280277

0 commit comments

Comments
 (0)