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 renderPlaceholder #4190

Merged

Conversation

juliankrispel
Copy link
Collaborator

@juliankrispel juliankrispel commented Apr 11, 2021

Description
Adds a renderPlaceholder prop to Editable

Issue
Fixes #4123
Fixes #4018 by removing whitespace: nowrap

Example

<Editable
  renderPlaceholder={props => {
    return (
      <div {...props}>
        <p>Hello there</p>
        <pre>Here's something rendered with renderPlaceholder</pre>
      </div>
    )
  }}
/>

image

Context
If your change is non-trivial, please include a description of how the new logic works, and why you decided to solve it the way you did. (This is incredibly helpful so that reviewers don't have to guess your intentions based on the code, and without it your pull request will likely not be reviewed as quickly.)

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Apr 11, 2021

🦋 Changeset detected

Latest commit: 4344f53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@juliankrispel
Copy link
Collaborator Author

thanks for the review @ianstormtaylor - I addressed your feedback 👍

Copy link
Owner

@ianstormtaylor ianstormtaylor left a comment

Choose a reason for hiding this comment

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

Hey @juliankrispel thanks for the update!

I was just going through to review again, and I think I realized that we're trying to solving a few different problems at once here with the same API, and I'm not sure we're doing it right. For a summary of how I'm thinking about this, we have a few problems we're solving for:

  • For the most common case, a simple placeholder="..." string is needed to mimic the default browser behavior that applies to <textarea> elements. We want this to get the same styling that those placeholders do (namely the opacity).

  • There's another common use case that is changing the rendering logic for when and where placeholders are rendered. This can be when implementing placeholders in the middle of documents (eg. in a caption block for an image), or when wanting to have multiple placeholders (eg. for a heading and body in a forced layout). I think these cases should be left unsolved by the placeholder/renderPlaceholder props, and instead people should use their own custom decorate prop instead for maximum control.

  • A less common but totally valid case is wanting to render more complex components in place of the default global placeholder. But the issue here is that people may or may not want to render them with the same styles as the default, specifically slate-react placeholder unable to change the style #4123 doesn't want the opacity styles. Right now we're forcing those styles, but we could tweak the logic to just use a <DefaultPlaceholder> similar to how we have a <DefaultLeaf>, allowing them to override it with renderPlaceholder.

I added a few comments in line to explain what the changes would be to arrive at that. It's a little complex to understand, but the goal is to make renderPlaceholder a very simple but fully customizable escape hatch that runs in the default code path.

Let me know if you have questions!

packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/leaf.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/leaf.tsx Outdated Show resolved Hide resolved
- separate renderPlaceholder method from placeholder prop
- add custom-placeholder example
@juliankrispel
Copy link
Collaborator Author

juliankrispel commented Apr 15, 2021

thanks for the tight feedback loop @ianstormtaylor much appreciated 🙏

I addressed your feedback but I believe there are still open questions

Also added an example for custom placeholders.

Lmk if there's anything else you'd like me to change. Cheers!

Copy link
Owner

@ianstormtaylor ianstormtaylor left a comment

Choose a reason for hiding this comment

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

Thanks @juliankrispel, this is looking great. I realized you were totally right about mixing in the style attribute, my bad for arguing against that. I put a few more comments in line for refining. I love the idea for the example of the customized placeholder!

packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/leaf.tsx Show resolved Hide resolved
.changeset/few-planets-brush.md Outdated Show resolved Hide resolved
.changeset/few-planets-brush.md Outdated Show resolved Hide resolved
- added attributes prop to default render prop
- make renderPlaceHolder consistent with other props
@juliankrispel
Copy link
Collaborator Author

Thanks @juliankrispel, this is looking great. I realized you were totally right about mixing in the style attribute, my bad for arguing against that. I put a few more comments in line for refining. I love the idea for the example of the customized placeholder!

Thank you for the review @ianstormtaylor, I much appreciate the help!

I've addressed all the feedback in your most recent review, cheers

Copy link
Owner

@ianstormtaylor ianstormtaylor left a comment

Choose a reason for hiding this comment

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

Everything looks great @juliankrispel! Two comments inline and then I'm good to merge.

packages/slate-react/src/components/editable.tsx Outdated Show resolved Hide resolved
packages/slate-react/src/components/leaf.tsx Outdated Show resolved Hide resolved
@juliankrispel
Copy link
Collaborator Author

Everything looks great @juliankrispel! Two comments inline and then I'm good to merge.

thanks, all feedback addressed

@Avizura Avizura mentioned this pull request Apr 23, 2021
5 tasks
@juliankrispel juliankrispel merged commit ea2eefe into ianstormtaylor:main Apr 23, 2021
This was referenced Apr 23, 2021
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.

slate-react placeholder unable to change the style Long placeholder values overflow editor
2 participants