Skip to content

Commit

Permalink
search bar: fix focus vs click bug and inactive button
Browse files Browse the repository at this point in the history
  • Loading branch information
jennur authored and zzacharo committed Sep 13, 2023
1 parent 125d2a6 commit bb72ca0
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class MultipleOptionsSearchBar extends Component {
this.setState({ queryString: value });
};

handleFocus = (e) => {
e.persist();
if(e.target.nodeName === "BUTTON") this.handleOnSearchClick();
}

render() {
const { placeholder, options } = this.props;
const { queryString } = this.state;
Expand All @@ -74,6 +79,7 @@ export class MultipleOptionsSearchBar extends Component {
onResultSelect={this.handleOnResultSelect}
onSearchChange={this.handleOnSearchChange}
resultRenderer={(props) => resultRenderer(props, queryString)}
onFocus={this.handleFocus}
results={options}
value={queryString}
placeholder={placeholder}
Expand Down Expand Up @@ -108,11 +114,11 @@ MultipleOptionsSearchBar.defaultProps = {
export class MultipleOptionsSearchBarCmp extends Component {
/** Multiple options searchbar to be wrapped with RSK context
*/
onBtnSearchClick = (e, { result }) => {
onBtnSearchClick = (e, data) => {
const { result } = data || {};
const { queryString, updateQueryState, currentQueryState } = this.props;
const { defaultOption } = this.props;
const { value: url } = result;
const destinationURL = url || defaultOption.value;
const destinationURL = result?.value || defaultOption.value;

if (window.location.pathname === destinationURL) {
updateQueryState({ ...currentQueryState, queryString });
Expand All @@ -126,6 +132,11 @@ export class MultipleOptionsSearchBarCmp extends Component {
onInputChange(value);
};

handleFocus = (e) => {
e.persist();
if(e.target.nodeName === "BUTTON") this.onBtnSearchClick();
}

render() {
const { placeholder, queryString, options } = this.props;
const button = (
Expand All @@ -145,6 +156,7 @@ export class MultipleOptionsSearchBarCmp extends Component {
onResultSelect={this.onBtnSearchClick}
onSearchChange={this.handleOnSearchChange}
resultRenderer={(props) => resultRenderer(props, queryString)}
onFocus={this.handleFocus}
results={options}
value={queryString}
placeholder={placeholder}
Expand Down

0 comments on commit bb72ca0

Please sign in to comment.