Skip to content

Commit

Permalink
feat: send along #input rest parameters to input element
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 20, 2019
1 parent c2a26c7 commit 8e0f798
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions packages/dnb-ui-lib/src/components/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const propTypes = {
class: PropTypes.string,
input_class: PropTypes.string,
attributes: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
wrapper_attributes: PropTypes.object,

// Submit button
submit_button_icon: PropTypes.oneOfType([
Expand Down Expand Up @@ -89,6 +90,7 @@ export const defaultProps = {
input_class: null,
class: null,
attributes: null,
wrapper_attributes: null,

// Submit button
submit_button_title: null,
Expand Down Expand Up @@ -213,13 +215,20 @@ export default class Input extends PureComponent {
input_class,
submit_button_title,
submit_button_icon,
on_submit
on_submit,
autocomplete,
class: _className,
className,

id: _id /* eslint-disable-line */,
children /* eslint-disable-line */,
value /* eslint-disable-line */,

wrapper_attributes,

...attributes
} = this.props

let { autocomplete } = this.props
if (type === 'search') {
autocomplete = null
}
const id = this._id

const classes = classnames(
Expand All @@ -228,8 +237,8 @@ export default class Input extends PureComponent {
size ? 'dnb-input--' + size : '',
align ? `dnb-input__align--${align}` : null,
status ? `dnb-input__status--${status_state}` : null,
this.props.class,
this.props.className
_className,
className
)

const { inputElement: Elem, ...renderProps } = this.renderProps
Expand All @@ -241,13 +250,13 @@ export default class Input extends PureComponent {
value: this.state.value || '',
type,
id,
// align,
disabled,
name: id,
onChange: this.onChangeHandler,
onKeyDown: this.onKeyDownHandler,
onFocus: this.onFocusHandler,
onBlur: this.onBlurHandler
onBlur: this.onBlurHandler,
...attributes
}

// also used for code markup simulation
Expand All @@ -256,11 +265,18 @@ export default class Input extends PureComponent {
if (description) {
inputParams['aria-describedby'] = id + '-description'
}
if (type === 'search') {
inputParams.autoComplete = 'off'
}

const shellParams = {
'data-input-state': this.state.inputState,
'data-has-content':
String(this.state.value || '').length > 0 ? 'true' : 'false'
String(this.state.value || '').length > 0 ? 'true' : 'false',
...wrapper_attributes
}
if (wrapper_attributes && typeof wrapper_attributes === 'object') {
Object.assign(shellParams, wrapper_attributes)
}

return (
Expand Down

0 comments on commit 8e0f798

Please sign in to comment.