-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ffe-datepicker-react): innerRef was not set
- Loading branch information
Peter Hellstrand
committed
Mar 4, 2024
1 parent
fc3a258
commit 5c2e9fb
Showing
2 changed files
with
36 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,52 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import { bool, func, oneOfType, string, shape, oneOf } from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import i18n from '../i18n/i18n'; | ||
|
||
export default class Input extends Component { | ||
focus() { | ||
this._input.focus(); | ||
} | ||
const Input = React.forwardRef((props, ref) => { | ||
const { | ||
ariaInvalid, | ||
inputProps = {}, | ||
onBlur, | ||
onChange, | ||
onKeyDown, | ||
value, | ||
className, | ||
language = 'nb', | ||
} = props; | ||
|
||
inputClassNames(extraClassNames) { | ||
return classNames( | ||
'ffe-input-field ffe-dateinput__field', | ||
extraClassNames, | ||
); | ||
} | ||
|
||
render() { | ||
const { | ||
ariaInvalid, | ||
inputProps = {}, | ||
onBlur, | ||
onChange, | ||
onKeyDown, | ||
value, | ||
language = 'nb', | ||
} = this.props; | ||
|
||
return ( | ||
<input | ||
aria-invalid={String(this.props['aria-invalid'] || ariaInvalid)} | ||
maxLength="10" | ||
onBlur={onBlur} | ||
onChange={onChange} | ||
onKeyDown={onKeyDown} | ||
ref={c => { | ||
this._input = c; | ||
}} | ||
aria-placeholder={i18n[language].DATE_FORMAT} | ||
value={value} | ||
{...inputProps} | ||
className={this.inputClassNames(inputProps.className)} | ||
/> | ||
); | ||
} | ||
} | ||
return ( | ||
<input | ||
aria-invalid={String(props['aria-invalid'] || ariaInvalid)} | ||
maxLength="10" | ||
onBlur={onBlur} | ||
onChange={onChange} | ||
onKeyDown={onKeyDown} | ||
ref={ref} | ||
aria-placeholder={i18n[language].DATE_FORMAT} | ||
value={value} | ||
{...inputProps} | ||
className={classNames( | ||
'ffe-input-field ffe-dateinput__field', | ||
className, | ||
)} | ||
/> | ||
); | ||
}); | ||
|
||
Input.propTypes = { | ||
'aria-invalid': string, | ||
ariaInvalid: oneOfType([bool, string]), | ||
inputProps: shape({ | ||
className: string, | ||
}), | ||
className: string, | ||
onBlur: func, | ||
onChange: func.isRequired, | ||
onKeyDown: func, | ||
value: string.isRequired, | ||
fullWidth: bool, | ||
language: oneOf(['nb', 'nn', 'en']), | ||
}; | ||
|
||
export default Input; |