The TextField API doesn't mention anything about how one could style the pseudo placeholder element of the input element.
Basically, I would like to change the default styling of the placeholder text, and the normal bag of tricks doesn't work, as I cannot access the element.
Is there a way I can get to it? And if so, what is the JSS/React/DOM equivalent way of writing ::-webkit-input-placeholder
?
Case 1
Put the desired placeholder text in the
label
property of theTextField
component, and use thelabelClassName
property of theTextField
to customize it. You could also passInputLabelProps
with aclassName
,classes
orstyle
attribute.Case 2
Refrain from using the
label
property ofTextField
and put the placeholder text on itsplaceholder
property instead. Rely onInputProps
to override the generated HTMLinput
element's class.Code
The code below covers both aforementioned cases. CodeSandbox snippet.
you can add styling to your input using
::placeholder
selector incss
it'll workI haven't found a proper answer to how I can access the inner input element, but as to how one could target the placeholder element using JSS, I found the answer in the source of the
Input
element, of whichTextField
is composed.Basically, it's using the straight css names, just enclosed in quotes:
'&::-webkit-input-placeholder': { color: 'blue' }