Add reorderable tabs with global persistence (#347)

This commit is contained in:
Gregory Schier
2026-01-05 14:58:16 -08:00
committed by GitHub
parent 412d7a7654
commit e818c349cc
12 changed files with 426 additions and 118 deletions

View File

@@ -177,18 +177,23 @@ export const Dropdown = forwardRef<DropdownRef, DropdownProps>(function Dropdown
const child = useMemo(() => {
const existingChild = Children.only(children);
const originalOnClick = existingChild.props?.onClick;
const props: HTMLAttributes<HTMLButtonElement> & { ref: RefObject<HTMLButtonElement | null> } =
{
...existingChild.props,
ref: buttonRef,
'aria-haspopup': 'true',
onClick:
existingChild.props?.onClick ??
((e: MouseEvent<HTMLButtonElement>) => {
onClick: (e: MouseEvent<HTMLButtonElement>) => {
// Call original onClick first if it exists
originalOnClick?.(e);
// Only toggle dropdown if event wasn't prevented
if (!e.defaultPrevented) {
e.preventDefault();
e.stopPropagation();
handleSetIsOpen((o) => !o); // Toggle dropdown
}),
}
},
};
return cloneElement(existingChild, props);
}, [children, handleSetIsOpen]);