Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Add n_blur/n_submit to Input.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Oct 12, 2018
1 parent d004b29 commit 9f023b9
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/components/Input.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export default class Input extends Component {
if (fireEvent) {
fireEvent({event: 'blur'});
}
if (setProps) {
setProps({
n_blur: this.props.n_blur + 1,
n_blur_timestamp: new Date(),
});
}
}}
onKeyUp={e => {
if (setProps && e.key === 'Enter') {
setProps({
n_submit: this.props.n_submit + 1,
n_submit_timestamp: new Date(),
});
}
}}
value={value}
{...omit(['fireEvent', 'setProps', 'value'], this.props)}
Expand All @@ -49,6 +63,13 @@ export default class Input extends Component {
}
}

Input.defaultProps = {
n_blur: 0,
n_blur_timestamp: -1,
n_submit: 0,
n_submit_timestamp: -1,
};

Input.propTypes = {
/**
* The ID of this component, used to identify dash components
Expand Down Expand Up @@ -76,7 +97,7 @@ Input.propTypes = {
* The type of control to render.
*/
type: PropTypes.oneOf([
// Only allowing the input types with wide browser compatability
// Only allowing the input types with wide browser compatibility
'text',
'number',
'password',
Expand Down Expand Up @@ -250,6 +271,24 @@ Input.propTypes = {
*/
step: PropTypes.string,

/**
* Number of times the `Enter` key was pressed while the input had focus.
*/
n_submit: PropTypes.number,
/**
* Last time that `Enter` was pressed.
*/
n_submit_timestamp: PropTypes.number,

/**
* Number of times the input lost focus.
*/
n_blur: PropTypes.number,
/**
* Last time the input lost focus.
*/
n_blur_timestamp: PropTypes.number,

/**
* Dash-assigned callback that gets fired when the input changes.
*/
Expand Down

0 comments on commit 9f023b9

Please sign in to comment.