react-select icon indicating copy to clipboard operation
react-select copied to clipboard

VERY SERIOUS BUG: Drop down not always on top

Open pjebs opened this issue 10 years ago • 17 comments

The drop down list of multi choice select is sometimes underneath components when it should always be on top. See attached screenshots (This was in iOS 8 Safari):

screen shot 2016-06-05 at 6 33 27 pm screen shot 2016-06-05 at 6 33 31 pm

pjebs avatar Jun 05 '16 08:06 pjebs

Having this same issue, no amount of z-index, position or display trickery seems to fix it.

Moeface avatar Jun 08 '16 07:06 Moeface

For now I'm just listening to when the dropdown comes up and and down and showing/hiding the textboxes. It's the best work-around I've found so far - but it doesn't look good though.

pjebs avatar Jun 08 '16 07:06 pjebs

For me, this was an issue with Velocity. It inlines a transform: translateY(0), and transform prevents z-index from applying to it.

Moeface avatar Jun 10 '16 01:06 Moeface

I think the menu dropdown (the one with class Select-menu-outer) should always be appended as a child element in the body and positioned near the select input by some calculations. Otherwise if my select component is inside an element whose z-index is less than another sibling element, the dropdown would never be on top.

prateekjahead avatar Jun 24 '16 17:06 prateekjahead

HubSpot's react-select-plus takes in dropdownComponent as a prop which solves the issue.

prateekjahead avatar Jun 27 '16 05:06 prateekjahead

this does not solve my problem or maybe I missed something in the usage ?

florentdestremau avatar Mar 09 '17 14:03 florentdestremau

I'm not clear on what react-select-plus expects for dropdownComponent - I can provide a div for example, with a fixed height or what not, but the options don't appear. I was expecting it to just be a wrapper element, with the menu inside, but is it expecting me to provide the render options in there as well? (i.e. it is a custom menu dropdown, not a wrapper), it's unclear....

duanefields avatar Mar 21 '17 16:03 duanefields

@duanefields It looks like it should be of the form dropdownComponent={props => <div>{props.children}</div>} but @prateekjahead I don't see how it solves the issue since — looking at the source — this custom component is still rendered as a child of the Select component.

dperetti avatar Apr 04 '17 21:04 dperetti

@dperetti @duanefields So what I did was that I used the Portal component from react-overlays library so that the dropdownComponent is not rendered as a child of Select component, something like:

const dropdownComponent = ({children}) => (
  <Portal show rootClose={false}>
    {children}
  </Portal>
);

And used the prop menuContainerStyle to position it near/below the target element after making calculations in onOpen callback. Anyone know a better solution?

prateekjahead avatar Apr 06 '17 05:04 prateekjahead

I was able to fix this issue by using menuRenderer and setting position fixed, top and width for the menu element, some of this code is from react-select itself and I'm using typescript:

private menuRenderer(props: ReactSelect.MenuRendererProps<any>): 
    ReactSelect.HandlerRendererResult {
        const Option = (props as any).optionComponent;
        const bodyRect = document.body.getBoundingClientRect();
        const elementRect = (this.refs.reactSelect.wrapper as HTMLDivElement).getBoundingClientRect();
        const options = props.options.map((option, i) => {
            const isSelected = props.valueArray && props.valueArray.indexOf(option) > -1;
            const isFocused = option === props.focusedOption;
            const optionClass = classNames((props as any).optionClassName, {
                'Select-option': true,
                'is-selected': isSelected,
                'is-focused': isFocused,
                'is-disabled': option.disabled,
            });

            return (
                <Option
                    className={optionClass}
                    instancePrefix={(props as any).instancePrefix}
                    isDisabled={option.disabled}
                    isFocused={isFocused}
                    isSelected={isSelected}
                    key={`option-${i}-${option[(props as any).valueKey]}`}
                    onFocus={(props as any).onFocus}
                    onSelect={(props as any).onSelect}
                    option={option}
                    optionIndex={i}
                    ref={ref => { (props as any).onOptionRef(ref, isFocused); }}>
                    {(props as any).optionRenderer(option, i)}
                </Option>
            );
        });

        return <div className="Select-menu-outer" style={{ position: 'fixed', top: elementRect.top - bodyRect.top + elementRect.height + 2 + 'px', width: elementRect.width - 2 + 'px' }}>
            <div role="listbox" className="Select-menu" id="react-select-2--list">
                {options}
            </div>
        </div>;
    }

darianferrer avatar Sep 30 '17 12:09 darianferrer

Why is this issue closed when it still is happening?

DocCaliban avatar Nov 12 '19 00:11 DocCaliban

Adding

styles={{
    menuPortal: base => ({
        ...base,
        transform: 'translateZ(0)'

has fixed it for our case (elements which had transform: translateZ or translate3d set were shown above the dropdown). Or you can remove translateZ from those elements

DmitryGonchar avatar Jan 16 '20 02:01 DmitryGonchar

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.

MenachemICTBIT avatar Nov 23 '20 17:11 MenachemICTBIT

Your solution @MenachemICTBIT partially fixed it for me. Before only the first two could be seen. This issue has been around for 4 years!

It still doesn't fully fix it

image

afrancht avatar Dec 14 '20 19:12 afrancht

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.

and

menuPortal: (provided: any, state: any) => ({ ...provided, zIndex: '9999', }),

it worked for me!

olehbiletskyi avatar Feb 01 '22 16:02 olehbiletskyi

I m facing the same bug now, nothing is working. Tried almost all possible ways. menu menuportal and even css styles.

vvikramp avatar Jan 07 '24 14:01 vvikramp

I m facing the same bug now, nothing is working. Tried almost all possible ways. menu menuportal and even css styles.

same here.

Anhaachan avatar May 15 '24 07:05 Anhaachan