Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Input not cleared on blur if auto completion is enabled #61

Closed
amit1911 opened this issue Dec 16, 2016 · 6 comments
Closed

Input not cleared on blur if auto completion is enabled #61

amit1911 opened this issue Dec 16, 2016 · 6 comments
Labels

Comments

@amit1911
Copy link
Contributor

Currently the input is only cleared on blur when the autocomplete menu doesn't exist (given that clearOnBlur is true). I think it would be good to have an option wherein the input is always cleared on blur as otherwise the user needs to manually clear it. We just need to change the handleInputBlur function. The current version is as follows:-

handleInputBlur = (event) => {
    if (!this.autoComplete || !this.autoComplete.refs.menu) {
        if (this.props.clearOnBlur) {
            this.setState({ inputValue: '' })
        }

        this.setState({ isFocused: false })

        if (this.props.onBlur) this.props.onBlur(event)
    }
}

The first line above checks if the autocomplete menu exists. If it exists, then it bypasses the whole blur event handling. Maybe we can have another prop alwaysClearOnBlur so that the input is always cleared though I am not sure why are we not handling the blur event in this case. We can customize the handleInputBlur as follows:-

handleInputBlur = (event) => {
    if (!this.autoComplete || !this.autoComplete.refs.menu) {
        if (this.props.clearOnBlur) {
            this.setState({ inputValue: '' })
        }

        this.setState({ isFocused: false })

        if (this.props.onBlur) this.props.onBlur(event)
    }
    if (this.props.alwaysClearOnBlur) {
        this.setState({ inputValue: '' })
    }
}
@leMaik
Copy link
Member

leMaik commented Dec 16, 2016

@amit1911 Thank you very much for the detailed report! I think that clearOnBlur should always clear on blur, so no need for a alwaysClearOnBlur prop. 😉 I'll track this as a bug.
There were some issues when clearing the input if autoComplete is enabled, though. I'll look into this on the week end. Or would you like to further investigate this issue? I'd really appreciate a PR. 😊

@leMaik leMaik added the bug label Dec 16, 2016
@leMaik leMaik changed the title Input not cleared on blur Input not cleared on blur if auto completion is enabled Dec 16, 2016
@amit1911
Copy link
Contributor Author

i disabled the if (!this.autoComplete || !this.autoComplete.refs.menu) { on my local and tested and everything worked fine for me. It was clearing the input on blur for autocomplete. But this might need detailed investigation if you noticed some issues earlier. i can create a PR by just removing the if condition if you want. Not sure if there is anything else to be done here.

@leMaik
Copy link
Member

leMaik commented Dec 16, 2016

@amit1911 Could you please check if

  • auto completion still works when using only the mouse
  • auto completion still works when using the arrow keys and pressing enter

We need automated tests for that. 😞

@amit1911
Copy link
Contributor Author

okay will verify this

@amit1911
Copy link
Contributor Author

Created the pull request #64 that fixes this issue and also verified the two things mentioned above by @leMaik

@leMaik
Copy link
Member

leMaik commented Dec 18, 2016

Awesome, thank you very much! 👍

@leMaik leMaik closed this as completed Dec 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants