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

Remove 'unkown props' from DOM elements; fixes #16 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions tool/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.bind = bind;
exports.hasCheckedProp = hasCheckedProp;
exports.hasValueProp = hasValueProp;
exports.indexOf = indexOf;
exports.sanitizeProps = sanitizeProps;

/**
* @param {object} context
Expand Down Expand Up @@ -57,3 +58,17 @@ function indexOf(collection, value, prop = 'value') {

return -1;
}

/**
* @see: https://facebook.github.io/react/warnings/unknown-prop.html
*/

function sanitizeProps(exclude = [], props = {}) {
return Object.keys(props).reduce((sanitized, prop) => {
if (!exclude.includes(prop)) {
sanitized[prop] = props[prop];
}

return sanitized;
}, {});
}
15 changes: 14 additions & 1 deletion view/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { Component, PropTypes } = require('react');
const { styleName } = require('../tool/className');
const { sanitizeProps } = require('../tool/component');
const React = require('react');

class Button extends Component {
Expand All @@ -11,9 +12,21 @@ class Button extends Component {
}
}

filter(props) {
let filteredProps = {};

Object.keys(props).forEach(prop => {
if (!Button.illegalDOMProps.includes(prop)) {
filteredProps[prop] = props[prop];
}
});

return filteredProps;
}

