Allow custom CSS styles on Typeahead component #292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
see feature request: #227
Behaviour
When the component is initialized the provided values for "class" and "style" are extracted from the uncaptured attributes parameter
AdditionalAttributes
. The values are then put into separate private fields:string _classAttribute
for setting the classstring _styleAttribute
for setting stylesIReadOnlyDictionary<string, objec> _capturedAttributes
for the rest of the additional attributesWhen no values for "class" or "style" are provided the component shows as default.
Otherwise the css styling from the outer div component will be overriden:
Changes
_capturedAttributes
,_classAttribute
and_styleAttribute
_classAttribute
and_styleAttribute
on the outer div of the componentcolor
andbackground-color
(default would be set from browser and not inherited)Example
Here is a quick example showing the component working together with input groups from Bootstrap 5.0:
Default:
Override style
Additional Information
This was just a quickly drawn together experiment because i wanted to use the component in a input-group, but since it seems to work well overall i thought i might propose this a feature.
The styling can be a bit fiddly to get right because it has to work together with all other styles used on the component. As you can see i had to set the default
form-control
padding to 0 to avoid double margins, but i guess it is up to the user to make this right.All in all i think this is a good way to give the user enhance control over the design without interfering with the functionality of the component too much - and without any need to override the typehead css classes directly.