Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♿️ Localized, accessible password input via InputGroup (WCAG 1.1.1 / 4.1.2) (#2505)
Luke Vella502c0f306ef2
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 1ba206f49..d9a4c5f07 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -299,6 +299,7 @@"hideAttribution": "Hide Attribution","hideParticipantsDescription": "Participants will not be able to see the names of other respondents.","hideParticipantsTitle": "Hide participant names",+ "hidePassword": "Hide password","hideScoresDescription": "Hide everyone's votes from a participant until they cast their own.","hideScoresTitle": "Hide votes","home": "Home",@@ -598,6 +599,7 @@"setupPasswordDescription": "Your account doesn't have a password yet. Click the button below to send a secure link to your email to set a password.","share": "Share","showBrandingDescription": "Show your brand identity on your public pages and emails",+ "showPassword": "Show password","shrink": "Shrink","signIn": "Sign in","signOut": "Sign Out",diff --git a/apps/web/src/app/[locale]/(auth)/register/components/register-name-form.tsx b/apps/web/src/app/[locale]/(auth)/register/components/register-name-form.tsxindex f5288fcd0..0b5b28bda 100644--- a/apps/web/src/app/[locale]/(auth)/register/components/register-name-form.tsx+++ b/apps/web/src/app/[locale]/(auth)/register/components/register-name-form.tsx@@ -12,12 +12,12 @@ import {FormMessage,} from "@rallly/ui/form";import { Input } from "@rallly/ui/input";-import { PasswordInput } from "@rallly/ui/password-input";import { absoluteUrl } from "@rallly/utils/absolute-url";import { useRouter, useSearchParams } from "next/navigation";import React from "react";import { useForm } from "react-hook-form";import { setVerificationEmail } from "@/app/[locale]/(auth)/login/actions";+import { PasswordInput } from "@/components/password-input";import { PasswordStrengthMeter } from "@/features/password/components/password-strength-meter";import { Trans, useTranslation } from "@/i18n/client";import { authClient } from "@/lib/auth-client";diff --git a/apps/web/src/app/[locale]/(auth)/reset-password/components/reset-password-form.tsx b/apps/web/src/app/[locale]/(auth)/reset-password/components/reset-password-form.tsxindex 04eecf961..447bd2d49 100644--- a/apps/web/src/app/[locale]/(auth)/reset-password/components/reset-password-form.tsx+++ b/apps/web/src/app/[locale]/(auth)/reset-password/components/reset-password-form.tsx@@ -10,10 +10,10 @@ import {FormLabel,FormMessage,} from "@rallly/ui/form";-import { PasswordInput } from "@rallly/ui/password-input";import { useRouter, useSearchParams } from "next/navigation";import { useForm } from "react-hook-form";import * as z from "zod";+import { PasswordInput } from "@/components/password-input";import { PasswordStrengthMeter } from "@/features/password/components/password-strength-meter";import { usePasswordValidationSchema } from "@/features/password/schema";import { Trans } from "@/i18n/client";diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsxindex 649a1f9cb..2594fc020 100644--- a/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsx@@ -9,10 +9,10 @@ import {FormLabel,FormMessage,} from "@rallly/ui/form";-import { PasswordInput } from "@rallly/ui/password-input";import { toast } from "@rallly/ui/sonner";import { useForm } from "react-hook-form";import * as z from "zod";+import { PasswordInput } from "@/components/password-input";import { PasswordStrengthMeter } from "@/features/password/components/password-strength-meter";import { usePasswordValidationSchema } from "@/features/password/schema";import { Trans, useTranslation } from "@/i18n/client";diff --git a/apps/web/src/components/password-input.tsx b/apps/web/src/components/password-input.tsxnew file mode 100644index 000000000..09e47349d--- /dev/null+++ b/apps/web/src/components/password-input.tsx@@ -0,0 +1,52 @@+"use client";++import { cn } from "@rallly/ui";+import {+ InputGroup,+ InputGroupAddon,+ InputGroupButton,+ InputGroupInput,+} from "@rallly/ui/input-group";+import { EyeIcon, EyeOffIcon } from "lucide-react";+import * as React from "react";+import { useTranslation } from "@/i18n/client";++export const PasswordInput = React.forwardRef<+ HTMLInputElement,+ React.ComponentProps<"input"> & { large?: boolean }+>(({ className, large, ...props }, ref) => {+ const { t } = useTranslation();+ const [showPassword, setShowPassword] = React.useState(false);++ return (+ <InputGroup className={cn("w-full", large ? "h-12" : "h-9")}>+ <InputGroupInput+ ref={ref}+ className={cn("h-full", large && "text-base", className)}+ {...props}+ type={showPassword ? "text" : "password"}+ />+ <InputGroupAddon+ align="inline-end"+ className={cn("has-[>button]:mr-0", large ? "pr-2" : "pr-1.5")}+ >+ <InputGroupButton+ variant="ghost"+ size={large ? "icon-sm" : "icon-xs"}+ className="text-muted-foreground"+ disabled={props.disabled}+ aria-label={+ showPassword+ ? t("hidePassword", { defaultValue: "Hide password" })+ : t("showPassword", { defaultValue: "Show password" })+ }+ onClick={() => setShowPassword((prev) => !prev)}+ >+ {showPassword ? <EyeOffIcon /> : <EyeIcon />}+ </InputGroupButton>+ </InputGroupAddon>+ </InputGroup>+ );+});++PasswordInput.displayName = "PasswordInput";diff --git a/apps/web/tests/authentication.spec.ts b/apps/web/tests/authentication.spec.tsindex 701bd4430..a3b149c42 100644--- a/apps/web/tests/authentication.spec.ts+++ b/apps/web/tests/authentication.spec.ts@@ -250,7 +250,7 @@ test.describe.serial(() => {// Fill in new passwordconst newPassword = "NewPassword456!";- await page.getByLabel("Password").fill(newPassword);+ await page.getByLabel("Password", { exact: true }).fill(newPassword);// Submit formawait page.getByRole("button", { name: "Reset password" }).click();@@ -264,7 +264,9 @@ test.describe.serial(() => {await page.goto("/reset-password?token=invalid-token-123");// Fill fields and submit- await page.getByLabel("Password").fill("NewPassword456!");+ await page+ .getByLabel("Password", { exact: true })+ .fill("NewPassword456!");await page.getByRole("button", { name: "Reset password" }).click();// Should show error message@@ -295,7 +297,7 @@ test.describe.serial(() => {// Reset to a new passwordconst finalPassword = "FinalPassword789!";await page.goto(resetLink);- await page.getByLabel("Password").fill(finalPassword);+ await page.getByLabel("Password", { exact: true }).fill(finalPassword);await page.getByRole("button", { name: "Reset password" }).click();// Now try to login with the new password@@ -347,7 +349,7 @@ test.describe.serial(() => {// Fill in passwordconst safePassword = "SafePassword123!";- await page.getByLabel("Password").fill(safePassword);+ await page.getByLabel("Password", { exact: true }).fill(safePassword);// Submit formawait page.getByRole("button", { name: "Reset password" }).click();diff --git a/packages/ui/src/password-input.tsx b/packages/ui/src/password-input.tsxdeleted file mode 100644index 999ae51d4..000000000--- a/packages/ui/src/password-input.tsx+++ /dev/null@@ -1,40 +0,0 @@-import { EyeIcon, EyeOffIcon } from "lucide-react";-import * as React from "react";--import type { InputProps } from "./input";-import { Input } from "./input";-import { cn } from "./lib/utils";--export interface PasswordInputProps extends InputProps {}--const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(- ({ className, type, ...props }, ref) => {- const [showPassword, setShowPassword] = React.useState(false);-- return (- <div className="relative">- <Input- type={showPassword ? "text" : "password"}- className={cn("pr-10", className)}- ref={ref}- {...props}- />- <button- type="button"- className="absolute top-1/2 right-4 -translate-y-1/2"- onClick={() => setShowPassword(!showPassword)}- disabled={props.disabled}- >- {showPassword ? (- <EyeOffIcon className="h-4 w-4 text-muted-foreground" />- ) : (- <EyeIcon className="h-4 w-4 text-muted-foreground" />- )}- </button>- </div>- );- },-);-PasswordInput.displayName = "PasswordInput";--export { PasswordInput };