Skip to content

How to close the modal from inside a command or onSelect? #760

Answered by asabaylus
dariusj18 asked this question in Q&A
Discussion options

You must be logged in to vote

Begin by setting closeOnSelect to false which will prevent the palette from automaticaly closing. Also you can optionaly set showSpinnerOnSelect to false to prevent the spinner from showing. Make resetInputOnOpen true so that the palette will reset the next time its opened.

Now that the palette won't close when the user selects the async command use a react hook to update open prop to false. For the next time the palette is opened you may need to change the open state back to true again

      onAfterOpen={() => {
        setOpen(true);
      }}

Here's a complete example:
https://codesandbox.io/s/react-command-palette-closemodal-hoq90?file=/src/index.js

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by asabaylus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #752 on June 23, 2021 05:11.