[WIP] dropdown bug

This commit is contained in:
daniel31x13 2023-10-28 07:20:35 -04:00
parent ac795cdbdc
commit db47a2a142
3 changed files with 18 additions and 4 deletions

View File

@ -4,6 +4,7 @@ type Props = {
children: ReactNode; children: ReactNode;
onClickOutside: Function; onClickOutside: Function;
className?: string; className?: string;
style?: React.CSSProperties;
}; };
function useOutsideAlerter( function useOutsideAlerter(
@ -30,12 +31,13 @@ export default function ClickAwayHandler({
children, children,
onClickOutside, onClickOutside,
className, className,
style,
}: Props) { }: Props) {
const wrapperRef = useRef(null); const wrapperRef = useRef(null);
useOutsideAlerter(wrapperRef, onClickOutside); useOutsideAlerter(wrapperRef, onClickOutside);
return ( return (
<div ref={wrapperRef} className={className}> <div ref={wrapperRef} className={className} style={style}>
{children} {children}
</div> </div>
); );

View File

@ -19,11 +19,18 @@ type Props = {
onClickOutside: Function; onClickOutside: Function;
className?: string; className?: string;
items: MenuItem[]; items: MenuItem[];
style?: React.CSSProperties;
}; };
export default function Dropdown({ onClickOutside, className, items }: Props) { export default function Dropdown({
style,
onClickOutside,
className,
items,
}: Props) {
return ( return (
<ClickAwayHandler <ClickAwayHandler
style={style}
onClickOutside={onClickOutside} onClickOutside={onClickOutside}
className={`${className} py-1 shadow-md border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800 rounded-md flex flex-col z-20`} className={`${className} py-1 shadow-md border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800 rounded-md flex flex-col z-20`}
> >

View File

@ -139,7 +139,7 @@ export default function LinkCard({ link, count, className }: Props) {
permissions?.canDelete) && ( permissions?.canDelete) && (
<div <div
onClick={(e) => { onClick={(e) => {
console.log(); console.log(expandDropdown);
setExpandDropdown({ x: e.clientX, y: e.clientY }); setExpandDropdown({ x: e.clientX, y: e.clientY });
}} }}
id={"expand-dropdown" + link.id} id={"expand-dropdown" + link.id}
@ -228,6 +228,11 @@ export default function LinkCard({ link, count, className }: Props) {
</div> </div>
{expandDropdown ? ( {expandDropdown ? (
<Dropdown <Dropdown
style={{
position: "fixed",
top: `${expandDropdown.y}px`,
left: `${expandDropdown.x}px`,
}}
items={[ items={[
permissions === true permissions === true
? { ? {
@ -273,7 +278,7 @@ export default function LinkCard({ link, count, className }: Props) {
if (target.id !== "expand-dropdown" + link.id) if (target.id !== "expand-dropdown" + link.id)
setExpandDropdown(false); setExpandDropdown(false);
}} }}
className="absolute top-12 right-5 w-40" className="w-40"
/> />
) : null} ) : null}
</div> </div>