Search code examples
reactjsz-indexreact-bootstrapreact-select

How can I solve a z-index ploblem with react-bootstrap component and react-select menu?


I am using react-select and react-bootstrap and I have the following problem. I create a bootstrap Card and inside I have a react-select, and the problem is when I open the react-select menu, this one is not displayed fully. I have tried changing the z-index value and the position to relative but nothing changed. Here is an image of my problem: Image

import React from "react";
import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import MonthSelect from "../../../selects/MonthSelect";

import Container from "react-bootstrap/Container";
import Accordion from "react-bootstrap/Accordion";
import Card from "react-bootstrap/Card";
import Button from "react-bootstrap/Button";

const FeeSearch = props => {
  const { register } = props;

  return (
    <>
      <Accordion>
        <Card border="secondary">
          <Card.Header style={{ padding: "5px" }}>
            <Accordion.Toggle as={Button} variant="link">
              <h6>Búsqueda</h6>
            </Accordion.Toggle>
          </Card.Header>
          <Accordion.Collapse in={true}>
            <Card.Body>
              <Container fluid>
                <Form.Group>
                  <Row>
                    <Col xs={3}>
                      <Form.Label>Mes</Form.Label>
                      <MonthSelect register={register} />
                    </Col>
                  </Row>
                </Form.Group>
              </Container>
            </Card.Body>
          </Accordion.Collapse>
        </Card>
      </Accordion>
    </>
  );
};

export default FeeSearch;

Solution

  • Use the menuPortalTarget prop to render your react-select into the root of the document. The issue is your react-select is being rendered into a specific stacking context that has overflow: hidden. By rendering into the body, you ensure there's no wrapping context cutting off your content:

    <Select menuPortalTarget={document.body} />