The PasswordInput is a variation of the Input component. Please see the Input documentation for more examples and information.
Basic Usage
By default, users can show the password, by pressing a toggle button.
import React from 'react';import { PasswordInput } from 'react-magma-dom';export function Example() {return <PasswordInput labelText="Password" />;}
Hide Password Mask Button
To prevent users from showing the password, the optional boolean isPasswordMaskButtonHidden can be used.
import React from 'react';import { PasswordInput } from 'react-magma-dom';export function Example() {return (<PasswordInputisPasswordMaskButtonHiddenlabelText="Password with no unmask button"/>);}
Custom Strings
The following option props can be used to override various text strings that appear on the UI or to users using assistive technology: hiddenPasswordAnnounceText, hidePasswordButtonAriaLabel, hidePasswordButtonText, shownPasswordAnnounceText, showPasswordButtonAriaLabel, showPasswordButtonText.
When using multiple password fields, ensure the showPasswordButtonAriaLabel and hidePasswordButtonAriaLabel include the field's label to help screen reader users identify which field each button controls.
The toggle button's maximum width is limited to half of the input width.
import React from 'react';import { PasswordInput } from 'react-magma-dom';export function Example() {return (<PasswordInputlabelText="New Password"hiddenPasswordAnnounceText="New password is now concealed"hidePasswordButtonAriaLabel="Conceal new password"hidePasswordButtonText="Conceal"shownPasswordAnnounceText="New password is now revealed"showPasswordButtonAriaLabel="Reveal new password. Note: this will visually expose your new password on the screen"showPasswordButtonText="Reveal"/>);}
Disabled
import React from 'react';import { PasswordInput } from 'react-magma-dom';export function Example() {return (<PasswordInput isPasswordMaskButtonHidden labelText="Disabled" disabled />);}
Input Size
The inputSize prop can be used to control the input size. Options are medium and large, with medium being the default.
import React from 'react';import { PasswordInput, InputSize } from 'react-magma-dom';export function Example() {return (<PasswordInputinputSize={InputSize.large}labelText="Large password"showPasswordButtonAriaLabel="Show large password. Note: this will visually expose your large password on the screen"hidePasswordButtonAriaLabel="Hide large password"/>);}
Inverse
isInverse is an optional boolean prop, that may be passed in when inputs are to be displayed on a dark background.
import React from 'react';import { PasswordInput, Card, CardBody, magma } from 'react-magma-dom';export function Example() {return (<Card background={magma.colors.neutral1100} isInverse><CardBody><PasswordInputhelperMessage="Helper text"isInverselabelText="Inverse input"/></CardBody></Card>);}
Error Message
import React from 'react';import { PasswordInput } from 'react-magma-dom';export function Example() {return (<PasswordInputerrorMessage="Your password is incorrect"labelText="Password with error"/>);}
Password Input Props
This component uses forwardRef. The ref is applied to the input element.
All of the standard input attributes can be provided as props and will be applied to the input element that gets rendered.
Many of the PasswordInput props are shared with the Input component. Please see the Input documentation for more examples and information.
actionable
Description
Is the wrapped input hidden with display:none? This would make the input look like an actionable item, so FormFieldContainer uses a span in lieu of a label.
Type
boolean
Default
-
containerStyle
Description
Style properties for the outer container
Type
CSSProperties
Default
-
errorMessage
Description
Content of the error message. If a value is provided, the field will be styled as an error state and the error message will display.
Type
ReactNode
Default
-
hasCharacterCounter
Description
Enables Character Counter by default. When set to false, the default HTML attribute of 'maxlength' will work. Note: This is a temporary prop and will be removed in future releases.
Type
boolean
Default
true
helperMessage
Description
Content of the helper message.
Type
ReactNode
Default
-
hiddenPasswordAnnounceText
Type
string
Default
-
hidePasswordButtonAriaLabel
Description
Aria-label for the "Hide Password" button
Type
string
Default
"Hide password"
hidePasswordButtonText
Description
Text displayed on screen for the "Hide Password" button
Type
string
Default
"Hide"
iconPosition
Description
Position within the component for the icon to appear
Type
enum, one of:
InputIconPosition.left
InputIconPosition.right
InputIconPosition.top
Default
InputIconPosition.right
inputLength
Description
Total number of characters in an input.
Type
number
Default
-
inputSize
Description
Relative size of the component
Type
enum, one of:
InputSize.large
InputSize.medium
Default
InputSize.medium
isInverse
Description
If true, the component will have inverse styling to better appear on a dark background
Type
boolean
Default
false
isLabelVisuallyHidden
Description
If true, label text will be hidden visually, but will still be read by assistive technology
Type
boolean
Default
false
isPasswordMaskButtonHidden
Description
If true, label text will be hidden visually, but will still be read by assistive technology
Type
boolean
Default
false
labelPosition
Description
Position within the component for the label to appear
Type
enum, one of:
LabelPosition.left
LabelPosition.top
Default
LabelPosition.top
labelStyle
Description
Style properties for the label element
Type
CSSProperties
Default
-
labelText
Description
Content for label; can be a node or a string
Type
ReactNode
Default
-
labelWidth
Description
If the labelPosition value is 'left' then Input labels have a specified width in percentage, otherwise no width is set.
Type
number
Default
-
maxCount
Description
Enables the Character Counter and sets the maximum amount of characters allowed within the Input.
Type
number
Default
-
maxLength
Description
Enables the Character Counter and sets the maximum amount of characters allowed within the Input.
Type
number
Default
-
messageStyle
Description
Style properties for the helper or error message
Type
CSSProperties
Default
-
showPasswordButtonAriaLabel
Description
Aria-label for the "Show Password" button
Type
string
Default
"Show password. Note: this will visually expose your password on the screen"
showPasswordButtonText
Description
Text displayed on screen for the "Show Password" button
Type
string
Default
"Show"
shownPasswordAnnounceText
Type
string
Default
-
width
Description
String to determine width of input, must be suffixed with "px", "rem", or "%""
Type
string
Default
"auto"
On this page