Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/9a28e2c5d1621972ed5c587772f37be0 to your computer and use it in GitHub Desktop.
Save neverything/9a28e2c5d1621972ed5c587772f37be0 to your computer and use it in GitHub Desktop.
Toggle the visibility on a password input field with Alpine.js: https://silvanhagen.com/toggle-password-visibility-alpinejs
<!-- Define the Alpine.js component using x-data -->
<div x-data="{ show: false }">
<!-- Bind the type attribute to the value of show using the :type notation -->
<input :type="show ? 'text' : 'password'" name="password" type="password" value="LookMaaGreatPassw0rd!" />
<!-- Toggle the value of show on click using @click and bind the class
attribute to it using the :class notation -->
<svg @click="show = !show" :class="{'block': !show, 'hidden':show }">...</svg>
<!-- And the same goes for the svg hidden by default. -->
<svg @click="show = !show" :class="{'hidden': !show, 'block':show }">...</svg>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment