The removed "legacy" appearance promoted input placeholders to the floating label if the label was not specified. All newer appearance settings require explicitly specifying a if one was not provided before. This change addresses an accessibility best practice of not using labels and placeholders interchangeably.
Migrating to MDC-based Angular Material Components | Form Fields
This regular expression works with IntelliJ IDE and maybe with others, supporting regex search and replace.
(?s)(\s+)(<[a-z-]+[^>]*?)\s+placeholder=\"([^"]*)\"
$1<mat-label>$3</mat-label>$1$2
(?s)
- makes the dot match all characters, including line breaks(\s+)
- group to fetch whitespace to correctly indent code(<mat-[^>]*?)
- non greedy search group until ...\s+placeholder=
...we find the placeholder and possbile whitespace to replace the wholeplaceholder
attribute([^"]*)
- the actual content of our our new<mat-label>
@JWess that works very nice, it helped me do tons of replacements. Thank you.
I have just two caveats for that command though, for people who may find this page:
input
for amat-chip-row
, since those work differently and this script can mess those up if done without verfying.input
metadata like classes and whatnot, but proper style formatters should fix that.