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

fix(htmlInputProps): fix handling of falsy values #1746

Merged
merged 1 commit into from
Jun 8, 2017
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
5 changes: 4 additions & 1 deletion src/lib/htmlInputPropsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const partitionHTMLInputProps = (props, htmlProps = htmlInputProps) => {
const inputProps = {}
const rest = {}

_.forEach(props, (val, prop) => _.includes(htmlProps, prop) ? (inputProps[prop] = val) : (rest[prop] = val))
Copy link
Member Author

Choose a reason for hiding this comment

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

Statement _.includes(htmlProps, prop) ? (inputProps[prop] = val) : (rest[prop] = val) will return prop's value, when value will be false the forEach will stop execution.

_.forEach(props, (val, prop) => {
const target = _.includes(htmlProps, prop) ? inputProps : rest
target[prop] = val
})

return [inputProps, rest]
}
6 changes: 3 additions & 3 deletions test/specs/lib/htmlInputPropsUtils-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { partitionHTMLInputProps } from 'src/lib/htmlInputPropsUtils'

const props = {
autoFocus: false,
className: 'foo',
name: 'bar',
placeholder: 'baz',
required: true,
}
Expand All @@ -16,7 +16,7 @@ describe('partitionHTMLInputProps', () => {
const [htmlInputProps, rest] = partitionHTMLInputProps(props)

htmlInputProps.should.deep.equal({
name: 'bar',
autoFocus: false,
placeholder: 'baz',
required: true,
})
Expand All @@ -27,6 +27,6 @@ describe('partitionHTMLInputProps', () => {
const [htmlInputProps, rest] = partitionHTMLInputProps(props, ['placeholder', 'required'])

htmlInputProps.should.deep.equal({ placeholder: 'baz', required: true })
rest.should.deep.equal({ className: 'foo', name: 'bar' })
rest.should.deep.equal({ autoFocus: false, className: 'foo' })
})
})