Hi!
I've seen the following stuff in one of our projects:
@Html.PropertyFor(x => x.Shortcuts, new
{
CustomTag = "ul role='menubar'",
ChildrenCustomTagName = "li role='none'"
})
The end tags looks like </li role='none'>
and </ul role='menubar'>
, which is quite ugly. But it's understandable, since the above usage isn't the way it's supposed to work.
I understand the purpose of the code, and it's quite relevant to be able to do these stuff, adding roles and other accessibility related stuff, without adding a custom ContentAreaRenderer.
The least I think the default implementation of ContentAreaRenderer should do, is to render the close tag properly, something like CustomTag.Split()[0]
and ChildrenCustomTagName.Split()[0]
, no matter that the tag names isn't good, it will give the possibility to add attributes without changing interface to PropertyFor
.
One other alternative — a cleaner one — would be adding the possibility to do something like:
@Html.PropertyFor(x => x.Shortcuts, new
{
CustomTag = "ul",
CustomTagAttributes = new { role = "menubar" },
ChildrenCustomTagName = "li",
ChildrenCustomTagAttributes = new { role = "none" },})
Anyway, there is a need of adding attributes through PropertyFor, and in my eyes the responsibility should be in the product, the default ContentAreaRenderer.