You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for setting a default Component role #631
This is interesting, haven't thought about specifying role on the component level, which somehow makes sense. For now I've sent a PR to bind to the "role" attribute in templates #630, not sure if both the idea from this issue and template bindings are needed (I guess so).
I can take a stab at it. Before jumping to the impl, though, what is the advantage of expressing role in JS as opposed to having it as an attribute in a template? I guess it makes things easier if there are multiple templates, but is there more to it?
@jelbourn sure, but what I meant is moving the role attribute to the template of a component. But now I realise it would be probably a wrong place, since the role would be marked on an element that is a child of the md-button element, right?
@mhevery@rkirov what would be the best place to add this logic? I can special case it in the DirectiveParser step, but maybe it is worth to have a dedicated pipeline step for this?
I think this would have to be a compile step. Since you want to update the template so that you don't have to do it on clone.
assume template
<div>
<md-button></md-button>
</div>
While compiling the template we would come across md-button and we would know that it has a component. We could then see that the component has a role and update the element in template. This would be a one time thing resulting in this template:
@Mlaval I think it will be good enough to move forward. There might be another issue in the future about how much boilerplate is involved with @PropertySetter
It is true that it can be a lot of boilerplate with @PropertySetter, @EventEmitter, the future @Static if it happens, etc.
We could add some sugar with an option in the directive's configuration, but it will for sure make the annotation more complex.
I agree that we absolutely need some way to cut down on the boilerplate of the sheer number of things a component needs to inject. For example, the material grid-list tile would be something like
classMdGridTile{constructor(
@Parent()gridList: MdGridList,
@PropertySetter('style.height')heightSetter: Function,
@PropertySetter('style.width')widthSetter: Function,
@PropertySetter('style.top')topSetter: Function,
@PropertySetter('style.left')leftSetter: Function,
@PropertySetter('style.marginTop')marginTopSetter: Function,
@PropertySetter('style.paddingTop')paddingTopSetter: Function,
@PropertySetter('role')roleSetter: Function){this.gridList=gridList;this.heightSetter=heightSetter;this.widthSetter=widthSetter;this.topSetter=topSetter;this.leftSetter=leftSetter;this.marginTopSetter=marginTopSetter;this.paddingTopSetter=paddingTopSetter;roleSetter('listitem');// Now I can actually start doing things.}}
Activity
pkozlowski-opensource commentedon Feb 13, 2015
This is interesting, haven't thought about specifying role on the component level, which somehow makes sense. For now I've sent a PR to bind to the "role" attribute in templates #630, not sure if both the idea from this issue and template bindings are needed (I guess so).
jelbourn commentedon Feb 13, 2015
Yeah, both are needed. #630 is about letting you bind to the role, but this is saying that a given Component should always have role X by default.
mhevery commentedon Feb 18, 2015
Makes sense to me. +1
pkozlowski-opensource commentedon Feb 18, 2015
I can take a stab at it. Before jumping to the impl, though, what is the advantage of expressing role in JS as opposed to having it as an attribute in a template? I guess it makes things easier if there are multiple templates, but is there more to it?
jelbourn commentedon Feb 18, 2015
If you want to make a Component that always has a particular role, it would be annoying boilerplate to have to specify the role every time, like:
Obviously this Component will always be a
role="button", so the component author can save the user that boilerplate.pkozlowski-opensource commentedon Feb 18, 2015
@jelbourn sure, but what I meant is moving the
roleattribute to the template of a component. But now I realise it would be probably a wrong place, since the role would be marked on an element that is a child of themd-buttonelement, right?jelbourn commentedon Feb 18, 2015
@pkozlowski-opensource That's right, and that would (potentially) be inside of the shadow DOM and would be invisible to screen readers.
pkozlowski-opensource commentedon Feb 20, 2015
@jelbourn we should be fine with screen readers, seems like those can "break through" the shadow root barrier: http://substantial.com/blog/2014/02/05/accessibility-and-the-shadow-dom/
@mhevery @rkirov what would be the best place to add this logic? I can special case it in the DirectiveParser step, but maybe it is worth to have a dedicated pipeline step for this?
mhevery commentedon Feb 20, 2015
I think this would have to be a compile step. Since you want to update the template so that you don't have to do it on clone.
assume template
While compiling the template we would come across
md-buttonand we would know that it has a component. We could then see that the component has aroleand update the element in template. This would be a one time thing resulting in this template:10 remaining items
marclaval commentedon Mar 23, 2015
Thanks to #1052 , this is doable with
@PropertySetter('attr.role'). Is it good enough or do we still need the map ?jelbourn commentedon Mar 23, 2015
@Mlaval I think it will be good enough to move forward. There might be another issue in the future about how much boilerplate is involved with
@PropertySettermarclaval commentedon Mar 25, 2015
It is true that it can be a lot of boilerplate with
@PropertySetter,@EventEmitter, the future@Staticif it happens, etc.We could add some sugar with an option in the directive's configuration, but it will for sure make the annotation more complex.
@mhevery any thoughts ?
jelbourn commentedon Mar 25, 2015
I agree that we absolutely need some way to cut down on the boilerplate of the sheer number of things a component needs to inject. For example, the material grid-list tile would be something like
mhevery commentedon Mar 31, 2015
Can't you just inject:
jelbourn commentedon Mar 31, 2015
This was filed before you could do
@PropertySetter('attr.role'). Closing now.angular-automatic-lock-bot commentedon Sep 6, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.