render() {
return (
<button {...this.props} className={styleName(this.props)} ref='control'/>
<button {...sanitizeProps(['theme', 'styles', 'styleName'], this.props)} className={styleName(this.props)} ref='control'/>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions view/Check.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind } = require('../tool/component');
const { bind, sanitizeProps } = require('../tool/component');
const { generateId } = require('../tool/identity');
const { noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -50,7 +50,7 @@ class Check extends Component {
return (
<div className={styleName(this.props)}>
<input
{...o}
{...sanitizeProps(['styleName', 'tc'], o)}
className={styles.native}
id={id}
onChange={this.onChange}/>
Expand Down
4 changes: 2 additions & 2 deletions view/CheckGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind, hasValueProp } = require('../tool/component');
const { bind, hasValueProp, sanitizeProps } = require('../tool/component');
const { generateId, hasUniqueValues, mapKey, mapKeyBasedOnPos } = require('../tool/identity');
const { isUndefined, mapRange, noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -77,7 +77,7 @@ class CheckGroup extends Component {
render() {
return (
<div
{...this.props}
{...sanitizeProps(['options', 'styles', 'hasUniqValues', 'styleName'], this.props)}
className={styleName(this.props)}
onChange={undefined}>
{this.renderColumns()}
Expand Down
4 changes: 2 additions & 2 deletions view/ColorPicker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind, hasValueProp } = require('../tool/component');
const { bind, hasValueProp, sanitizeProps } = require('../tool/component');
const { classNames, styleName } = require('../tool/className');
const { isUndefined, noop } = require('../tool/func');
const { isHexBased, normalizeColor, trimHash } = require('../tool/color');
Expand Down Expand Up @@ -122,7 +122,7 @@ class ColorPicker extends Component {
onKeyDown={this.onKeyDown}>
{this.renderPreview()}
<Input
{...o}
{...sanitizeProps(['hasFixedWidth', 'palette'], o)}
className={undefined}
defaultValue={undefined}
id={id}
Expand Down
4 changes: 2 additions & 2 deletions view/Input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind, hasValueProp } = require('../tool/component');
const { bind, hasValueProp, sanitizeProps } = require('../tool/component');
const { isUndefined, noop } = require('../tool/func');
const { style, styleName } = require('../tool/className');
const React = require('react');
Expand Down Expand Up @@ -107,7 +107,7 @@ class Input extends Component {
renderInput() {
return (
<input
{...this.props}
{...sanitizeProps(['styleName', 'styles'], ...this.props)}
className={style(this.props.styles, 'control', {
hasClear: this.state.value,
})}
Expand Down
5 changes: 4 additions & 1 deletion view/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

const { Component, PropTypes } = require('react');
const { styleName } = require('../tool/className');
const { sanitizeProps } = require('../tool/component');
const React = require('react');

class Link extends Component {
render() {
return (
<a {...this.props} className={styleName(this.props)}/>
<a
{...sanitizeProps(['theme', 'styles', 'styleName'], ...this.props)}
className={styleName(this.props)}/>
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion view/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { Component, PropTypes } = require('react');
const { generateId } = require('../tool/identity');
const { sanitizeProps } = require('../tool/component');
const { noop } = require('../tool/func');
const React = require('react');

Expand Down Expand Up @@ -35,7 +36,9 @@ class Overlay extends Component {

render() {
return (
<div {...this.props} ref='overlay'/>
<div
{...sanitizeProps(['calculatePosition', 'onPositionUpdate'], ...this.props)}
ref='overlay'/>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions view/Radio.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind, hasValueProp, indexOf } = require('../tool/component');
const { bind, hasValueProp, indexOf, sanitizeProps } = require('../tool/component');
const { generateId, hasUniqueValues, mapKey, mapKeyBasedOnPos } = require('../tool/identity');
const { isUndefined, noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -73,7 +73,7 @@ class Radio extends Component {
render() {
return (
<div
{...this.props}
{...sanitizeProps(['options', 'styles', 'hasUniqValues', 'styleName'], this.props)}
className={styleName(this.props)}
onChange={undefined}>
{this.renderOptions()}
Expand Down
4 changes: 2 additions & 2 deletions view/RadioButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind } = require('../tool/component');
const { bind, sanitizeProps } = require('../tool/component');
const { generateId } = require('../tool/identity');
const { noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -46,7 +46,7 @@ class RadioButton extends Component {
<span className={styleName(this.props)}>
<input
type='radio'
{...o}
{...sanitizeProps(['tc', 'styleName'], o)}
className={styles.native}
id={id}
onChange={this.onChange}/>
Expand Down
4 changes: 2 additions & 2 deletions view/RadioGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind, hasValueProp, indexOf } = require('../tool/component');
const { bind, hasValueProp, indexOf, sanitizeProps } = require('../tool/component');
const { generateId, hasUniqueValues, mapKey, mapKeyBasedOnPos } = require('../tool/identity');
const { isUndefined, noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -74,7 +74,7 @@ class RadioGroup extends Component {
render() {
return (
<div
{...this.props}
{...sanitizeProps(['options', 'styles', 'hasUniqValues', 'styleName'], this.props)}
className={styleName(this.props)}
onChange={undefined}>
{this.renderOptions()}
Expand Down
5 changes: 4 additions & 1 deletion view/Spin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

const { Component, PropTypes } = require('react');
const { styleName } = require('../tool/className');
const { sanitizeProps } = require('../tool/component');
const React = require('react');

class Spin extends Component {
render() {
return (
<span {...this.props} className={styleName(this.props)}/>
<span
{...sanitizeProps(['styles', 'styleName'], this.props)}
className={styleName(this.props)}/>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions view/Textarea.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind } = require('../tool/component');
const { bind, sanitizeProps } = require('../tool/component');
const { noop } = require('../tool/func');
const { styleName } = require('../tool/className');
const React = require('react');
Expand Down Expand Up @@ -32,7 +32,7 @@ class Textarea extends Component {
render() {
return (
<textarea
{...this.props}
{...sanitizeProps(['styles', 'styleName'], this.props)}
className={styleName(this.props)}
onChange={this.onChange}
ref='control'/>
Expand Down
4 changes: 2 additions & 2 deletions view/Tumbler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Component, PropTypes } = require('react');
const { bind } = require('../tool/component');
const { bind, sanitizeProps } = require('../tool/component');
const { generateId } = require('../tool/identity');
const { noop } = require('../tool/func');
const { styleName } = require('../tool/className');
Expand Down Expand Up @@ -46,7 +46,7 @@ class Tumbler extends Component {
<div className={styleName(this.props)}>
<input
type='checkbox'
{...o}
{...sanitizeProps(['styleName'], o)}
className={styles.native}
id={id}
onChange={this.onChange}/>
Expand Down