-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: add an AutocompleteWithSuggestions component for reusability #952
Conversation
Putting this in [WIP] mode because we want to extend this component further. A new feature for Newspack Listings needs this component to be able to handle multiple selections at once, like so: In this use case, the list of suggestions looks and behaves more like a taxonomy select component. I believe it would be possible to extend the component to handle this as well if we provide certain props (perhaps EDIT: Let's move forward with this with the single-select functionality only, as other PRs are currently blocked by this. |
Actually, @thomasguillot—would you mind if we tackled the multiselect enhancement of this component in a separate PR (and a second, subsequent NPM package release)? I ask because the single-item component is going to be a dependency of this Campaigns feature in the works, and it'd be great to not block that feature in the meantime. EDIT: opened an issue for the multiselect: #954 |
Yep, no problem @dkoo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some issues:
- After the component loads, but before typing anything into the input, selecting a post results in an empty item rendered:
- After selecting a post and typing in characters to select another one, user has to first remove the previously-selected post to insert the post from search results.
- The UI suggests that multiple items can be selected, while it's not true:
you can test within the Newspack Plugin
We do have a components demo page just for that purpose - I've added it there in 881d816
import { AutocompleteTokenField } from '../'; | ||
import './style.scss'; | ||
|
||
class AutocompleteWithSuggestions extends Component { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: would've expected any new components we add to be functional (non-class-based) components, but besides developer experience that's not that important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to a functional component in 74b51b9.
Ah, there was some weirdness in the interaction with the
Also fixed in 51bf59f. Now, you should be able to type in a search term, select a suggestion, and it will overwrite the existing value.
That's true, but for all use cases of the single-select version of this component, we immediately unmount the component and render something else as soon as a selected value exists, so it hasn't been an issue so far. I'm open to suggestions on how to display a selected state for this component when in single-select mode (maybe we separate the
Ah, I forgot about the demo page! Thanks for adding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Co-authored-by: Adam Boro <adam@adamboro.com>
# [1.40.0-alpha.1](v1.39.0...v1.40.0-alpha.1) (2021-05-18) ### Bug Fixes * replace WP User Avatar with Simple Local Avatars ([#966](#966)) ([f980412](f980412)) * **oauth:** wpcom token saving ([24052d6](24052d6)) * **progress-bar:** radius when having headings ([#963](#963)) ([8347362](8347362)) * loading quiet anim time/height and margin when admin menu is folded ([#958](#958)) ([f297780](f297780)) ### Features * add an AutocompleteWithSuggestions component for reusability ([#952](#952)) ([460728d](460728d)) * add new ButtonCard component ([#961](#961)) ([eff9edf](eff9edf)) * add reusable blocks extended as supported plugin ([#968](#968)) ([10f9758](10f9758))
🎉 This PR is included in version 1.40.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [1.40.0](v1.39.0...v1.40.0) (2021-05-18) ### Bug Fixes * replace WP User Avatar with Simple Local Avatars ([#966](#966)) ([f980412](f980412)) * **oauth:** wpcom token saving ([24052d6](24052d6)) * **progress-bar:** radius when having headings ([#963](#963)) ([8347362](8347362)) * loading quiet anim time/height and margin when admin menu is folded ([#958](#958)) ([f297780](f297780)) ### Features * add an AutocompleteWithSuggestions component for reusability ([#952](#952)) ([460728d](460728d)) * add new ButtonCard component ([#961](#961)) ([eff9edf](eff9edf)) * add reusable blocks extended as supported plugin ([#968](#968)) ([10f9758](10f9758))
🎉 This PR is included in version 1.40.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Adds a new component to the Newspack Components library, which is an extension of the
AutocompleteTokenfield
that also renders a list of suggestions to choose from. Takes functions as props for fetching suggestions, fetching saved tokens, and what to do when theAutocompleteTokenfield
value changes.This UI pattern is something that @thomasguillot has suggested for several features in progress, including this Author Profile block (not yet begun) and the Newspack Listings parent/child UI.
After this lands, we'll want to push a new version of the package to the NPM library.
How to test the changes in this Pull Request:
It's somewhat hard to test this as an NPM package, but you can test within the Newspack Plugin.
AutocompleteWithSuggestions
component from thenewspack-components
directory. Here's an example of some working code (may need to import additional dependencies such asapiFetch
,addQueryArgs
,decodeEntities
, etc.):fetchSuggestions
prop in the above example):cd
ing into the./assets/components
folder in this repo and runningnpm install && run prepublishOnly
. Then, in another repo that already uses components from thenewspack-components
NPM package, copy the contents of the./assets/components
folder into yournode_modules/newspack-components
folder in the second repo. You can then import likeimport { AutocompleteWithSuggestions } from 'newspack-components'
and test using the above example code in an editor page.Other information: