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

Accept React attributes on custom components #11217

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/renderers/dom/fiber/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ function setInitialDOMProperties(
ensureListeningTo(rootContainerElement, propKey);
}
} else if (isCustomComponentTag) {
/* Suggested fix?
*
* if ((DOMProperty.getPropertyInfo(propKey))) {
* DOMPropertyOperations.setValueForProperty(domElement, propKey, nextProp);
* } else {
* DOMPropertyOperations.setValueForAttribute(domElement, propKey, nextProp);
* }
*/
DOMPropertyOperations.setValueForAttribute(domElement, propKey, nextProp);
} else if (nextProp != null) {
// If we're updating to null or undefined, we should remove the property
Expand Down
12 changes: 12 additions & 0 deletions src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ describe('DOMPropertyOperations', () => {
ReactDOM.render(<div hidden={false} />, container);
expect(container.firstChild.hasAttribute('hidden')).toBe(false);
});

it('should set the className to a custom component', () => {
var container = document.createElement('div');
ReactDOM.render(<amp className="just-a-class" />, container);
expect(container.firstChild.getAttribute('class')).toEqual('just-a-class');
});

it('should set the className to a custom component with a dash on its name', () => {
var container = document.createElement('div');
ReactDOM.render(<amp-img className="just-a-class" />, container);
expect(container.firstChild.getAttribute('class')).toEqual('just-a-class');
});
});

describe('value mutation method', function() {
Expand Down