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

[Blazor] Nested Components with inner partial classes (not child components) #20765

Closed
vertonghenb opened this issue Apr 12, 2020 · 6 comments
Closed
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) feature-razor.language ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Pillar: Dev Experience Priority:2 Work that is important, but not critical for the release severity-minor This label is used by an internal tool Status: Resolved

Comments

@vertonghenb
Copy link
Contributor

vertonghenb commented Apr 12, 2020

The Idea

In C# we can use inner or nested classes for example:

partial class ClassWithNestedClass
{
    partial class NestedClass { }
}

partial class ClassWithNestedClass
{
    partial class NestedClass { }
}

More information about nested classes can be found here.

However it would be nice to see the same approach in Blazor for components, which can make the usage much cleaner and clearer, an example component (mind the . between Menu and Item or Menu and SubMenu)

<Menu>
   <Menu.Item Label="Text" Icon="myicon"/>
   <Menu.SubMenu>
      <Menu.Item Label="Text" Icon="myicon"/>
      <Menu.Item Label="Text" Icon="myicon"/>
   </Menu.Submenu>
</Menu>

The current workaround is to have the components fully named and there is no way (or at least that I'm aware of) to nest components like this(like nested classes), Which makes the code a bit less clear especially if you have multiple components with the SubMenu or Item name.

<Menu>
   <MenuItem Label="Text" Icon="myicon"/>
   <MenuSubMenu>
      <MenuItem Label="Text" Icon="myicon"/>
      <MenuItem Label="Text" Icon="myicon"/>
   </MenuSubmenu>
</Menu>

Describe the solution you'd like

Make it possible to create inner (nested) components just like we can do with normal nested classes.

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one labels Apr 13, 2020
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Apr 13, 2020
@mkArtakMSFT
Copy link
Member

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@StevenTCramer
Copy link
Contributor

This would be a nice feature to support encapsulation. Would reduce name conflicts and make code overall cleaner.

@captainsafia captainsafia added affected-medium This issue impacts approximately half of our customers severity-minor This label is used by an internal tool labels Oct 7, 2020
@montyclt
Copy link

montyclt commented Nov 2, 2020

That not only improve clearer markup, that allow too to access a private member of Menu class from Menu.Item class because a nested class can access to private members of the class that holds it.

When creating a component file named "Menu.Item.razor", the generated class is named Menu_Item. Creating nested classes with this file name will be a good enhacement.

@javiercn javiercn added feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) feature-razor.language labels Apr 19, 2021
@TanayParikh TanayParikh modified the milestones: Backlog, .NET 7 Planning Oct 19, 2021
@TanayParikh TanayParikh added the Priority:2 Work that is important, but not critical for the release label Oct 22, 2021
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 7 Planning, Backlog Nov 11, 2021
@ghost
Copy link

ghost commented Nov 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
Copy link
Member

This is a dupe of #12302

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2023
@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Dec 21, 2023
@ghost ghost added the Status: Resolved label Dec 21, 2023
@montyclt
Copy link

This is a dupe of #12302

Not really due the other issue is about restricting component to be placed as child of other component in markup and this issue is about define component as inner class of another class.

As I said:

That not only improve clearer markup, that allow too to access a private member of Menu class from Menu.Item class because a nested class can access to private members of the class that holds it.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) feature-razor.language ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Pillar: Dev Experience Priority:2 Work that is important, but not critical for the release severity-minor This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

8 participants