2.0.0 • Published 14 days ago

@leafygreen-ui/password-input v2.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
14 days ago

Password Input

npm (scoped)

View on MongoDB.design

Installation

Yarn

yarn add @leafygreen-ui/password-input

NPM

npm install @leafygreen-ui/password-input

Example

import { PasswordInput } from '@leafygreen-ui/password-input';

// Multiple notifications
<PasswordInput
  label="New password"
  stateNotifications={[
    {
      notification: "i'm an error",
      state: 'error',
    },
    {
      notification: "i'm a warning",
      state: 'warning',
    },
    {
      notification: "i'm valid",
      state: 'valid',
    },
    {
      notification: "i'm waiting",
      state: 'none',
    },
  ]}
  autoComplete="new-password"
  id="new-password"
  onChange={() => console.log('onChange callback')}
/>;
// Single notification
<PasswordInput
  label="Confirm Password"
  stateNotifications={[
    {
      notification: "i'm an error",
      state: 'error',
    },
  ]}
  autoComplete="new-password"
  id="new-password"
/>
// Custom notification
<div>
  <PasswordInput
    label="Password"
    stateNotifications="error"
    aria-describedby="custom-error-id"
    autoComplete="current-password"
    id="current-password"
  />
  <Banner id="custom-error-id" variant="danger" />
</div>
// General notification
<PasswordInput
  label="Password"
  stateNotifications="error"
  autoComplete="current-password"
  id="current-password"
/>

<PasswordInput
  label="Password"
  stateNotifications="valid"
  autoComplete="current-password"
  id="current-password"
/>

Properties

PropTypeDescriptionDefault
idstringid associated with the password input.
labelstringText shown above the password input.
valuestringThe controlled value of the password input.
disabledbooleanDisables the password input but still allows you to toggle password visibility.false
onChangefunctionThe event handler function for the 'onchange' event. Accepts the change event object as its argument and returns nothing.
onBlurfunctionThe event handler function for the 'onblur' event. Accepts the focus event object as its argument and returns nothing.
placeholderstringThe placeholder text shown in the input field before the user begins typing.
autoCompletestringSpecifies what permission the user agent has to provide automated assistance in filling out form field values, as well as guidance to the browser as to the type of information expected in the field. More info can be found here.new-password
size'small' | 'default' | 'large'Determines the size of the input.default
errorMessagestringError message that appears below the input. Renders only if aria-disabledby=undefined and (stateNotifications='error' or stateNotifications='warning')'This input needs your attention'
successMessagestringSuccess message that appears below the input. Renders only if aria-disabledby=undefined and stateNotifications='valid''Success'
stateNotificationsArray<{notification: string; state: 'error' \| 'warning' \| 'valid' \| 'none'}> or 'error' | 'warning' | 'valid' | 'none'Determines what notifications will appear below the password input. The array determines the overall input state. If at least one object has 'error' | 'warning' as the state value, the input will display a red outline. If all objects have valid as the state value, then the input will display a green outline. If none of the conditions above are met, then the input will display a default state. To use a custom error notification container rather than the default provided in this component, stateNotifications will only require a string with the appropriate state value. In addition, the aria-describedby attribute must be provided with the id of the custom notification container. You can read more about aria-describedby here.[]
classNamestringThe className passed to the root element of the component.
...native input attributesAny other props will be spread on the root input element

States

const State = {
  Error: 'error', // red x icon, red text
  Warning: 'warning', // red warning icon, red text
  Valid: 'valid', // green checkmark, black text
  None: 'none', // gray checkmark, gray text
} as const;

Validation Feedback

Password input has 3 different supported options for validation feedback:

  1. Pass the id of a custom notification as the aria-describedby prop and pass a state value string as the stateNotifications prop to link a custom notification to the password input.
  2. Pass an array of notifications as the stateNotifications prop for cases where multiple notifications may need to render. aria-describedby prop must be undefined in this case.
  3. Pass a state value string and pass a string to the errorMessage prop or successMessage prop for cases where only a single notification will ever render. aria-describedby prop must be undefined and stateNotifications prop must be a string in this case.

Special Case

Aria Labels

Either label or aria-labelledby or aria-label must be provided a string, or there will be a console error. This is to ensure that screenreaders have a description for what the PAssword Input does.

Aria Describedby

To use a custom error notification container rather than the state notifications array or default error or success message provided in this component, stateNotifications requires a string with the appropriate state value. In addition, the aria-describedby attribute must be provided with the id of the custom notification container. You can read more about aria-describedby here.

2.0.0

14 days ago

1.0.20

25 days ago

1.0.19

1 month ago

1.0.18

2 months ago

1.0.17

2 months ago

1.0.16

7 months ago

1.0.9

10 months ago

2.0.0-alpha.0

10 months ago

2.0.0-alpha.1

10 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.7-next.0

12 months ago

1.0.7-next.1

12 months ago

1.0.7-next.2

12 months ago

1.0.7-next.3

12 months ago

1.0.8

11 months ago

1.0.7-next.4

12 months ago

1.0.7

11 months ago

1.0.7-next.5

12 months ago

1.0.7-next.6

12 months ago

1.0.6

12 months ago

1.0.7-next.7

12 months ago

1.0.5

12 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago