Setting a custom anchorRef on popovers
#3794
Answered
by
diegohaz
cloud-walker
asked this question in
Questions
-
|
Hi all, I have the following situation: import * as A from '@ariakit/react'
import React from 'react'
const MyInput = React.forwardRef(function CustomInput(
{
wrapperRef,
...props
}: React.HTMLAttributes<HTMLInputElement> & {
wrapperRef?: React.Ref<HTMLDivElement>
},
ref: React.Ref<HTMLInputElement>,
) {
// this is the anchor that the popover needs, as the input is more inside the div, potentially with padding and stuff
return (
<div ref={wrapperRef}>
<input {...props} ref={ref} type="text" />
</div>
)
})
export function MyCombobox() {
const anchorRef = React.useRef<HTMLDivElement>(null) // is there a way to pass this ref to the popover?
return (
<A.ComboboxProvider>
<A.Combobox render={<MyInput wrapperRef={anchorRef} />} />
<A.ComboboxPopover>
<A.ComboboxItem value="1">One</A.ComboboxItem>
<A.ComboboxItem value="2">Two</A.ComboboxItem>
<A.ComboboxItem value="3">Three</A.ComboboxItem>
</A.ComboboxPopover>
</A.ComboboxProvider>
)
}Is there an (possibly ergonomic / official) way to pass the anchorRef to the popover? I've found that there is a Please consider that the example is a simplified example, in my real use case I've a UI library, with the Combobox splitted in multiple components. |
Beta Was this translation helpful? Give feedback.
Answered by
diegohaz
May 17, 2024
Replies: 1 comment 4 replies
-
|
You can use the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For now, yes. In the future, you'll be able to use
ComboboxAnchorseparately fromCombobox.