Skip to content

fix(autocomplete): handle focusing when item is clicked and reset inputValue on form reset #11099

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

Merged
merged 13 commits into from
Dec 19, 2024

Conversation

driskull
Copy link
Member

@driskull driskull commented Dec 18, 2024

Related Issue: #10044

Summary

  • opens autocomplete when input is clicked
    • This is useful for when the input is already focused but the autocomplete is closed.
  • Sets focus and sets open=false when autocomplete-item is clicked
    • ensures that the input receives focus after an autocomplete-item is clicked
  • use enterKeyHint property JSX
  • update onFormReset to be called after form component logic
    • This allows us to reset the inputValue to the defaultInputValue without overriding existing logic
  • adds autocomplete to validation demo

cc @benelan

BEGIN_COMMIT_OVERRIDE
END_COMMIT_OVERRIDE

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Dec 18, 2024
@driskull driskull requested a review from benelan December 18, 2024 23:39
@driskull driskull marked this pull request as ready for review December 18, 2024 23:39
@driskull driskull changed the title fix(autocomplete): handle focusing when item is clicked. fix(autocomplete): handle focusing when item is clicked and reset inputValue on form reset Dec 19, 2024
// Autocomplete
const autocomplete = document.getElementById("framework");
autocomplete.addEventListener("calciteAutocompleteChange", (event) => {
autocomplete.inputValue = event.target.value;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is for demonstration purposes only. We don't update the inputValue when a value has been selected. This is because we don't know what data would be best to put into the input. A value may be a unique id, a description or label may be better. Its best to leave this up to the end user to decide if they want to populate the input or not. In some cases, it may be best to leave the input as is with whatever the user has typed in so they can adjust their query.

@driskull driskull added the no changelog entry Use the commit override to avoid a changelog entry label Dec 19, 2024
@driskull driskull requested a review from jcfranco December 19, 2024 00:33
@driskull driskull added the skip visual snapshots Pull requests that do not need visual regression testing. label Dec 19, 2024
Copy link
Member

@benelan benelan left a comment

Choose a reason for hiding this comment

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

Nice!

@driskull driskull merged commit fc2ceee into dev Dec 19, 2024
26 checks passed
@driskull driskull deleted the dris0000/autocomplete-fixes-form branch December 19, 2024 01:34
benelan pushed a commit that referenced this pull request Feb 8, 2025
…utValue on form reset (#11099)

**Related Issue:** #10044

## Summary

- opens autocomplete when input is clicked
- This is useful for when the input is already focused but the
autocomplete is closed.
- Sets focus and sets `open=false` when `autocomplete-item` is clicked
- ensures that the input receives focus after an `autocomplete-item` is
clicked
- use `enterKeyHint` property JSX
- update `onFormReset` to be called after form component logic
- This allows us to reset the `inputValue` to the `defaultInputValue`
without overriding existing logic
- adds autocomplete to validation demo

cc @benelan 


BEGIN_COMMIT_OVERRIDE
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. no changelog entry Use the commit override to avoid a changelog entry skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants