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

Replace children #3

Merged
merged 2 commits into from
Oct 2, 2016
Merged

Replace children #3

merged 2 commits into from
Oct 2, 2016

Conversation

aknuds1
Copy link
Owner

@aknuds1 aknuds1 commented Sep 30, 2016

Fixes #2.

From Jason English:

Hi, I would like to propose the ability to replace all children of an element with a given React component.

Problem

Given this HTML template

<div class="row">
    <div class="col-sm-6">
        <div data-container="wysiwyg">
            <h1>Sample Heading</h1>
            <p>Sample Text</p>
        </div>
    </div>
</div>

I would like to

  • a) Preserve the data-container element.
  • b) Replace the inner html of data-container with my custom React component.

The current solution is to check the child node's parent. This breaks down as soon as you start having multiple children

Solution

Given a Processing Instruction, you can now set a new property called {boolean} replaceChildren.

This property will tell the parser to add the returned component from processNode as a child of the created React element. The template shown above would become:

<div class="row">
    <div class="col-sm-6">
        <div data-container="wysiwyg">
            <RichTextEditor html={"<h1>Sample heading</h1><p>Sample Text</p>"} />
        </div>
    </div>
</div>

We would love to hear thoughts on this.

@aknuds1 aknuds1 force-pushed the replace_children branch 2 times, most recently from 39a0186 to 48bc04b Compare September 30, 2016 13:30
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 48bc04b on replace_children into 859415b on master.

1 similar comment
@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 48bc04b on replace_children into 859415b on master.

@coveralls
Copy link

coveralls commented Oct 2, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling c0b5fd4 on replace_children into 859415b on master.

@aknuds1 aknuds1 merged commit 457c65e into master Oct 2, 2016
@aknuds1 aknuds1 deleted the replace_children branch October 2, 2016 07:36
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.

None yet

3 participants