Code Monkey home page Code Monkey logo

bootstrap-show-password-toggle's Introduction

LICENSE GitHub Super-Linter GitHub Stars npm Version npm Downloads

Bootstrap Show Password Toggle

A show password as text toggle for Bootstrap forms

  • Native-looking UI
  • Vanilla JavaScript with no dependencies
  • Base64 encoded SVG icons (no external images or fonts required)
  • Graceful fallback for browsers with JavaScript disabled
  • Works with Bootstrap 4 and 5
  • Supports dark mode (Bootstrap 5 only)
  • Only 1KB gzipped

show password toggle

Quick Start

  • Download the latest release
  • Clone the repo git clone https://github.com/coliff/bootstrap-show-password-toggle.git
  • Install with npm npm install bootstrap-show-password-toggle
  • Install with yarn yarn add bootstrap-show-password-toggle

Usage

  1. Include the show-password-toggle.min.css in your CSS

  2. Wrap the password input in an input-group div as follows:

<div class="input-group">
  <input type="password" class="form-control rounded" required>
  <button id="toggle-password" type="button" class="d-none"
    aria-label="Show password as plain text. Warning: this will display your password on the screen.">
  </button>
</div>
  1. Load the show-password-toggle.min.js after the form

I highly recommend adding the attributes: spellcheck="false", autocorrect="off" and autocapitalize="off" to the password input so that when the password is displayed in plain text the input is not auto-corrected, capitalized or spellchecked (to avoid red squiggly line underneath).

You should also add name="current-password" and autocomplete="current-password" to help browsers autocomplete the form.

Demo

Browser Support

Works well with all the browsers supported by Bootstrap

FAQS

Q. Can I change the show password icon?

A. Yes you can change the icon displayed by replacing the .input-password[type="password"] Base64 encoded background image. SVG is recommended.

Known Issues

  • If the browser autofills the password input then the user-agent will apply background-image: none !important.
  • The password input requires the use of the required attribute. This is so the background-image is not displayed when the input is empty. (It'd be great if browsers supported the :blank pseudo-selector!)

Credits and Thanks

  • MDO and Bootstrap team for the icons
  • Sam Dutton at Google for the idea and initial JavaScript from the 'Sign-in form Best Practices' article
  • BrowserStack for providing the infrastructure that allows us to test in real browsers

bootstrap-show-password-toggle's People

Contributors

atefbb avatar coliff avatar dan-jensen avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bootstrap-show-password-toggle's Issues

Icon not showing

Thanks for your great work - I've downloaded CSS and JS file via
https://raw.githubusercontent.com/coliff/bootstrap-show-password-toggle/master/css/show-password-toggle.css
but the icon is not rendered in the password field and only a gray rectangular is shown in Chrome browser.

Same is happening with min.css as well.

I do use the following bootstrap files:

Do I miss something?

Btw: https://coliff.github.io/bootstrap-show-password-toggle/tests/bootstrap4-sign-in/ does not render the icon in Chrome as well.

Thanks

Content Security Policy Error Fix

My project uses the content security policy and it refuses to load the image with the next error message:

"Refused to load the image 'data:image/svg+xml,%3Csvg' "

So to fix this I had to use the next tag:

<meta http-equiv="Content-Security-Policy" content="
        default-src 'none';
        style-src 'self' 'unsafe-inline';
        img-src 'self' data:;
        " />

Add Dark Mode Support

Bootstrap 5.3 will add dark mode support so it'd be great if this toggle supported dark mode.

Not positioning properly with form validation io.

When a form validation is included in project and the state of the input field results to valid, the form validation includes a check at the same position which is right next to each other.

Can the toggle be placed in front for that matter?

image

I had to modify the css to get it the way I want it to be. is there a way to dynamically handle this?

image

multiple on one page

I think from a 30 second peek at the code that this can only be used for one input on the page because it is targeting the button by a specific ID. Or am I wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.