Skip to content

Commit

Permalink
use css focus for eligible dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangoMan committed Aug 29, 2024
1 parent 1361678 commit 3b0eb67
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/nextjs/app/admin/_components/SubmissionEligible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import { notification } from "~~/utils/scaffold-eth";

const eligibleLabelStyles = "label cursor-pointer text-sm justify-start gap-2";

// Close the dropdown by blurring the active element
const closeDropdown = () => {
const elem = document.activeElement;
if (elem instanceof HTMLElement) {
elem.blur();
}
};

export const SubmissionEligible = ({ submission }: { submission: Submission }) => {
const { mutateAsync: postNewEligible, isPending } = useMutation({
mutationFn: (newEligible: { eligible: boolean; clear: boolean }) =>
Expand All @@ -23,6 +31,7 @@ export const SubmissionEligible = ({ submission }: { submission: Submission }) =
try {
const result = await postNewEligible({ eligible: newEligible, clear: false });

closeDropdown();
notification.success(result.message);
refresh();
} catch (error: any) {
Expand Down Expand Up @@ -58,16 +67,18 @@ export const SubmissionEligible = ({ submission }: { submission: Submission }) =
}

return (
<details className="dropdown dropdown-end">
<summary
<div className="dropdown dropdown-end">
<div
tabIndex={0}
role="button"
className={clsx("absolute top-0 right-0 btn btn-xs border-0 font-medium text-gray-200 tracking-tighter", {
"text-gray-600 bg-gray-300 hover:bg-gray-400": submission.eligible === null,
"bg-red-800 hover:bg-red-700": submission.eligible === false,
"bg-green-800 hover:bg-green-700": submission.eligible === true,
})}
>
{buttonLabel}
</summary>
</div>
<div
tabIndex={0}
className="dropdown-content bg-base-100 z-[1] w-auto py-2 px-3 top-7 border border-gray-200 shadow"
Expand Down Expand Up @@ -134,6 +145,6 @@ export const SubmissionEligible = ({ submission }: { submission: Submission }) =
</div>
</div>
</div>
</details>
</div>
);
};

0 comments on commit 3b0eb67

Please sign in to comment.