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

Dropdown is getting overlapped by second react-select. #1537

Closed
Jaikant opened this issue Feb 7, 2017 · 29 comments
Closed

Dropdown is getting overlapped by second react-select. #1537

Jaikant opened this issue Feb 7, 2017 · 29 comments

Comments

@Jaikant
Copy link

Jaikant commented Feb 7, 2017

Hey guys, I have now been struggling for a few hours. I am having two react-select components.
The dropdown from the component on top is getting overlapped by the below component.

I added a z-index of 999 to .Select-menu-outer, but it doesn't change anything.
I have attached a screenshot of the issue.

screen shot 2017-02-07 at 4 29 22 pm

@evgeniiteterin
Copy link

anyone solved this problem? menuContainerStyle={{ zIndex: 5 }} not work.

@turnerniles
Copy link

See prateekjahead's comment: #1010
"HubSpot's react-select-plus takes in dropdownComponent as a prop which solves the issue."

@MaxInMoon
Copy link

By the way, zIndex doesn't has any effect on position: static elements

@mwmcode
Copy link

mwmcode commented Jun 30, 2017

this worked for me

.Select-menu {
    position: fixed !important;
}

then I had to give fixed width to both the input and the dropdown, here is the css I changed:

.Select {
    width: 444px !important;
    margin-right: 5px;
    z-index: 0 !important;
}

.Select.is-open {
	z-index: 1 !important;
}

.Select-menu {
    position: fixed !important;
    width: 440px !important;
    margin: 1px;
}

@brianarpie
Copy link

v1.2.1

.Select.is-open {
    z-index: 1000 !important;
}

worked for me

@lounsbrough
Copy link

Any update on getting this resolved?

@d3mp
Copy link

d3mp commented Mar 28, 2019

@lounsbrough, this is worked for me:

v2.4.2
const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };

@lounsbrough
Copy link

@d3mp, yes, we implemented something like this and it's working in our environment.

Thanks.

@juliankigwana
Copy link

juliankigwana commented Apr 5, 2019

@d3mp is right. You need to target the element that has the absolute style, which is the menu.

@benkindt
Copy link

@d3mp thanks, this works! Use it like:

const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };
<Select styles={selectStyles} />

@Luke-Markham
Copy link

@d3mp thanks, this works! Use it like:

const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };
<Select styles={selectStyles} />

worked for me

@simonkaspersen
Copy link

simonkaspersen commented Feb 20, 2020

This issue was made in 2017, and still is a issue?
None of the solutions above works. The dropdown menu is hidden behind other components. CSS, selectstyles og portal-component was not successful.

image

@Jonny-B
Copy link

Jonny-B commented Feb 21, 2020

Same here. Menu is still falling behind.

@flexdinesh
Copy link
Collaborator

flexdinesh commented Feb 21, 2020

@simonkaspersen @Jonny-B which version of react-select are you using?

Would you be able to create a codesandbox that replicates the behaviour? Would be easier to help if there's a code example in a codesandbox.

Also, you can try portalling as suggested here — #3263 (comment)

@simonkaspersen
Copy link

@flexdinesh Have tried with the 3 last versions.

Will try. I am currently writing away some of the react-select-boxes

@simonkaspersen
Copy link

So I needed a combination of:

menuPortalTarget={document.querySelector('body')}

and:

const selectStyles = {
    menuPortal: base => ({ ...base, zIndex: 9999 }),
    menu: provided => ({ ...provided, zIndex: "9999 !important" })
};

<Select 
    styles={selectStyles}
/>

@jossmac
Copy link
Collaborator

jossmac commented Feb 25, 2020

Default behaviour is correct, please see this CodeSandbox.

@MenachemICTBIT
Copy link

After seeing the half dozen related issues, yet not finding a resolution, I have found one.

<Select menuPortalTarget={document.body} menuPosition={'fixed'} />

Add these two options to your Select component.

It appears to make us of the new React Portal feature.

@jperestrelo
Copy link

Thanks @MenachemICTBIT I Was struggling with the same without finding any satisfactory solution, this worked like a charm!

@MenachemICTBIT
Copy link

@jperestrelo Glad to hear it. I really struggled with this one as well.

The next problem then becomes that, since the menu is position:fixed, if you need to scroll the page the menu won't scroll with you. I managed a slight hack where I added an event listener that closes the menu when you scroll outside the menu itself (allowing scrolling inside the menu).

@debuurjongen
Copy link

debuurjongen commented Jun 25, 2021

I had a problem with a relative position of the Select component (fixed position was not an option), fixed it by creating a wrapper containing the status of open menu and updating the z-index based on state:

const selectStyles = {
    container: () => ({ 
      position: 'relative',
      minWidth: '100%',
      maxWidth: 'auto', 
    })
};

const SelectWrapper = () => {

  const [menuIsOpen, setMenuIsOpen] = useState(false);

  return(
    <Select 
      styles={selectStyles}
      onMenuOpen={() => setMenuIsOpen(!menuIsOpen)}
      onMenuClose={() => setMenuIsOpen(!menuIsOpen)}
      styles={{ ...selectStyles, container: () => ({ ...selectStyles.container, zIndex: menuIsOpen ? 999 : 1 })}}
    />
)}

