admin管理员组文章数量:1391955
After reading this SO question I found that it isn't possible to have nested optgroups
as it's not part of the HTML5 spec.
It is possible to apply styles yourself, but I would rather avoid that if it's possible in angular material.
"Under the hood" angular material swaps a lot of elements for divs and applies custom styling. Which makes me think they might handle this situation.
If I have the following code, I would expect the md-optgroup
with label="Second level deep"
to be indented further.
Plunker
<md-input-container>
<md-select ng-model="vm.someModel">
<md-optgroup label="One level deep">
<md-option>
One level deep
</md-option>
</md-optgroup>
<md-optgroup label="Another group">
<md-optgroup label="Second level deep">
<md-option>Two levels deep</md-option>
</md-optgroup>
</md-optgroup>
</md-select>
</md-input-container>
However, all md-optgroups
are not indented and displayed the same.
This is how it currently looks:
I can't see anything in the demos or docs about this (in fact they they don't have any docs for md-optgroup
at all), but the docs can sometimes be out of date/inplete.
Is it possible to have nested option groups with different indentation?
If not, what is the best way to achieve this using what is available in angular material? Should I use flex etc.
I'm trying to achieve something like this:
After reading this SO question I found that it isn't possible to have nested optgroups
as it's not part of the HTML5 spec.
It is possible to apply styles yourself, but I would rather avoid that if it's possible in angular material.
"Under the hood" angular material swaps a lot of elements for divs and applies custom styling. Which makes me think they might handle this situation.
If I have the following code, I would expect the md-optgroup
with label="Second level deep"
to be indented further.
Plunker
<md-input-container>
<md-select ng-model="vm.someModel">
<md-optgroup label="One level deep">
<md-option>
One level deep
</md-option>
</md-optgroup>
<md-optgroup label="Another group">
<md-optgroup label="Second level deep">
<md-option>Two levels deep</md-option>
</md-optgroup>
</md-optgroup>
</md-select>
</md-input-container>
However, all md-optgroups
are not indented and displayed the same.
This is how it currently looks:
I can't see anything in the demos or docs about this (in fact they they don't have any docs for md-optgroup
at all), but the docs can sometimes be out of date/inplete.
Is it possible to have nested option groups with different indentation?
If not, what is the best way to achieve this using what is available in angular material? Should I use flex etc.
I'm trying to achieve something like this:
Share Improve this question edited May 23, 2017 at 11:50 CommunityBot 11 silver badge asked Mar 4, 2016 at 11:03 Matt LishmanMatt Lishman 1,8172 gold badges23 silver badges34 bronze badges1 Answer
Reset to default 6After a bit of time to think about it, I managed to do it using flex-offset
.
You can simply apply flex-offset
to the md-optgroup
.
I used flex-offset="5"
because that looked the most sensible but any offset will work.
I added additional nesting and options to clarify the point a bit better.
Updated plunker
<md-input-container>
<md-select ng-model="vm.someModel">
<md-optgroup label="One level deep">
<md-option>
One level deep
</md-option>
</md-optgroup>
<md-optgroup label="Another group">
<md-optgroup flex-offset="5" label="Second level deep">
<md-optgroup flex-offset="5" label="3 deep now and we want to see what happens with long text">
<md-option>Some more options</md-option>
</md-optgroup>
<md-option>Two levels deep</md-option>
<md-option>Two levels deep again</md-option>
</md-optgroup>
</md-optgroup>
</md-select>
</md-input-container>
本文标签: javascriptAngular Material nested optgroupsStack Overflow
版权声明:本文标题:javascript - Angular Material nested optgroups - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685389a2619668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论