Skip to content
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

Using portal prop closes dropdown when clicking interactable areas in the dropdown #308

Open
shirleyxiao1103 opened this issue Jan 31, 2024 · 5 comments

Comments

@shirleyxiao1103
Copy link

shirleyxiao1103 commented Jan 31, 2024

Hello,
I'm utilizing the props portal to show the dropdown in the document.body like the example you have in your examples. However when I add the portal, anywhere I click inside the dropdown closes the dropdown and calls onDropdownClose. e.g if I try to click into the input field or if I try to click on an option while in multi select. At the moment the only way I can keep it open is if I utilize the keepOpen prop. Have any ideas on what could be closing the dropdown right away?

These are the other props I am currently using as well

<Select
        className={classNames.join(' ')}
        // dropdownPosition={dropdownPosition}
        // keepOpen={keepDropdownOpen}
        options={data}
        values={selectedOptions}
        disabled={isDisabled}
        dropdownGap={0}
        closeOnSelect={false}
        multi={isMulti}
        backspaceDelete={false}
        dropdownRenderer={customDropdownRenderer}
        contentRenderer={customContentRenderer}
        dropdownHandleRenderer={({ state }) => customDropdownHandleRenderer({ state, isMobile })}
       // onDropdownOpen={(e) => {
        //   onDropdownOpen(e);
        //   calculateDropdownSize();
        //   setKeepDropdownOpen(true);
        // }}
        onDropdownClose={(event) => {
          handleDropdownClose(event);
          console.log('onDropdownClose: ', event);
        }}
        handleKeyDownFn={handleKeyDownFn}
        portal={typeof document !== `undefined` && document.body}
        additionalProps={additionalProps}
      />
@shirleyxiao1103 shirleyxiao1103 changed the title Using portal prop closes dropdown when clicking anywhere in the dropdown Using portal prop closes dropdown when clicking interactable areas in the dropdown Jan 31, 2024
@sanusart
Copy link
Owner

sanusart commented Jan 31, 2024 via email

@shirleyxiao1103
Copy link
Author

One other thing I found is that if I disable the input field and click on that area it is fine.

Yup let me try recreating in a sandbox and will send it.

@shirleyxiao1103
Copy link
Author

shirleyxiao1103 commented Jan 31, 2024

here is a link with an example with clicking into input closes the dropdown, but clicking beside the input in the dropdown is fine https://codesandbox.io/p/sandbox/react-dropdown-select-example-y3cg9x?file=%2Fsrc%2FApp.js%3A24%2C50

Edit: seems like is related to position:relative

@sanusart
Copy link
Owner

sanusart commented Feb 2, 2024

Hey, I tryed here with regular input and it does not have the behaiviour
I am not sure how chackra UI is behaiving.

Try to see if the search in the select not needed, Maybe it is stilling the focus?

@shirleyxiao1103
Copy link
Author

yea maybe 🤔 I also tried that if I use a regular input and wrap that with a div that has position: relative the issue appears

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants