-
Notifications
You must be signed in to change notification settings - Fork 526
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
Adds autocomplete components #1490
Conversation
🦋 Changeset detectedLatest commit: 43a84f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
5a092e3
to
ec58805
Compare
- allows the user to pass a custom scrollContainerRef if the menu is rendered inside a scrolling element besides AutocompleteOverlay - hides the AutocompleteMenu when it is rendered outside of the AutocompleteOverlay component
…ents' functionality
c7c68e8
to
dfc8b07
Compare
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
These are nit picks / tiny annoyances that I ran into while exploring the stories. I think both of these are polish and not deal breakers though.
|
…/text-input-with-tokens-component
…er/react into mp/autocomplete-components
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.
Overall: 😍 💅🏻 🤠 🎇
This is all great and very impressive. I have some questions for sure, but some of them might be mostly about my lack of context. Happy to jump on a call if that helps.
Unsolicited UX feedback
Another thing (already discussed over zoom) — it feels odd that hovering my mouse over the autocomplete suggestions would update the text input — I found that to be too much mutation to be driven off of a hover.
Something surprising: deleting a token results in the token text being put in the input.
Bug?
Not sure if it's a documentation bug or what but I noticed this odd text clipping:
CleanShot.2021-10-11.at.14.05.59.mp4
import AutocompleteMenu from './AutocompleteMenu' | ||
import AutocompleteOverlay from './AutocompleteOverlay' | ||
|
||
const Autocomplete: React.FC<{id?: string}> = ({children, id: idProp}) => { |
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.
🤔 what's the use case for id
as an external prop? I couldn't find a story or doc indicating why you'd want that.
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.
I wanted to give an easy way to select elements for integration tests. If you think there are better ways to do this, I'm happy to get rid of this prop.
filterFn = getDefaultItemFilter(inputValue), | ||
'aria-labelledby': ariaLabelledBy, | ||
onOpenChange, | ||
onSelectedChange = getDefaultOnSelectionChange(setInputValue), |
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.
if a user doesn't pass an onSelectedChange
, I think that means you'll be creating a new onSelectedChange
with each render, and it looks like there's a useMemo call below with onSelectedChange
in its dependencies array.
edit: same thing for filterFn
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.
Good catch. Any ideas for how we could avoid the re-renders?
My first thought is to export the "default" functions and require engineers to explicitly pass a filterFn
and onSelectedChange
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.
I ended up just removing the assignments from the destructured props. If the prop is undefined, we just call the default functions defined up top.
However, I could still see a case for exporting getDefaultItemFilter
and requiring a value for filterFn
.
I'd love to hear your thoughts.
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.
I think you can just change it to:
const AutocompleteMenu = ({
onSelectedChange // (don't assign a default yet here)
}): Props => {
// ...
const onSelectedChangeOrDefault = useMemo(() => {
return onSelectedChange || defaultOnSelectedChange(setInputValue)
}, [...])
}
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.
Ah ok, that works too.
Did you intentionally use useMemo
instead of useCallback
? I thought useCallback
was the one for memoizing functions.
I hadn't seen that when working in Storybook, but I wasn't working with strings that long. I'll take a look. Edit: I fixed the styling issue in the docs example. However, I noticed that the horizontal padding in the |
Noticed a few odds behaviors in the live code examples:
CleanShot.2021-10-12.at.15.06.05.mp4
CleanShot.2021-10-12.at.15.09.35.mp4 |
Thanks @colebemis! I see what the problems are. Thankfully they're both just silly mistakes with the example code and not bugs in the components. |
@@ -30,6 +30,7 @@ export {useConfirm} from './Dialog/ConfirmationDialog' | |||
export {ActionList} from './ActionList' | |||
export {ActionMenu} from './ActionMenu' | |||
export type {ActionMenuProps} from './ActionMenu' | |||
export {default as Autocomplete} from './Autocomplete' |
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.
Should we also export the props here?
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.
@jfuchs Can we right tests to ensure that components and their prop types are being exported?
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.
Probably. It looks like we do it for other components.
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.
Looks great! ✨
A couple of things before we merge this:
- Add a changeset
- Export the prop types from the
src/index.ts
Adds components that support adding autocomplete functionality to a text input.
Screenshots
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.