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

Spied input value as a state variable in EuiFieldSearch #3270

Merged
merged 4 commits into from
Apr 9, 2020

Conversation

anishagg17
Copy link
Contributor

@anishagg17 anishagg17 commented Apr 7, 2020

Summary

Fixes: #2860

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox

  • Props have proper autodocs
    - [ ] Added documentation examples
    - [ ] Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@thompsongl
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3270/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

After clicking the 'x' clear button, the text does get removed, but the button remains. The button should also hide after it is clicked.

@anishagg17
Copy link
Contributor Author

fixed the issue

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Two more cases where the clear button gets out of sync with the input value:

  1. When an empty input has its value set dynamically, no clear button is shown
  2. When an input with a value set, and that value is then set to '' dynamically, the clear button remains visible.

@anishagg17
Copy link
Contributor Author

anishagg17 commented Apr 9, 2020

I tried both the cases that you mentioned

by changing this to set the value to 'search' and '' respectively for both the cases without the regard of input e.target.value and both worked fine.

setValue(e.target.value);

Can you give a code overview and let me know if i am doing something wrong?

@thompsongl
Copy link
Contributor

The value updates I mentioned happen when the value prop is changed from outside the component. For example:

export default () => {
  const [value, setValue] = useState('');

  const onChange = e => {
    setValue(e.target.value);
  };

  return (
    <>
    <button onClick={() => setValue('outside')>Set to outside</button>
    <EuiFieldSearch
      value={value}
      onChange={onChange}
      isClearable={true}
    />
    </>
  )
}

Clicking the button will result in the prop value and state value of EuiFieldSearch to be out of sync.

@anishagg17
Copy link
Contributor Author

Sir, since the problem arises when no value prop is supplied to the component, I managed to utilize the state variable in that case to fix the issue,

@thompsongl
Copy link
Contributor

jenkins test this

The latest update appears to fix the issue case and the regressions introduced moving from props to state.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3270/

@thompsongl
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3270/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Thanks for working through this, @anishagg17!

@thompsongl thompsongl merged commit 1d25698 into elastic:master Apr 9, 2020
@anishagg17 anishagg17 deleted the search branch April 9, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EuiFieldSearch doesn't shows a button that quickly clears any input
3 participants