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 filter dom props function to prevent react warnings #30

Merged
merged 1 commit into from
Aug 12, 2016
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
lib
!src/lib
demo
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@
"tape": "^4.4.0",
"tape-catch": "^1.0.4",
"testdouble": "^1.2.0"
},
"dependencies": {
"html-attributes": "1.1.0"
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from "react";
import filterDOMProps from "./lib/filter-dom-props";

export default class ReactImageFallback extends Component {
constructor(props) {
Expand Down Expand Up @@ -48,7 +49,8 @@ export default class ReactImageFallback extends Component {
}

render() {
return this.state.imageSource ? <img {...this.props} src={this.state.imageSource} /> : null;
const domProps = filterDOMProps(this.props);
return this.state.imageSource ? <img {...domProps} src={this.state.imageSource} /> : null;
}
}
ReactImageFallback.displayName = "ReactImageFallback";
Expand Down
63 changes: 63 additions & 0 deletions src/lib/filter-dom-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import htmlAttributes from "html-attributes";

const eventProps = {
onCopy: true,
onCut: true,
onPaste: true,
onLoad: true,
onError: true,
onWheel: true,
onScroll: true,
onCompositionEnd: true,
onCompositionStart: true,
onCompositionUpdate: true,
onKeyDown: true,
onKeyPress: true,
onKeyUp: true,
onFocus: true,
onBlur: true,
onChange: true,
onInput: true,
onSubmit: true,
onClick: true,
onContextMenu: true,
onDoubleClick: true,
onDrag: true,
onDragEnd: true,
onDragEnter: true,
onDragExit: true,
onDragLeave: true,
onDragOver: true,
onDragStart: true,
onDrop: true,
onMouseDown: true,
onMouseEnter: true,
onMouseLeave: true,
onMouseMove: true,
onMouseOut: true,
onMouseOver: true,
onMouseUp: true,
onSelect: true,
onTouchCancel: true,
onTouchEnd: true,
onTouchMove: true,
onTouchStart: true,
onAnimationStart: true,
onAnimationEnd: true,
onAnimationIteration: true,
onTransitionEnd: true
};

function isValidDOMProp(prop) {
return eventProps[prop] || htmlAttributes[prop];
}

export default function filterDOMProps(props) {
let domProps = {};
for (let prop in props) {
if (props.hasOwnProperty(prop) && isValidDOMProp(prop)) {
domProps[prop] = props[prop];
}
}
return domProps;
}