@GodAlmighty990
Copy link

This solution worked for me.

const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };
I am creating an app with bootstrap react falcon theme using their wizardInputs and this worked for me. My wizardInput was bleeding through my react select menu. Hope this helps someone

@BagusJatikusuma
Copy link

This solution worked for me.

const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) }; I am creating an app with bootstrap react falcon theme using their wizardInputs and this worked for me. My wizardInput was bleeding through my react select menu. Hope this helps someone

thank you. it works.

@AshwinNema
Copy link

@lounsbrough, this is worked for me:

v2.4.2 const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };

It helped. Thanks

@Dalton-Klein
Copy link

@lounsbrough, this is worked for me:
v2.4.2 const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };

It helped. Thanks

This did not work for me. No change in behavior.

@GodAlmighty990
Copy link

@lounsbrough, this is worked for me:
v2.4.2 const selectStyles = { menu: styles => ({ ...styles, zIndex: 999 }) };

It helped. Thanks

This did not work for me. No change in behavior.

try this

const customStyles = {
menu: base => ({
...base,
// override border radius to match the box
borderRadius: 0,
// kill the gap
marginTop: 0,
zIndex: 999
}),
}

<Select
name="keyword"
required={true}
className="mb-3"
styles={customStyles}
components={animatedComponents}
closeMenuOnSelect={true}
options={keywords}
defaultValue={responder?.length ? responder[0]?.responder?.keyword?.map((el) => { return {title: el.title, _id: el._id}}): ""}
getOptionLabel={({title}) => title}
getOptionValue={({_id}) => _id}
onChange={(keyword) => setUpload({...upload, keyword: keyword === null ? [] : keyword})}
isMulti
placeholder="select Keywords"
isSearchable={true}
errors={errors}
innerRef={register({
required: "Add your Keyword"
})}
/>

@amal-octilus
Copy link

amal-octilus commented Nov 30, 2023

hey guys mine is indside a model from headlessui
none of the above worked for me

below is my select component and modal code

import Select from "react-select";

function SearchableSelect({
    name,
    options = [],
    className = "",
    isMulti = false,
    customStyles = "",
    ...props
}) {
    return (
    <Select
        className={`basic-single h-10 ${className}`}
        classNamePrefix="select"
        defaultValue={props?.defaultValue ?? isMulti ? "" : options[0]}
        isMulti={isMulti}
        isClearable={true}
        isSearchable={true}
        name={name}
        options={options}
        styles={customStyles}
        {...props}
    />
);

}

export default SearchableSelect;

<Modal show={showModal} className="!overflow-y-auto">
                    <form
                        onSubmit={submit}
                        className="space-y-5"
                        id={cellData?.id}
                    >
                        <div className="p-8">
                            <div className="grid grid-cols-1 gap-x-10 gap-y-5 md:grid-cols-2">
                                {modalContent == "editContent" &&
                                    editFormData?.map((d, i) => {
                                        return (
                                            <div key={i}>
                                                {!!d?.selectable && (
                                                    <BaseFormControl
                                                        name={d?.name}
                                                        label={d?.label}
                                                        placeholder={d?.label}
                                                        error={errors[d?.name]}
                                                        renderInput={({
                                                            type,
                                                            ...props
                                                        }) => (
                                                            <SearchableSelect
                                                                customStyles={
                                                                    customStyles
                                                                }
                                                                isMulti={true}
                                                                 options={
                                                                     d?.options
                                                                 }
                                                                {...props}
                                                            />
                                                        )}
                                                        onChange={(val) => {
                                                            setData(
                                                                d?.name,
                                                                val?.map(
                                                                    (d) =>
                                                                        d?.value
                                                                )
                                                            );
                                                        }}
                                                        onBlur={(e) =>
                                                            validate(
                                                                e,
                                                                d?.type,
                                                                d?.name,
                                                                clearErrors,
                                                                setError
                                                            )
                                                        }
                                                    />
                                                )}
                                            </div>
                                        );
                                    })}
                            </div>
                            <div className="flex justify-end gap-2 pt-[1.5rem]">
                                <button
                                    className="btn btn-primary"
                                    onClick={submit}
                                >
                                    Update
                                </button>

                                <button
                                    onClick={() => setShowModal(false)}
                                    type="button"
                                    className="btn"
                                >
                                    Close
                                </button>
                            </div>
                        </div>
                    </form>
                </Modal>

@AliBayatpour
Copy link

The same issue: none of the solutions worked, and react select shows over the popup...

@m-nathani
Copy link

This issue was still happening to me on

"react-select": "^5.8.0",

image

    <SelectTimeInput
      name="closesAt"
      placeholder="Close time"
      aria-label="close at time"
      ....
      // menuPortalTarget is needed to avoid dropdown getting overlapped by second dropdown
      // https://github.com/JedWatson/react-select/issues/1537
      menuPortalTarget={document.body}
    />

and solution for it was this: menuPortalTarget={document.body} .

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