boblauer / react-onclickout

An ES6-friendly on-click-outside React component.
MIT License
92 stars 14 forks source link

If a click triggered the creation of the react-onclickout component, onClickOut immediately fires #4

Closed grassick closed 8 years ago

grassick commented 8 years ago

If a click in the UI was what caused the clickout component to be rendered, it immediately fires.

Simple example:

class SelectExprComponent extends React.Component
  constructor: ->
    super
    @state = { active: false }

  handleActivate: =>
    @setState(active: true)

  handleDeactivate: =>
    @setState(active: false)

  render: ->
    if @state.active
      R ClickOutHandler, onClickOut: @handleDeactivate,
        H.input type: "text", initialValue: ""
    else
      H.a onClick: @handleActivate, "Select..."      

Will immediately flip back to inactive state because click that happened before ClickOutHandler was created is still propagating up to the window.

I have a pull request for this that I'll put up shortly.