Grapes homepage1.57.0
  • Guide
  • Tokens
  • Components
    Grapes on GithubGrapes on Figma
    Interaction
    • Button
    • IconButton
    • FloatingActionBar
    • Link
    Icons
    • Icon
    • HighlightIcon
    Form
    • AmountInput
    • Autocomplete
    • AutocompleteMultiple
    • AutocompletePlace
    • CheckboxBox
    • CheckboxField
    • DatePicker
    • FormField
    • Input
    • OptionGroup
    • PasswordInput
    • PhoneInput
    • RadioBox
    • RadioField
    • RadioGroup
    • Select
    • SwitchField
    • TextArea
    • TextInput
    • Upload
    • UploadButton
    Feedback
    • Badge
    • Banner
    • Callout
    • EmptyState
    • Modal
    • ModalSlideshow
    • DeprecatedModalSlideshow
    • PageModal
    • Skeleton
    • Tag
    • Toast
    • Tooltip
    Data display
    • Accordion
    • Avatar
    • Box
    • Calendar
    • CalendarRange
    • CollapsibleList
    • FileCard
    • InfoTip
    • ListBox
    • ListView
    • Panel
    • SidePanel
    • DeprecatedPreview
    • Table
    • Timeline
    • useDateFormatter
    Navigation
    • DropdownItem
    • DropdownMenu
    • Navigation
    • NavigationItem
    • Popover
    • Tabs

    PasswordInput

    The PasswordInput creates an input of type password with a set of rules. The eye icon lets you display the password if needed.

    View source code
    • Usage
    • Props

    Basic usage

    const passwordRules: PasswordRule[] = [
      {
        label: "characters",
        required: 12,
        validate: (value): boolean => !!value && value.length >= 12,
      },
      {
        label: "lowercase",
        required: 1,
        validate: (value): boolean => !!value && value.toUpperCase() !== value,
      },
      {
        label: "uppercase",
        required: 1,
        validate: (value): boolean => !!value && value.toLowerCase() !== value,
      },
      {
        label: "digit",
        required: 1,
        validate: (value): boolean => !!value && /\d/.test(value),
      },
    ];
    
    const getConfirmPasswordRule = (password: string | null): PasswordRule => {
      return {
        label: "Passwords match",
        validate: (value) => Boolean(password && value && value === password),
      };
    };
    
    const Demo = () => {
      const [password, setPassword] = useState<string | null>(null);
      const [confirmPassword, setConfirmPassword] = useState<string | null>(null);
    
      return (
        <div className="w-[360px]">
          <PasswordInput
            fit="parent"
            rules={passwordRules}
            value={password}
            onChange={(event) => {
              setPassword(event.target.value);
            }}
          />
          <PasswordInput
            fit="parent"
            className="mt-16"
            rules={[getConfirmPasswordRule(password)]}
            value={confirmPassword}
            onChange={(event) => {
              setConfirmPassword(event.target.value);
            }}
          />
        </div>
      );
    };
    
    12 characters
    1 lowercase
    1 uppercase
    1 digit
    Passwords match