Skip to content

Password input - Web Component

The PasswordInput component can be used imported from:

Playground

Parameters

The Web component uses the <z-password-input> tag:

By default, all the parameters are optional or can be set in different, except for the ones marked as required

The parametrization of the component can be done with the following custom HTML params:

NameTypeDescriptionSlotA11y
configstring

The main parameter has two components following the pattern: <shape><?:size>.

  • shape: Establishes the styling of the input. Default value is line . Possible values are: shaped or line. ,
  • size: (optional) defines de size of the input. The default value is m, being omitted from the param. The possible values are: m or l.
labelstringLabel of the inputlabel
placeholderstringPlaceholder of the input
readonlybooleanTransforms the input into an output
autocompletestringAutomated assistance in filling out form field values
modelstringValue of the model
disabledbooleanBlocks the interaction with the input component.
requiredbooleanMarks the input component as required.
namestringIdentification for the field inside the form
help-textstringThe forced message to be shown under the inputhelp-text
invalidbooleanThe forced state for set the input as invalid

Events

This component has events. Check the documentation about how to use the events.

NamePayloadDescription
changestringReturns the new value of the "value" attribute
entervoidTriggered when "Enter" in pressed
restartedvoidEmitted on value reset

Slots

This component has slots. Check the documentation about how to use the slots.

NameTagsDescription
defaultspan

Parameters use

config

The config parameter is used to set the shape of the input between lined and shaped. Being omitted will render the default line shape.

label

The label parameter is used to set the text label of the component. Make sure you always use it.

model

The model parameter is used to set the value for the input.

name

The name parameter is used to set the name of the component. This is useful when the component is part of a form.

help-text

The help-text parameter is used to provide additional assistance to the user.

Flags

disabled

The disabled parameter is used to block the interaction with the component. Not to be confused with readonly.

required

The required parameter is used to set the component as required.

readonly

The readonly parameter is used to set the input in a read-only state. It's commonly used to display information.

invalid

The invalid parameter is used to force the component to be invalid.

Special uses

Security level UI

We can use some extra Javascript and CSS to achieve a more visual validation interface for our password inputs. In this case we bind the input model and we use the help-text slot to present a discretized progress made with <div> tags that are activated with a data-active attributed that is set depending of the model length. We make the input invalid if the model length is 0.

So with some extra JavaScript added to this HTML:

And some SCSS styling, we achieve the functionality:

scss
#security-example {
  &:has(div[data-active] + div[data-active])::part(input) {
    border-color: var(--zc-lemon-aa);
  }

  &:has(div[data-active] + div[data-active] + div[data-active])::part(input) {
    border-color: var(--zc-moss-100);
  }

  output[slot="help-text"] {
    display: grid;
    gap: var(--zs-25);
    grid-template-columns: repeat(3, 1fr);
    padding-top: var(--zs-25);
    width: 100%;

    > div {
      background-color: var(--zg-8);
      height: var(--zs-50);
    }
    > div[data-active] {
      background-color: var(--zc-peach-aa);

      &:has(+ div[data-active]),
      &:first-child + div[data-active] {
        background-color: var(--zc-lemon-aa);
      }
      &:has(+ div[data-active] + div[data-active]),
      & + div[data-active]:has(+ div[data-active]),
      &:last-child {
        background-color: var(--zc-moss-100);
      }
    }
  }
}

Methods

reset()

We can all the reset() method of the WebComponent in order to reset the value. This will clean the internal states and emit the nullable value with the change event, plus a restarted event:

In this example, the button triggers the method:

Value:  undefined

Browser support

Detected engine:  

  • Chromium

  • Webkit

  • Gecko

HTML Examples

CodeSandbox example