Airframe GitHub Storybook
Component

ba-input-password

An input field which enables customers to enter a password

Airframe

Active
Figma

Web Components

Active
Storybook GitHub

React

Active
Storybook GitHub

React Native

Planned
Design Code Accessibility QA
A

Label

A short, descriptive text that identifies the purpose of the input field

B

Hint text (optional)

Additional guidance below the label to help users complete the field correctly

C

Input field

The text entry area where users type their password, masked by default

D

Show password checkbox

Toggles the input field between masked and plain text to let users confirm what they've typed

<ba-input-password label="Password" name="password" hint-text="Custom hint text" required></ba-input-password>
Property Attribute Description Type Default
autocomplete autocomplete The autocomplete setting string | undefined 'current-password'
hintText hint-text Hint text to show above the input string | undefined undefined
inputWidth input-width The width of the input in characters string | undefined undefined
invalid invalid Whether the input is invalid boolean | undefined false
label(required) label A label for the input string undefined
maxLength max-length Max amount of characters allowed in validation string | undefined undefined
minLength min-length Min amount of characters allowed in validation string | undefined undefined
name(required) name The name of the input string undefined
required required Whether the input is required boolean | undefined false
value value The value of the input string | undefined ''
  • None
Slot Description Permitted elements
"error" Element will be rendered in the error slot <p>
"error-required" Element will be rendered in the error-required slot <p>
"error-min-length" Element will be rendered in the error-min-length slot <p>
"error-max-length" Element will be rendered in the error-max-length slot <p>
"help" Element will be rendered in the help slot above the hint text <ba‑flex>, <ba‑grid>, <div>

ba-input-password can be slotted into:

Event Description Type
baBlur Emitted when the input loses focus CustomEvent<void>
baFocus Emitted when the input has focus CustomEvent<void>
baOnInput Emitted when a keyboard input occurred CustomEvent<InputPasswordChangeEventDetail>
baSubmit Emitted when the user submits the form from within the component CustomEvent<void>
Method Description
isValid() => Promise<boolean> Triggers required validation and resolves with validity state
reset() => Promise<void> Resets the input back to its initial value and validity

Most scenarios will only require the label attribute and a name.

A simple password input
<ba-input-password label="Password" name="input-password"></ba-input-password>

It is sometimes useful to add hint text.

A password input that has hint text
<ba-input-password label="Password" name="input-password" hint-text="Custom hint text" required></ba-input-password>

You can specify a minimum and maximum length of characters.

Specifying a minimum and maximum length of characters
<ba-input-password name="password-input" label="Password" min-length="2" max-length="6"></ba-input-password>

You can set the field to be required.

Setting the field as required
<ba-input-password name="password-input" label="Password" required></ba-input-password>

BAgel provides error messages with translations for:

  • Required
  • Minimum length of characters
  • Maximum length of characters

These can be customised using slots.

Specifying custom validation errors
<ba-input-password name="password-input" label="Password" required min-length="2" max-length="6">
  <p slot="error-required">Custom required error</p>
  <p slot="error-min-length">Custom min length error</p>
  <p slot="error-max-length">Custom max length error</p>
</ba-input-password>

You can override all error messages with the error slot.

Overriding all error messages
<ba-input-password name="password-input" label="Password" required min-length="2" max-length="6">
  <p slot="error">This will override all error messages</p>
  <p slot="error-required">Custom required error</p>
  <p slot="error-min-length">Custom min length error</p>
  <p slot="error-max-length">Custom max length error</p>
</ba-input-password>

You can provide your own custom validation using events and props.

Custom validation
<ba-input-password name="password-input" label="Password" required>
  <p slot="error">Custom error message</p>
</ba-input-password>

<script>
  const passwordEl = document.querySelector('ba-input-password');
  passwordEl.addEventListener('baOnInput', (e) => {
    const value = e.detail.value;

    // Do your custom validation here.
    //
    //
    // Then set the input to invalid
    passwordEl.setAttribute('invalid')
  })
</script>

You can display your own custom validation rules using the help slot. Combine this with custom validation.

A full working example can be found on our storybook at the below link Custom Password Rules

Custom validation rules
<ba-input-password name="password-input" label="Password" required>
  <p slot="error">Custom error message</p>

  <ba-grid slot="help" class="password-rules" row-gutter-320vw="8" aria-live="polite">
    <ba-media-object gutter="8">
      <ba-icon
        slot="media"
        id="passwordLengthIcon"
        name="info"
        size="24"
      ></ba-icon>
      <ba-content>
        <p>
          <span class="ba-u-visually-hidden-text" id="numberLengthText">Password rule incomplete 10 to 20 characters with no spaces</span>
          <span aria-hidden="true">10 to 20 characters with no spaces</span>
        </p>
      </ba-content>
    </ba-media-object>

    <ba-media-object gutter="8">
      <ba-icon
        slot="media"
        id="upperLowercaseIcon"
        name="info"
        size="24"
      ></ba-icon>
      <ba-content>
        <p>
          <span class="ba-u-visually-hidden-text" id="numberCasingText">Password rule incomplete upper and lower case letters</span>
          <span aria-hidden="true">Upper and lower case letters</span>
        </p>
      </ba-content>
    </ba-media-object>

    <ba-media-object gutter="8">
      <ba-icon
        slot="media"
        id="oneNumberIcon"
        name="info"
        size="24"
      ></ba-icon>
      <ba-content>
        <p>
          <span class="ba-u-visually-hidden-text" id="numberHiddenText">Password rule incomplete at least 1 number</span>
          <span aria-hidden="true">At least 1 number</span>
        </p>
      </ba-content>
    </ba-media-object>
  </ba-grid>
