Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
Closing a popper MUI using ClickAwayListener affects everything inside

I'm new react developer, here I have small problem my ClickAwayListener should close Popper when clicking 'x' or outside, which it does but problem is I have a component inside my Paper and that have Select when I click that select to see my options then options appear and fast disappear, I have tested and ClickAwayListener also affects this, how to disable the affect of ClickAwayListener to those inside Paper?

import ClickAwayListener from "@material-ui/core/ClickAwayListener";

 const renderSettingsPopper = () => {
    return (
      <Popper
        id={"graph"}
        open={popupOpenState()}
        placement="left-start"
        anchorEl={anchorEl}
        className={props.classes.components}
        style={{ zIndex: 4 }}
        modifiers={{
          flip: {
            enabled: true,
          },
          preventOverflow: {
            enabled: true,
            boundariesElement: "viewport",
          },
        }}
      >
        <ClickAwayListener onClickAway={closeSettingsPopup}>
          <Paper className={props.classes.components}>
            {renderSettingsForm()}
          </Paper>
        </ClickAwayListener>
      </Popper>
    );
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This problem is harder than I anticipated but I finally found a solution. You need to track the Select open state inside the Popover.

<Select
  label="Age"
  defaultValue={10}
  onOpen={() => setSelectOpen(true)}
  MenuProps={{
    TransitionProps: {
      onExited: () => setSelectOpen(false),
    },
  }}
>
  <MenuItem value={10}>Ten</MenuItem>
  <MenuItem value={20}>Twenty</MenuItem>
  <MenuItem value={30}>Thirty</MenuItem>
</Select>

And disable the close handler when one of the Select is currently opened:

<ClickAwayListener
  onClickAway={() => {
    if (selectOpen) return;
    handleClose();
  }}
>

Codesandbox Demo

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda