Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Component Attributes Do Not Support Complex Content (mixed c# and markup) #29121

Closed
musictopia2 opened this issue Jan 7, 2021 · 9 comments
Labels
affected-few This issue impacts only small number of customers enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-razor.language ✔️ Resolution: Duplicate Resolved as a duplicate of another issue severity-nice-to-have This label is used by an internal tool Status: Resolved
Milestone

Comments

@musictopia2
Copy link

Here is my repository where the problem is duplicated each time.
https://github.com/musictopia2/ComplexContentBugSample

Either this is a bug or a new feature that is needed.

There are cases where somebody may use a custom component that accepts styles to make it more flexible.
If using divs, it works perfectly as you can see in my repository. I need it working even with custom components.
It would be okay if it somehow only worked when using standard class or style by splatting.

This is one case where its important to be able to mix c# into the string. If any other way is done, then you lose the intellisense for the styles which hurts productivity and makes it more likely to introduce errors as well.

I found out that early versions of blazor did not even support mixing c# for strings for divs. This same thing needs to happen even if its a custom component at least if using class and style via splatting.

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jan 7, 2021
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. Can you point to a specific line in your code indicating the behavior you'd like to work, where it currently doesn't?

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 7, 2021
@musictopia2
Copy link
Author

musictopia2 commented Jan 7, 2021

The line of code I would like to work is this

<SampleSplattingDiv style="background-color: @_firstColor;" />

the @ symbol means that a variable is coming from c#.
the same way it works if it was a div and not custom component that may pass on additional styles.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jan 7, 2021
@mkArtakMSFT
Copy link
Member

@NTaylorMullen do you have an issue we can dupe this with?

@mkArtakMSFT mkArtakMSFT removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Jan 8, 2021
@NTaylorMullen
Copy link
Contributor

@NTaylorMullen do you have an issue we can dupe this with?

Nope no issue. This was an intentional limitation early on in Blazor development to reduce the complexity of the system. Mixing content is a tough problem because of the implications it imposes on when/if to encode and how to buffer the entire content of the attribute performantly and still hand it off in a reasonable form to a consumer

@javiercn
Copy link
Member

You can always achieve this by using style="@("background-color: " + _firstColor)" if that is confusing just create a local function to compute the result and use style="GetComputedStyle()" or similar.

@musictopia2
Copy link
Author

Do you think its possible the tooling can be updated that if doing that way, the intellisense can still work.
Because I tried the first method and it showed no intellisense.
Even using the style=GetComputedStyle eliminates the intellisense for it as well.

@musictopia2
Copy link
Author

The mixing worked fine though when using standard div. If regular divs work, then shouldn't it work the same way if using a component instead of a standard div?

@mkArtakMSFT mkArtakMSFT modified the milestones: Discussions, Backlog Jan 11, 2021
@ghost
Copy link

ghost commented Jan 11, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one area-razor.compiler and removed area-blazor Includes: Blazor, Razor Components labels Jan 11, 2021
@captainsafia captainsafia added affected-few This issue impacts only small number of customers severity-nice-to-have This label is used by an internal tool labels Feb 18, 2021
@TanayParikh TanayParikh added feature-razor.language ✔️ Resolution: Duplicate Resolved as a duplicate of another issue labels Oct 19, 2021
@ghost ghost added the Status: Resolved label Oct 19, 2021
@TanayParikh
Copy link
Contributor

Thanks for reporting, closing as duplicate of dotnet/razor#7684.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-razor.language ✔️ Resolution: Duplicate Resolved as a duplicate of another issue severity-nice-to-have This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

6 participants