From 11ede2e5179262c737bac40e19835bb543f4e8ef Mon Sep 17 00:00:00 2001 From: Harish Gautam <33349461+harsh9975@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:49:06 +0530 Subject: [PATCH] fix: Onboarding page added `aria-lable` and keyboard navigation (#1562) Co-authored-by: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> --- .../(app)/onboarding/components/Greeting.tsx | 24 ++++++++++++- .../(app)/onboarding/components/Objective.tsx | 22 ++++++++++-- .../(app)/onboarding/components/Product.tsx | 1 + .../app/(app)/onboarding/components/Role.tsx | 23 +++++++++++-- apps/web/app/(app)/onboarding/utils.ts | 34 +++++++++++++++++++ packages/ui/ColorPicker/index.tsx | 2 ++ 6 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 apps/web/app/(app)/onboarding/utils.ts diff --git a/apps/web/app/(app)/onboarding/components/Greeting.tsx b/apps/web/app/(app)/onboarding/components/Greeting.tsx index 197bde421f..af5c4582fe 100644 --- a/apps/web/app/(app)/onboarding/components/Greeting.tsx +++ b/apps/web/app/(app)/onboarding/components/Greeting.tsx @@ -3,6 +3,7 @@ import { Button } from "@formbricks/ui/Button"; import type { Session } from "next-auth"; import Link from "next/link"; +import { useEffect, useRef } from "react"; type Greeting = { next: () => void; @@ -13,6 +14,27 @@ type Greeting = { const Greeting: React.FC = ({ next, skip, name, session }) => { const legacyUser = !session ? false : new Date(session?.user?.createdAt) < new Date("2023-05-03T00:00:00"); // if user is created before onboarding deployment + const buttonRef = useRef(null); + + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "Enter") { + event.preventDefault(); + next(); + } + }; + const button = buttonRef.current; + if (button) { + button.focus(); + button.addEventListener("keydown", handleKeyDown); + } + + return () => { + if (button) { + button.removeEventListener("keydown", handleKeyDown); + } + }; + }, []); return (
@@ -30,7 +52,7 @@ const Greeting: React.FC = ({ next, skip, name, session }) => { -
diff --git a/apps/web/app/(app)/onboarding/components/Objective.tsx b/apps/web/app/(app)/onboarding/components/Objective.tsx index 108ed1fed6..269dc067d3 100644 --- a/apps/web/app/(app)/onboarding/components/Objective.tsx +++ b/apps/web/app/(app)/onboarding/components/Objective.tsx @@ -7,8 +7,9 @@ import { cn } from "@formbricks/lib/cn"; import { TProfileObjective } from "@formbricks/types/profile"; import { TProfile } from "@formbricks/types/profile"; import { Button } from "@formbricks/ui/Button"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { toast } from "react-hot-toast"; +import { handleTabNavigation } from "../utils"; type ObjectiveProps = { next: () => void; @@ -35,6 +36,16 @@ const Objective: React.FC = ({ next, skip, formbricksResponseId, const [selectedChoice, setSelectedChoice] = useState(null); const [isProfileUpdating, setIsProfileUpdating] = useState(false); + const fieldsetRef = useRef(null); + + useEffect(() => { + const onKeyDown = handleTabNavigation(fieldsetRef, setSelectedChoice); + window.addEventListener("keydown", onKeyDown); + return () => { + window.removeEventListener("keydown", onKeyDown); + }; + }, [fieldsetRef, setSelectedChoice]); + const handleNextClick = async () => { if (selectedChoice) { const selectedObjective = objectives.find((objective) => objective.label === selectedChoice); @@ -71,14 +82,14 @@ const Objective: React.FC = ({ next, skip, formbricksResponseId, return (
-