Last active
March 27, 2019 20:22
-
-
Save tbveralrud/fcdde1027d8c9f1ec06971b462c2a512 to your computer and use it in GitHub Desktop.
How to escape implicit autofill values in HTML label elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Browsers don't respect `autocomplete='off'`. | |
// Safari (maybe others) will inspect the text value of a `label` element to predict intent. | |
// Sometimes we want to include 'name' in the value and not have it interpreted as a 'user name'. | |
// This function will transform the string to a visually equivalent string by inserting `zero width join` characters. | |
const wordJoiner = '\u{2060}'; | |
export function escapeImplicitAutofillValue(label: string): string { | |
return label.split('').join(wordJoiner); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Screen readers will read each letter individually. Use
aria-label
with the unescaped string to speak the label correctly.