This repository was archived by the owner on Dec 3, 2024. It is now read-only.
Allow custom CSS styles on Typeahead component#292
Open
SSchulze1989 wants to merge 7 commits intoBlazored:mainfrom
Open
Allow custom CSS styles on Typeahead component#292SSchulze1989 wants to merge 7 commits intoBlazored:mainfrom
SSchulze1989 wants to merge 7 commits intoBlazored:mainfrom
Conversation
Adapted class on outer div to conform with default Input control style behaviour see https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web/src/Forms/AttributeUtilities.cs
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 _classAttributefor setting the classstring _styleAttributefor setting stylesIReadOnlyDictionary<string, objec> _capturedAttributesfor 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,_classAttributeand_styleAttribute_classAttributeand_styleAttributeon the outer div of the componentcolorandbackground-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-controlpadding 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.