</ba-input-password>

<script>
  const passwordEl = document.querySelector('ba-input-password');
  passwordEl.addEventListener('baOnInput', (e) => {
    const value = e.detail.value;

    // Do your custom validation here.
    //
    //
    // Then set the input to invalid
    passwordEl.setAttribute('invalid')
  })
</script>
Prop Description Type Default
autocomplete The autocomplete setting string | undefined 'current-password'
hintText Hint text to show above the input string | undefined undefined
inputWidth The width of the input in characters string | undefined undefined
invalid Whether the input is invalid boolean | undefined false
label (required) A label for the input string undefined
maxLength Max amount of characters allowed in validation string | undefined undefined
minLength Min amount of characters allowed in validation string | undefined undefined
name (required) The name of the input string undefined
required Whether the input is required boolean | undefined false
value The value of the input string | undefined ''
error Element will be rendered in the error slot <p>
errorRequired Element will be rendered in the error-required slot <p>
errorMinLength Element will be rendered in the error-min-length slot <p>
errorMaxLength Element will be rendered in the error-max-length slot <p>
help Element will be rendered in the help slot above the hint text <ba‑flex>, <ba‑grid>, <div>

None

BaInputPassword can be slotted into:

Event handler Description
onBaBlur Emitted when the input loses focus
onBaFocus Emitted when the input has focus
onBaInput Emitted when a keyboard input occurred
onBaSubmit Emitted when the user submits the form from within the component
Method Description
isValid() => Promise<boolean> Triggers required validation and resolves with validity state
reset() => Promise<void> Resets the input back to its initial value and validity

Most scenarios will only require the label attribute and a name.

A simple password input
<BaInputPassword label="Password" name="input-password" />

It is sometimes useful to add hint text.

A password input that has hint text
<BaInputPassword label="Password" name="input-password" hintText="Custom hint text" required />

You can specify a minimum and maximum length of characters.

Specifying a minimum and maximum length of characters
<BaInputPassword name="password-input" label="Password" minLength="2" maxLength="6" />

You can set the field to be required.

Setting the field as required
<BaInputPassword name="password-input" label="Password" required />

BAgel provides error messages with translations for required, minimum length, and maximum length. These can be customised using props.

Specifying custom validation errors
<BaInputPassword
  name="password-input"
  label="Password"
  required
  minLength="2"
  maxLength="6"
  errorRequired="Custom required error"
  errorMinLength="Custom min length error"
  errorMaxLength="Custom max length error"
/>

You can override all error messages with the error prop.

Overriding all error messages
<BaInputPassword
  name="password-input"
  label="Password"
  required
  minLength="2"
  maxLength="6"
  error="This will override all error messages"
  errorRequired="Custom required error"
  errorMinLength="Custom min length error"
  errorMaxLength="Custom max length error"
/>

You can provide your own custom validation using events and props.

Custom validation
export default function CustomValidationExample() {
  const [passwordInvalid, setPasswordInvalid] = useState(false);

  const customValidation = (event: { value: string }) => {
    // Do custom validation here

    // Set the input to invalid
    setPasswordInvalid(true);
  }

  return (
    <BaInputPassword
      label="Password"
      name="input-password"
      required
      invalid={passwordInvalid}
      onBaInput={customValidation}
      error="Custom error text"
    />
  );
}

React Native documentation coming soon.

Always use the label attribute to give a meaningful label to the field.

Further reading:

Disabled form elements are not supported in BAgel because they create accessibility challenges, such as preventing keyboard navigation, confusing screen reader users, and reducing visual clarity for those with impairments

Further reading:

Placeholders on inputs are not supported in BAgel because they create accessibility challenges, such as failing to provide persistent labels for screen readers, reducing color contrast for users with visual impairments, and causing confusion for those with cognitive difficulties.

If you would like to add a infomations to help the user fill the input, you can use the hint-text attribute.

Further reading:

State: Previous element in DOM has focus

⇥ Tab

<ba-input-password> input gets focus

State: <ba-input-password> input has focus

⇥ Tab

Show password checkbox gets focus

⇧ Shift + ⇥ Tab

Previous tabbable element in the DOM gets focus

State: Show password checkbox has focus

␣ Space

Toggles whether the password is masked or shown as plain text

⇥ Tab

Next tabbable element in the DOM gets focus

⇧ Shift + ⇥ Tab

<ba-input-password> input gets focus

Use this checklist to confirm the component has been configured and used correctly.

  • ba-input-password is only used for password entry fields
  • Hint text is used when the expected format or constraints may not be obvious to the user
  • Required fields are marked with the required attribute
  • min-length and max-length are set where the password has known character constraints
  • Custom validation rules are displayed using the help slot when the password must meet specific criteria
  • A meaningful label is provided via the label attribute
  • Hint text is used in preference to placeholder text, which is not supported
  • Error messages are descriptive and explain how to resolve the validation failure
  • The field is keyboard operable and receives a visible focus indicator
  • The disabled state is not used — ba-input-password does not support disabled inputs

These checks are handled by the component and do not need to be repeated each time it is used.

  • ba-input-password is operable using assistive technology
  • Has a visible focus indicator on all sides of the input
  • Colour contrast for all states in all BAgel themes
  • Animations respect users' reduced motion settings
  • High contrast mode adjustments
Designing Developing Components BAgel helper Web QA React Native QA britishairways.com Careers Cookie policy