Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(factories): reverted changed for not passing props to elements in the factories #759

Merged
merged 9 commits into from
Jan 23, 2019

Conversation

mnajdova
Copy link
Contributor

This PR is reverting some of the changes introduced in #496 regarding not passing props in the factories if the element is a React component, in order to fix #671

{ value: <div {...{ overridden: true } as any} /> },
)
itOverridesDefaultPropsWithFalseyProps('element', {
value: <div {...{ undef: undefined, nil: null, zero: 0, empty: '' } as any} />,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create these superfluous objects and spread them like this? It would be much simpler to just pass the props, if possible:

Suggested change
value: <div {...{ undef: undefined, nil: null, zero: 0, empty: '' } as any} />,
value: <div undef={undefined} nil={null} zero={0} empty='' />,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript is complaining because these props are not valid for div element, that's why we have this object spread. I can create another object and spread it, but it is much easier indeed to read it if it is inline on the element.

Copy link
Member

@levithomason levithomason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one nit comment.

shorthand value, it becomes client's responsibility to handle some aspects that Stardust was
originally responsible for (such as {code('styles')} or {code('accessibility')}).
shorthand value, all props that Stardust has created for the slot's Component will be spread
on the passed element. This means, you may end up with invalid props applied on HTML
Copy link
Contributor

@kuzhelov kuzhelov Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that provided element should be able to handle Stardust props - while this requirement is satisfied for all Stardust components, you should be aware of that when either HTML or any third-party elements are provided.

The reason I would suggest to rephrase original one is elimination of invalid props - in fact, there is nothing invalid in props provided, it is just about element may be not aware of necessity to handle them.

Copy link
Contributor Author

@mnajdova mnajdova Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of this, maybe using the <i /> is not the best example? Should we consider using another Stardust component, like for example?

@mnajdova mnajdova merged commit e5052b8 into master Jan 23, 2019
@layershifter layershifter deleted the fix/factories-pass-props-to-elements branch January 23, 2019 14:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a component slot with .create function will not apply styles
3 participants