Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Search): prevent blur event when SearchResult is clicked #3456

Merged

Conversation

jongsue
Copy link
Contributor

@jongsue jongsue commented Feb 22, 2019

fixes #3298

I couldn't write the test code.

If you know how to do it, please let me know
thanks in advance

@codecov-io
Copy link

codecov-io commented Feb 22, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@abba96b). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3456   +/-   ##
=========================================
  Coverage          ?   99.89%           
=========================================
  Files             ?      172           
  Lines             ?     2796           
  Branches          ?        0           
=========================================
  Hits              ?     2793           
  Misses            ?        3           
  Partials          ?        0
Impacted Files Coverage Δ
src/modules/Search/Search.js 99.46% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abba96b...8bb1ce6. Read the comment docs.

@@ -552,6 +552,7 @@ export default class Search extends Component {
key={childKey || result.title}
active={selectedIndex === offsetIndex}
onClick={this.handleItemClick}
onMouseDown={e => e.preventDefault()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please move this code to a separate class method and place it under handleItemClick:
  handleItemMouseDown = (e) => {
    debug('handleItemMouseDown()')
    // We should prevent default to prevent blur events.
    // https://github.com/Semantic-Org/Semantic-UI-React/issues/3298
    e.preventDefault()
  }
  1. As we there, let's use _.invoke():
  handleFocus = (e) => {
    debug('handleFocus()')

    _.invoke(this.props, 'onFocus', e, this.props)
    this.setState({ focus: true })
  }

  handleBlur = (e) => {
    debug('handleBlur()')

    _.invoke(this.props, 'onBlur', e, this.props)
    this.setState({ focus: false })
  }
- onMouseDown={e => e.preventDefault()}
+ onMouseDown={this.handleItemMouseDown}
  1. About a new unit test, we want to assert that onBlur will not happen on the item selection, we can test this:
    it('is not called on an item click', () => {
      const onBlur = sandbox.spy()
      wrapperMount(<Search results={options} onBlur={onBlur} />)

      openSearchResults()
      wrapper.find('SearchResult').at('0').simulate('click', nativeEvent)
      onBlur.should.have.not.been.called()
    })

Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs some changes, thanks for taking this 👍

@layershifter
Copy link
Member

Applied changes to get this fix 👍

@layershifter layershifter merged commit c7e245f into Semantic-Org:master Feb 27, 2019
@levithomason
Copy link
Member

Released in semantic-ui-react@0.86.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search: does not trigger onResultSelect if custom open prop is supplied
4 participants