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

Can only pass child content to razor elements if the child content is all lowercase #7203

Open
trundlr opened this issue Dec 19, 2024 · 4 comments

Comments

@trundlr
Copy link

trundlr commented Dec 19, 2024

Describe the bug

It's impossible to pass a razor element as ChildContent for another custom razor element (non-builtin) as far as I can tell.

Image

Error | 'SelectionMenu' does not contain a definition for 'SelectionMenuTitle' and no accessible extension method 'SelectionMenuTitle' accepting a first argument of type 'SelectionMenu' could be found (are you missing a using directive or an assembly reference?) - _gen_FloorSelectionMenu.razor_3c355040.cs:28,76
   at Sandbox.CompileGroup.BuildAsync()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
   at Sandbox.Tasks.ExpirableSynchronizationContext.ProcessQueue() in 
'SelectionMenu' does not contain a definition for 'SelectionMenuTitle' and no accessible extension method 'SelectionMenuTitle' accepting a first argument of type 'SelectionMenu' could be found (are you missing a using directive or an assembly reference?)
at 'SelectionMenu' does not contain a definition for 'SelectionMenuTitle' and no accessible extension method 'SelectionMenuTitle' accepting a first argument of type 'SelectionMenu' could be found (are you missing a using directive or an assembly reference?) in UI/SelectionMenus/FloorSelectionMenu.razor:line 6

To Reproduce

See above!

Expected behavior

We should be able to pass custom panels as children into custom panels. It is very common practice in web development.

Media/Files

No response

Additional context

No response

@trundlr
Copy link
Author

trundlr commented Dec 19, 2024

Ok apparently it works if there are only lowercased letters in the element name and attributes 🤣 This compiles fine.
Image

@trundlr trundlr changed the title Can't pass custom razor elements as ChildContent to other custom razor elements Can only pass child content to razor elements if the child content is all lowercase Dec 19, 2024
@solwllms
Copy link

You need to expliclty specify which RenderFragment the stuff goes inside of (you can do multiple in a panel, at whatever points you like), so something like this should work:

<SelectionMenu>
	<ChildContent>
		<SelectionMenuTitle Title="Balls" />
	</ChildContent>
</SelectionMenu>

Does blazor do that implicitly if it's just ChildContent? im not even sure how that would work

@trundlr
Copy link
Author

trundlr commented Dec 19, 2024

I'm not sure about Blazor - but if it works all lowercased without nesting in tags, shouldn't it just work for upper cased as well? It's incredibly common to slot children in like how I have above in web frameworks, without having to specify some child tag.

@trundlr
Copy link
Author

trundlr commented Dec 19, 2024

https://blazor-university.com/templating-components-with-renderfragements/

This seems to imply you only need ChildContent if there is more than one RenderFragment being used on a component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

2 participants