-
Notifications
You must be signed in to change notification settings - Fork 933
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Console errors when using 'toggleMenu' action prop #182
Comments
toggleMenu
action prop
I'm seeing the same thing. I made a minimal reproduction and I get the same errors. |
Hi! Yeah, so the problem is that So the solution is simple: You know... I think we could make this nicer for folks. In Who wants to do this? |
@kentcdodds I've got time to do this today. |
A couple of thoughts occurred to me:
|
I'm glad you asked! Yes, we should probably do this for all the |
Wow, you respond quickly! I actually just edited my second comment. What do you think of the new points? |
Yes, I like your item 3 idea. To avoid the issues though, we'll need to pluck those values off of the given object at the first of the function rather than in the callback. I'm thinking something as simple as: toggleMenu = (otherStateToSet = {}, cb) => {
const {highlightedIndex, inputValue, isOpen, selectedItem, type} = otherStateToSet
this.internalSetState(
({isOpen}) => {
return {isOpen: typeof isOpen === undefined ? isOpen : !isOpen, highlightedIndex, inputValue, selectedItem, type}
},
() => {
const {isOpen} = this.getState()
if (isOpen) {
this.highlightDefaultIndex()
}
cbToCb(cb)()
},
)
} We wouldn't really need a util for this I think... But maybe. |
Also, you mention |
Haha, I thought they did, but looks like they don't. We're probably good to leave them as-is |
Sounds great. I'll PR when I'm finished. |
downshift
version: 1.3.1node
version: 8.2.1npm
(oryarn
) version: yarn 0.27.5Relevant code or config
What you did:
I've tried using the
toggleMenu
action andisOpen
props to control the visibility of a dropdown menu.What happened:
isOpen
value changes as expected, but the console shows a bunch of these errors:Problem description:
Console gets a couple of above errors on each execution of
toggleMenu
action.Suggested solution:
I could easily get around this by managing the state of
isOpen
on my own, but it would be better if I could use thedownshift
actions for that simple use case.The text was updated successfully, but these errors were encountered: