logo image
  • Overview

    • View all components
    • Install required things
  • Common UI

    • App Logo
    • Avatar
    • Button
    • Badge
    • Typography

    • Forms

    • Notification
    • Modal
    • Card
    • Breadcrumb
    • Pagination
    • Top Progress Bar
    • Table
    • Item Grid
    • Youtube Video
  • Features UI

    • Live chat button
  • Sections

    • Hero Banner
    • FAQs
  • Layouts

    • common

    • TopBar Layout
    • SideBar Layout
  1. Home
  2. Components
  3. Common Ui
  4. Forms
  5. Common
  6. Password Field

Password Field

The PasswordField component is a secure and reusable input designed for password entry. It uses Tailwind CSS for styling and Formik for managing form state and validation. With built-in support for hiding/showing passwords and error handling, it’s perfect for login, registration, and change-password forms. Easy to integrate and customize for any project.


Password Field preview

Form with Password Field

Please install everything that's required

Before setup and using this component, please install all the required dependencies from this link (if you have never installed).

1. Setup codes

Create a new file components/common/forms/PasswordField.tsx and add this code below

jsx
import React from "react"; import * as Yup from "yup"; import TextField from "./TextField"; type PassWordFieldProps = { className?: string; }; export const passwordFieldValidation = Yup.string() .min(8, "Password must be at least 8 characters") .matches(/[A-Z]/, "Password must contain at least one uppercase letter") .matches(/[a-z]/, "Password must contain at least one lowercase letter") .matches(/\d/, "Password must contain at least one number") .matches(/[@$!%*?&]/, "Password must contain at least one special character") .required("Password is required"); export default function PasswordField({ className }: PassWordFieldProps) { return ( <> <TextField id="password" name="password" type="password" label="Password" className={className} /> </> ); }

2. Usages

Because the PasswordField component is built base on Formik, so we need to wrap the Formik and Form tags out site of PasswordField component.

jsx
"use client"; import { Form, Formik } from "formik"; ... <Formik initialValues={{ password: "" }} validationSchema={validationSchema} onSubmit={(values) => alert(`Password is ${values.password}`)} > <Form className="flex flex-col gap-4"> <PasswordField /> ... </Form> </Formik>

You can see the UI of PasswordField

Form with Password Field

You can see all the source code of the form

jsx
"use client"; import { Form, Formik } from "formik"; import React from "react"; import * as Yup from "yup"; import Button from "@/components/Button"; import PasswordField, { passwordFieldValidation } from "@/components/Form/PasswordField"; const validationSchema = Yup.object().shape({ password: passwordFieldValidation, }); const TestForm = () => { return ( <div className="not-prose flex max-w-2xl flex-col gap-3 rounded-lg border-2 p-6"> <p className="mb-4 text-3xl font-bold">Form with Password Field</p> <Formik initialValues={{ password: "" }} validationSchema={validationSchema} onSubmit={(values) => alert(`Password is ${values.password}`)} > <Form className="flex flex-col gap-4"> <PasswordField /> <div> <Button type="submit" className="w-full"> <span> Submit <span aria-hidden="true">&rarr;</span> </span> </Button> </div> </Form> </Formik> </div> ); }; export default TestForm;

Learn more to using PasswordField component in Signin, Signup forms on this link

On this page

  1. 1. Setup codes

  2. 2. Usages