@@ -12,6 +12,17 @@ const getDefaultValue = (object: any, path: string) =>
1212 // eslint-disable-next-line unicorn/no-array-reduce
1313 path . split ( '.' ) . reduce ( ( a , b ) => a [ b ] , object ) ;
1414
15+ function checkWebkitTextSecuritySupported ( ) {
16+ const input = document . createElement ( 'input' ) ;
17+ input . style . display = 'none' ;
18+ document . body . append ( input ) ;
19+ const style = window . getComputedStyle ( input ) ;
20+
21+ return ! ! ( style as any ) . webkitTextSecurity ;
22+ }
23+
24+ const isWebkitTextSecuritySupported = checkWebkitTextSecuritySupported ( ) ;
25+
1526/**
1627 * @public
1728 */
@@ -77,6 +88,10 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
7788 const displayValue = isObscured ? obfuscateSecretDisplay ( value ) : value ;
7889 const isBlurred = ! showPlainText && ! ! value && ! isObscured ;
7990
91+ // The goal is to use webkitTextSecurity only if the browser supports it or if the field is multiline.
92+ // If the browser does not support webkitTextSecurity, we will use the password type.
93+ const useWebkitTextSecurity = isWebkitTextSecuritySupported || textFieldProps ?. multiline ;
94+
8095 return (
8196 < Stack
8297 direction = "row"
@@ -90,7 +105,7 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
90105 fullWidth = { true }
91106 helperText = { helperText }
92107 label = { label }
93- autoComplete = " off"
108+ autoComplete = { useWebkitTextSecurity ? ' off' : 'one-time-code' }
94109 required = { true }
95110 onChange = { onChange }
96111 onBlur = { onBlur }
@@ -101,11 +116,11 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
101116 ...textFieldProps ?. sx ,
102117 input : {
103118 ...( textFieldProps ?. sx as any ) ?. input ,
104- filter : isBlurred ? 'blur(3px) ' : undefined ,
119+ WebkitTextSecurity : useWebkitTextSecurity && isBlurred ? 'disc ' : undefined ,
105120 } ,
106121 textarea : {
107122 ...( textFieldProps ?. sx as any ) ?. textarea ,
108- filter : isBlurred ? 'blur(3px) ' : undefined ,
123+ WebkitTextSecurity : useWebkitTextSecurity && isBlurred ? 'disc ' : undefined ,
109124 } ,
110125 } }
111126 ref = { ref }
@@ -127,6 +142,9 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
127142 ) : null ,
128143 } ,
129144 } }
145+ type = {
146+ ! useWebkitTextSecurity && isBlurred && ! textFieldProps ?. multiline ? 'password' : 'text'
147+ }
130148 />
131149 { isSecret && (
132150 < FormFieldReset
0 commit comments