Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♿️ Tie vote buttons to their date/time option and remove fake-clickable wrappers (#2565)
Luke Vellacc5d1e87dac0
diff --git a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsxindex b9e83c7f5..d5677781b 100644--- a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx+++ b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx@@ -15,9 +15,10 @@ import { Participant, ParticipantName } from "@/components/participant";import { useVotingForm } from "@/components/poll/voting-form";import { YouAvatar } from "@/components/poll/you-avatar";import { Trans, useTranslation } from "@/i18n/client";+import { getOptionDateTimeLabel } from "@/lib/utils/date-time-utils";-import { usePoll } from "../../poll-context";-import { toggleVote, VoteSelector } from "../vote-selector";+import { useOptions, usePoll } from "../../poll-context";+import { VoteSelector } from "../vote-selector";export interface ParticipantRowFormProps {name?: string;@@ -37,6 +38,7 @@ const ParticipantRowForm = ({const { t } = useTranslation();const { optionIds } = usePoll();+ const { options } = useOptions();const form = useVotingForm();React.useEffect(() => {@@ -107,6 +109,7 @@ const ParticipantRowForm = ({</div></td>{optionIds.map((optionId, i) => {+ const option = options[i];return (<tdkey={optionId}@@ -116,21 +119,17 @@ const ParticipantRowForm = ({control={form.control}name={`votes.${i}`}render={({ field }) => (- // biome-ignore lint/a11y/useKeyWithClickEvents: Fix later- // biome-ignore lint/a11y/noStaticElementInteractions: Fix later<div- onClick={() => {- field.onChange({- optionId,- type: toggleVote(field.value?.type),- });- }}className={cn(- "absolute inset-0 flex cursor-pointer items-center justify-center transition-colors",+ "absolute inset-0 flex items-center justify-center transition-colors","hover:bg-gray-50 active:bg-gray-100 active:ring-1 active:ring-gray-200 active:ring-inset dark:active:bg-gray-700/50 dark:active:ring-gray-700 dark:active:ring-inset dark:hover:bg-gray-800",)}><VoteSelector+ className="after:absolute after:inset-0"+ optionLabel={+ option ? getOptionDateTimeLabel(option) : undefined+ }value={field.value?.type}onChange={(vote) => {field.onChange({ optionId, type: vote });diff --git a/apps/web/src/components/poll/mobile-poll/poll-option.tsx b/apps/web/src/components/poll/mobile-poll/poll-option.tsxindex b72ce702d..a2c86744c 100644--- a/apps/web/src/components/poll/mobile-poll/poll-option.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-option.tsx@@ -1,13 +1,10 @@-/** biome-ignore-all lint/a11y/useSemanticElements: fix later */-/** biome-ignore-all lint/a11y/useKeyWithClickEvents: fix later */-/** biome-ignore-all lint/a11y/useFocusableInteractive: fix later */"use client";import type { VoteType } from "@rallly/database";import { cn } from "@rallly/ui";import { Button } from "@rallly/ui/button";import { Icon } from "@rallly/ui/icon";import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";-import * as React from "react";+import type * as React from "react";import { useToggle } from "react-use";import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";@@ -30,6 +27,7 @@ export interface PollOptionProps {onChange: (vote: VoteType) => void;selectedParticipantId?: string;optionId: string;+ optionLabel: string;}const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({@@ -133,24 +131,17 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({onChange,editable = false,optionId,+ optionLabel,}) => {const showVotes = !!(selectedParticipantId || editable);- const selectorRef = React.useRef<HTMLButtonElement>(null);- const [active, setActive] = React.useState(false);const [isExpanded, toggle] = useToggle(false);return (<div- role="button"- className={cn("space-y-4 bg-background p-4 transition-colors", {- "bg-accent/50": editable && active,- })}- onPointerDown={() => setActive(editable)}- onPointerUp={() => setActive(false)}- onPointerOut={() => setActive(false)}+ className={cn(+ "relative space-y-4 bg-background p-4 transition-colors",+ editable && "active:bg-accent/50",+ )}data-testid="poll-option"- onClick={() => {- selectorRef.current?.click();- }}><div className="flex h-7 items-center justify-between gap-x-4"><div className="shrink-0">{children}</div>@@ -158,20 +149,19 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({<Buttonsize="sm"variant="ghost"- onClick={(e) => {- e.stopPropagation();- toggle();- }}+ className="relative z-10"+ onClick={() => toggle()}><ConnectedScoreSummary optionId={optionId} /><Icon>{isExpanded ? <ChevronUpIcon /> : <ChevronDownIcon />}</Icon></Button>{showVotes ? (- <div className="relative flex size-7 items-center justify-center">+ <div className="flex size-7 items-center justify-center">{editable ? (<VoteSelector- ref={selectorRef}+ className="after:absolute after:inset-0"+ optionLabel={optionLabel}value={vote}onChange={onChange}/>diff --git a/apps/web/src/components/poll/mobile-poll/poll-options.tsx b/apps/web/src/components/poll/mobile-poll/poll-options.tsxindex 4a52eab2a..abd00c8f4 100644--- a/apps/web/src/components/poll/mobile-poll/poll-options.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-options.tsx@@ -5,6 +5,7 @@ import { useParticipants } from "@/components/participants-provider";import { useVotingForm } from "@/components/poll/voting-form";import { usePoll } from "@/components/poll-context";import type { ParsedDateTimeOpton } from "@/lib/utils/date-time-utils";+import { getOptionDateTimeLabel } from "@/lib/utils/date-time-utils";import DateOption from "./date-option";import TimeSlotOption from "./time-slot-option";@@ -59,6 +60,7 @@ const PollOptions: React.FunctionComponent<PollOptions> = ({<TimeSlotOptiononChange={handleChange}optionId={option.optionId}+ optionLabel={getOptionDateTimeLabel(option)}yesScore={score.yes}ifNeedBeScore={score.ifNeedBe}vote={vote}@@ -74,6 +76,7 @@ const PollOptions: React.FunctionComponent<PollOptions> = ({<DateOptiononChange={handleChange}optionId={option.optionId}+ optionLabel={getOptionDateTimeLabel(option)}yesScore={score.yes}ifNeedBeScore={score.ifNeedBe}vote={vote}diff --git a/apps/web/src/components/poll/vote-selector.tsx b/apps/web/src/components/poll/vote-selector.tsxindex fb951b86a..c48bd7286 100644--- a/apps/web/src/components/poll/vote-selector.tsx+++ b/apps/web/src/components/poll/vote-selector.tsx@@ -2,10 +2,18 @@ import type { VoteType } from "@rallly/database";import { cn } from "@rallly/ui";import * as React from "react";+import { useTranslation } from "@/i18n/client";+import VoteIcon from "./vote-icon";export interface VoteSelectorProps {value?: VoteType;+ /**+ * Accessible description of the option being voted on (e.g. "Tue 30 Jun+ * 2026, 1:00 PM – 2:00 PM") so screen readers can tie the vote to its+ * date/time.+ */+ optionLabel?: string;onChange?: (value: VoteType) => void;onFocus?: React.FocusEventHandler<HTMLButtonElement>;onBlur?: React.FocusEventHandler<HTMLButtonElement>;@@ -26,18 +34,34 @@ export const VoteSelector = React.forwardRef<HTMLButtonElement,VoteSelectorProps>(function VoteSelector(- { value, onChange, onFocus, onBlur, onKeyDown, className },+ { value, optionLabel, onChange, onFocus, onBlur, onKeyDown, className },ref,) {+ const { t } = useTranslation();++ const voteLabel = (() => {+ switch (value) {+ case "yes":+ return t("yes", { defaultValue: "Yes" });+ case "ifNeedBe":+ return t("ifNeedBe", { defaultValue: "If need be" });+ case "no":+ return t("no", { defaultValue: "No" });+ default:+ return t("pending", { defaultValue: "Pending" });+ }+ })();+return (<buttondata-testid="vote-selector"type="button"+ aria-label={optionLabel ? `${optionLabel}, ${voteLabel}` : voteLabel}onFocus={onFocus}onBlur={onBlur}onKeyDown={onKeyDown}className={cn(- "flex size-7 items-center justify-center rounded-lg border border-input bg-background ring-ring focus-visible:ring-2",+ "flex size-7 cursor-pointer items-center justify-center rounded-lg border border-input bg-background ring-ring focus-visible:ring-2",className,)}onClick={() => {diff --git a/apps/web/src/lib/utils/date-time-utils.ts b/apps/web/src/lib/utils/date-time-utils.tsindex 797af116b..bce17aaf1 100644--- a/apps/web/src/lib/utils/date-time-utils.ts+++ b/apps/web/src/lib/utils/date-time-utils.ts@@ -37,6 +37,13 @@ export interface ParsedTimeSlotOption {export type ParsedDateTimeOpton = ParsedDateOption | ParsedTimeSlotOption;+export const getOptionDateTimeLabel = (option: ParsedDateTimeOpton) => {+ const date = `${option.dow} ${option.day} ${option.month} ${option.year}`;+ return option.type === "timeSlot"+ ? `${date}, ${option.startTime} – ${option.endTime}`+ : date;+};+export const removeAllOptionsForDay = (options: DateTimeOption[],date: Date,