Skip to content

How to get the click target when a DropdownMenu or Select is clicked? #2264

Answered by joaom00
holdenmatt asked this question in Help
Discussion options

You must be logged in to vote

You can listen for pointerdown events or control the select via open and onOpenChange props and open onClick only. (By doing the second option, you will not be able to select an item in one life cycle click i.e. mouse down, mouse move, mouse up.)

const [open, setOpen] = React.useState(false)

<Select.Root open={open} onOpenChange={setOpen}>
  <Select.Trigger onPointerDown={event => even.preventDefault()} onClick={() => setOpen(true)} />
</Select.Root>

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@holdenmatt
Comment options

@joaom00
Comment options

Answer selected by holdenmatt
@holdenmatt
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants