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

Add second parameter to createSlotFill to define wrapper element for Slot #6920

Conversation

ryanwelcher
Copy link
Contributor

@ryanwelcher ryanwelcher commented May 23, 2018

Description

This PR adds an optional second parameter to createSlotFill that allows control over the element that wraps the children. This fixes #6839 and relates to #6867 and feels like a better approach than one I proposed in #6905

How has this been tested?

I have tested via npm run test and using the following:

const { registerPlugin } = wp.plugins;
const { PluginPostStatusInfo } = wp.editPost;

const PluginRender = () => {
	return (
		<PluginPostStatusInfo>
			<p>Hello!</p>
		</PluginPostStatusInfo>
	);
}
registerPlugin( 'my-plugin-slug', { render: PluginRender } )

I am seeing a React warning that is due to adding a ref to a stateless component which is due to using PanelRow as the wrapper component. I think we can address if this approach is deemed suitable.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@ryanwelcher
Copy link
Contributor Author

cc @gziolo

@youknowriad
Copy link
Contributor

Did you try just replacing the wrapper div with Fragment? I believe the wrapper is necessary in case bubblesVirtually is set to true but maybe we can just remove it in the other case.

return (
<div ref={ this.bindNode }>
<SlotWrap ref={ this.bindNode }>
Copy link
Member

Choose a reason for hiding this comment

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

@aduth - can we use Fragment here and omit ref part?

Copy link
Contributor Author

@ryanwelcher ryanwelcher May 24, 2018

Choose a reason for hiding this comment

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

@gziolo would using Fragment be preferable to passing the component? If so, I can do another PR to that end.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I don't think we want this to be a meaningful node. Currently it's used as the target for rendering portal children.

return createPortal( children, slot.node );

So, we probably need the ref still (since createPortal requires a DOM node target). While I agree #6839 is a problem, I don't think we want developers to be concerned with controlling this wrapper (since, again, it needn't exist as a meaningful node).

Two things we could explore:

  • The bubbleVirtually = false variation of a Fill may not require the wrapper, since it's not using createPortal
    • Though, I'd like to encourage the virtual variation, maybe eventually deprecate bubbleVirtually = false unless this wrapper business becomes too much an issue
  • Assign the portal target node as the parent from which the slot is rendered, and avoid the wrapper node.
    • Maybe assign ref to a temporary node, register slot with temporary node's parent, then remove temporary node?

Copy link
Member

Choose a reason for hiding this comment

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

Should we open an issue based on @aduth's comment and close this one? I don't think the changes proposed in this PR align with how we want to move forward. We definitely want to improve the general experience with Slot & Fill pair and eventually remove the need to wrap Slots with <div />.

Copy link
Member

Choose a reason for hiding this comment

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

See #7231

@gziolo
Copy link
Member

gziolo commented Jun 8, 2018

Closing this one in favor of #7231. I also think I fixed the original issue raised in #6867, but what @aduth proposes will help us to avoid finding tweaks in the future 👍

@gziolo gziolo closed this Jun 8, 2018
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

Successfully merging this pull request may close these issues.

Avoid unstylable <div> elements around Slotfills.
4 participants