Modifying CSS style of imported Fabric components
Hi Guys,
I am importing a component
import { TextField } from 'office-ui-fabric-react/lib/TextField';
in the return(
<TextField className={ searchInputCSS['search-textfield'] } placeholder="I want to know how to..." ariaLabel="Enter search text" value={ this.state.searchText } onChanged={ this.autosuggestHandler } onKeyPress ={ this._handleKeyPress } />
)
Even though I have assigned a different font size to my search-textfield class, it is being overriden by the MS styles.
What is the best way to override this?
can you define your rule as:
.ms-TextField.search-textfield { ... }
/* if you're using css modules */
:global(.ms-TextField).search-textfield { ... }
BTW I don't like this answer but css specificity is fighting us here. Open to suggestions.
I really, really don't want people to fallback to !important...
Inline styles would solve it, but I don't really want to go in that direction.
@dzearing I hear you.
Had tried increasing specificity but actually the component hides the <input> field which needs to be targeted to change the font size.
In this case had to go target <input> specifically by referencing the parent class and increasing specificity that way.
This works(even if a bit ugly)
.search-textfield input{ font-size:1.2em; }
We can always add more classNames to props to pass through. Or things like "inputProps" so you can pass through additional things targeted for specific places.
something like inputProps sounds pretty good. If standardized it would mean easy overrides.
Another possible option would be to load your customized css file after any component using a fabric component. This should theoretically put your css override after the fabric component css which means as the browser computes it the override would now win.
My guess is that the overrides file is currently before the component.
Of course all this depends on how your overrides file is being consumed. Are you bringing it in via require or writing it directly in the
of the html?
I've added inputClassName on TextField to push a specific class to the input element. That will help with the specific scenario.