Make WordPress Core

Changeset 65826


Ignore:
Timestamp:
11/30/2026 02:10:21 PM (less than one hour ago)
Author:
lancewillett
Message:

Build/Test Tools: Add TypeScript checking for password-toggle.js.

Guard against missing form elements before changing password visibility.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/16332

Props shailu25.
See #66751.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/password-toggle.js

    r63556 r65826  
    1313        toggleElements = document.querySelectorAll( '.pwd-toggle' );
    1414
    15         toggleElements.forEach( function (toggle) {
     15        toggleElements.forEach( function ( toggle ) {
    1616                toggle.classList.remove( 'hide-if-no-js' );
    1717                toggle.addEventListener( 'click', togglePassword );
    … …  
    2020        /**
    2121         * Toggles the password input field visibility.
     22         *
     23         * @this {HTMLElement}
    2224         */
    2325        function togglePassword() {
    2426                status = this.getAttribute( 'data-toggle' );
    25                 input = this.parentElement.children.namedItem( 'pwd' );
     27                input = this.parentElement ? this.parentElement.children.namedItem( 'pwd' ) : null;
    2628                icon = this.getElementsByClassName( 'dashicons' )[ 0 ];
    2729                label = this.getElementsByClassName( 'text' )[ 0 ];
    2830
    29                 if ( 0 === parseInt( status, 10 ) ) {
    30                         this.setAttribute( 'data-toggle', 1 );
     31                if ( ! input || ! icon || ! label ) {
     32                        return;
     33                }
     34
     35                if ( 0 === parseInt( status || '', 10 ) ) {
     36                        this.setAttribute( 'data-toggle', '1' );
    3137                        this.setAttribute( 'aria-label', __( 'Hide password' ) );
    3238                        input.setAttribute( 'type', 'text' );
    … …  
    3541                        icon.classList.add( 'dashicons-hidden' );
    3642                } else {
    37                         this.setAttribute( 'data-toggle', 0 );
     43                        this.setAttribute( 'data-toggle', '0' );
    3844                        this.setAttribute( 'aria-label', __( 'Show password' ) );
    3945                        input.setAttribute( 'type', 'password' );
  • trunk/tsconfig.json

    r65822 r65826  
    3636                "src/js/_enqueues/admin/media-new-upload.js",
    3737                "src/js/_enqueues/admin/media-upload-pipeline.js",
     38                "src/js/_enqueues/admin/password-toggle.js",
    3839                "src/js/_enqueues/admin/xfn.js",
    3940                "src/js/_enqueues/lib/accordion.js",
Note: See TracChangeset for help on using the changeset viewer.