So i’ve created a custom “button” tag helper for all <button>
tags and this works as intended. I’m able to sett certain properties for these and the available attributes show up as expected in the intellisense.
Tag helper:
[HtmlTargetElement("button")]
public class ButtonTagHelper(IWebHostEnvironment env) : TagHelper
{
/// <summary>
/// Set the variant of the button. If no type is set the "default" will be used.
/// - Primary
/// - Buy
/// - Ghost
/// - Transparent
/// </summary>
[HtmlAttributeName("e-button-variant")]
public string? ButtonVariant { get; set; }
The available attributes (with “e-” as prefix) show up in the intellisense for the <button>
tag:
Now I want to add a second “HtmlTargetElement” for this “button” tag helper with a “ParentTag” selector, like this:
[HtmlTargetElement("button")]
[HtmlTargetElement("dropdown-menu-toggle", ParentTag = "dropdown-menu")]
public class ButtonTagHelper(IWebHostEnvironment env) : TagHelper
{
/// <summary>
/// Set the variant of the button. If no type is set the "default" will be used.
/// - Primary
/// - Buy
/// - Ghost
/// - Transparent
/// </summary>
[HtmlAttributeName("e-button-variant")]
public string? ButtonVariant { get; set; }
But now the intellisense won’t show me the available attributes for this tag, why is this?
If I add the available attributes anyway the tag works as intended and when hoovering over the attribute it gives me the right description and so on.
If I remove the “ParentTag” selector from the “HtmlTargetElement” the intellisense now works?
[HtmlTargetElement("button")]
[HtmlTargetElement("dropdown-menu-toggle")]
public class ButtonTagHelper(IWebHostEnvironment env) : TagHelper
{
/// <summary>
/// Set the variant of the button. If no type is set the "default" will be used.
/// - Primary
/// - Buy
/// - Ghost
/// - Transparent
/// </summary>
[HtmlAttributeName("e-button-variant")]
public string? ButtonVariant { get; set; }
The intellisense now works:
Why is it that I will get intellisense for the available attributes for the tag if I remove the “ParentTag” selector but with it it does not? Isn’t the “ParentTag” just a condition for the tag helper and in this case the “dropdown-menu-toggle” meets those requirements?