-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3820 from ivanko22/searchBox2024
update SearchBar into SearchBar2024
- Loading branch information
Showing
8 changed files
with
231 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
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
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { Component } from 'react'; | ||
import { blurTextFieldAndroid, focusTextFieldAndroid } from '../../common/utils/cordovaUtils'; | ||
import { renderLog } from '../../common/utils/logging'; | ||
import BaseSearchbox from './BaseSearchbox'; | ||
|
||
/* eslint-disable jsx-a11y/control-has-associated-label */ | ||
export default class SearchBar2024 extends Component { | ||
constructor (props) { | ||
super(props); | ||
|
||
this.state = { | ||
searchString: '', | ||
}; | ||
|
||
this.handleKeyPress = this.handleKeyPress.bind(this); | ||
this.updateResults = this.updateResults.bind(this); | ||
this.clearQuery = this.clearQuery.bind(this); | ||
} | ||
|
||
componentDidMount () { | ||
if (this.props.clearSearchTextNow) { | ||
if (this.props.clearFunction) { | ||
this.props.clearFunction(); | ||
} | ||
const { searchString } = this.state; | ||
if (searchString) { | ||
this.setState({ | ||
searchString: '', | ||
}); | ||
} | ||
} | ||
} | ||
|
||
componentDidUpdate (prevProps) { | ||
if (this.props.clearSearchTextNow !== prevProps.clearSearchTextNow) { | ||
if (this.props.clearSearchTextNow) { | ||
if (this.props.clearFunction) { | ||
this.props.clearFunction(); | ||
} | ||
const { searchString } = this.state; | ||
if (searchString) { | ||
this.setState({ | ||
searchString: '', | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
componentWillUnmount () { | ||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
this.timer = null; | ||
} | ||
} | ||
|
||
handleKeyPress () { | ||
if (this.timer) clearTimeout(this.timer); | ||
this.timer = setTimeout(() => { | ||
this.props.searchFunction(this.state.searchString); | ||
}, this.props.searchUpdateDelayTime); | ||
} | ||
|
||
clearQuery () { | ||
this.props.clearFunction(); | ||
this.setState({ searchString: '' }); | ||
} | ||
|
||
updateResults (event) { | ||
const searchString = event.target.value; | ||
this.setState({ | ||
searchString, | ||
}); | ||
} | ||
|
||
// check limit of 50 characters | ||
render () { | ||
renderLog('SearchBar2024'); // Set LOG_RENDER_EVENTS to log all renders | ||
const { placeholder } = this.props; | ||
const { searchString } = this.state; | ||
return ( | ||
<div className="search-bar clearfix"> | ||
<BaseSearchbox | ||
id="search_input" | ||
placeholder={placeholder} | ||
value={searchString} | ||
onKeyDown={this.handleKeyPress} | ||
onChange={this.updateResults} | ||
onFocus={() => focusTextFieldAndroid('SearchBar2024')} | ||
onBlur={blurTextFieldAndroid} | ||
onClear={this.clearQuery} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
SearchBar2024.propTypes = { | ||
clearButton: PropTypes.bool, | ||
clearFunction: PropTypes.func.isRequired, | ||
clearSearchTextNow: PropTypes.bool, | ||
placeholder: PropTypes.string, | ||
searchButton: PropTypes.bool, | ||
searchFunction: PropTypes.func.isRequired, | ||
searchUpdateDelayTime: PropTypes.number.isRequired, | ||
}; |
Oops, something went wrong.