Most components should be able to be opened programatically #1626
kennedyjustin
started this conversation in
Ideas
Replies: 2 comments
-
ref |
Beta Was this translation helpful? Give feedback.
0 replies
-
You should be able to catch the button reference, use the button event as a forwardRef. It's not that ideal, but work fine. export const Collapse = React.forwardRef<CollapseRef, Props>(
({ children }, ref) => {
const dRef = useRef<HTMLButtonElement>(null);
useImperativeHandle(ref, () => ({
toggle
}));
function toggle() {
dRef.current?.click();
}
return (
<Disclosure>
<Disclosure.Button ref={dRef} className="hidden" />
<Disclosure.Panel className="text-gray-500">
{children}
</Disclosure.Panel>
</Disclosure>
);
}
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Apologies if this has been hashed out before, but a major impediment to using this library smoothly is the scenario where components (like a Popover, Disclosure, etc.) must be opened manually/programatically.
The usual scenario is something like a search bar, where a popover below must be opened once the user starts typing. Obviously the use did not press a button, so theres no way to do it now.
I found the Dialog (Modal) component works really well, and I assume a similar API can be built with Popover/Disclosure, etc.
Beta Was this translation helpful? Give feedback.
All reactions