ui icon indicating copy to clipboard operation
ui copied to clipboard

[bug]: Not choosing a value in a select nested in a popover closes the popover.

Open typeleven opened this issue 1 year ago • 8 comments

Describe the bug

if a select is placed in a popover the popover closes if you click out of the select without choosing a value.

Affected component/components

Popover

How to reproduce

click on popover enter select click back into the popover popover closes chrome_2024-08-31_07-05-55

Codesandbox/StackBlitz link

https://v0.dev/r/TOP7DD1xxY1?share=QI8DlC6dERDKeXgz36iMHglr

Logs

No response

System Info

v0

Before submitting

  • [X] I've made research efforts and searched the documentation
  • [X] I've searched for existing issues

typeleven avatar Sep 01 '24 14:09 typeleven

I encountered this bug too, and found where the issue lies (+ a workaround for it). I was using "@radix-ui/react-popover": "1.1.2", downgrading it to "@radix-ui/react-popover": "1.1.1" fixed the problem.

Alxertion avatar Oct 14 '24 10:10 Alxertion

Faced the same issue today, funnily enough the v0.dev link shows the correct behaviour now 🤔. I'm using "@radix-ui/react-popover": "1.1.1" (also tried 1.1.0 and 1.1.2) and "@radix-ui/react-select": "2.1.2".

In case this helps anyone else, my workaround was to control the open state on both the Popover and Select, and prevent the Popover from closing if the Select is currently open. Something like:

  const [open, setOpen] = useState(false);
  const [selectOpen, setSelectOpen] = useState(false);

  <Popover open={open} onOpenChange={(v) => !selectOpen && setOpen(v)}>
    {/* ... */}
    <Select open={selectOpen} onOpenChange={setSelectOpen}>
      {/* ... */}
    </Select>
    {/* ... */}
  </Popover>

niss36 avatar Oct 25 '24 14:10 niss36

Encountered the same bug today. Selects do not like Popovers. Does anybody know a clean workaround?

aretel avatar Jan 20 '25 12:01 aretel

const [selectOpen, setSelectOpen] = useState(false);

This worked and is relatively clean.

aretel avatar Jan 20 '25 12:01 aretel

any updates on this issue?

aretel avatar Feb 13 '25 14:02 aretel

This works

        <PopoverTrigger asChild>
          <Button variant="outline">Open Popover with Select</Button>
        </PopoverTrigger>
        <PopoverContent className="w-80">
          <div className="space-y-4">
            <h4 className="font-medium leading-none">Select an option</h4>
            <p className="text-sm text-muted-foreground">
              The popover will stay open while you interact with the select
            </p>
            <Select>
              <SelectTrigger
                onPointerDown={(e) => {
                  // Prevent the click from closing the popover
                  e.stopPropagation()
                }}
              >
                <SelectValue placeholder="Select an option" />
              </SelectTrigger>
              <SelectContent
                onCloseAutoFocus={(e) => {
                  // Prevent focus returning to popover which would close it
                  e.preventDefault()
                }}
              >
                <SelectItem value="option1">Option 1</SelectItem>
                <SelectItem value="option2">Option 2</SelectItem>
                <SelectItem value="option3">Option 3</SelectItem>
              </SelectContent>
            </Select>
            <p className="text-sm text-muted-foreground">Try clicking outside the select without making a selection</p>
          </div>
        </PopoverContent>
      </Popover>

saevig avatar Mar 26 '25 14:03 saevig

@heisenbugespen Thanks! This is it

alynaug avatar Apr 11 '25 05:04 alynaug

this claims that this issue is fixed, but its obviously not. https://github.com/radix-ui/primitives/issues/2224

I'm just using native-select as a solution (with popover), much simpler.

softmarshmallow avatar Dec 09 '25 10:12 softmarshmallow