material icon indicating copy to clipboard operation
material copied to clipboard

feat(tab): support applying classes to md-tab and reflecting them on the md-tab-item

Open evamichalcak opened this issue 11 years ago • 19 comments

I need some tabs to be a different color than the rest. I assigned a class to the md-tab element in my markup, but it doesn't get assigned to the final md-tab-item and the styles don't apply to the tab. Shouldn't that class get passed on?

evamichalcak avatar May 29 '15 10:05 evamichalcak

I am facing the same problem. Although there is a unique ID attribute on every md-tab-content, developers still lose the control on these elements. Is there a way to add custom class values to md-tab-content tag?

tony0918 avatar Jun 03 '15 09:06 tony0918

@evamichalcak @tony0918 The way I was thinking of solving this issue would be that when using the md-tab-label and md-tab-body tags, all attributes would be transferred to their respective md-tab-item and md-tab-content tags. Any thoughts on this?

robertmesserle avatar Jun 09 '15 06:06 robertmesserle

@robertmesserle That's perfect. But Also from version 0.9.8, there is an additional div which wrap up tab contents. It's hard to add custom class to that div tag as well. Do you have any plan to that? Thanks.

tony0918 avatar Jun 09 '15 06:06 tony0918

@tony0918 This extra div MAY be temporary - I'd like to remove it, but the alternative solution is much uglier and would take a bit more time to fine tune. Is there any reason that you explicitly need a class on that DIV and not on the parent element?

robertmesserle avatar Jun 09 '15 06:06 robertmesserle

@robertmesserle That's wonderful. In order to make the content in the tab content to take the rest space of the container, I need to add flex and layout attributes on that element. It's my requirement.

tony0918 avatar Jun 09 '15 07:06 tony0918

@tony0918 Ah, okay, that makes sense.

robertmesserle avatar Jun 09 '15 08:06 robertmesserle

Where are we with this? We'd like to write web driver tests for our pages and not being able to set a class or an ID on a tab that we "click" on makes things very difficult and/or fragile (e.g. having to write a selector that includes the child offset of the tab).

osuritz avatar Nov 11 '15 00:11 osuritz

Much related to #2254. The solution proposed here by @robertmesserle would close both issues.

bonzanni avatar Feb 29 '16 09:02 bonzanni

This issue is closed as part of our deprecation effort. For details, see our post Spring Cleaning 2016.

ThomasBurleson avatar Apr 28 '16 20:04 ThomasBurleson

@osuritz did you ever figure out a solution for this? We're in exactly the same spot. Trying to write Protractor tests and can't assign a class or ID.

mcblum avatar Jul 25 '17 11:07 mcblum

I've moved on to a different project since, but I think at the time we ended up using an offset number in the CSS selector.

On Tue, Jul 25, 2017 at 4:59 AM, mcblum [email protected] wrote:

@osuritz https://github.com/osuritz did you ever figure out a solution for this? We're in exactly the same spot. Trying to write Protractor tests and can't assign a class or ID.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/material/issues/3028#issuecomment-317715721, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4qSDSJtQzAWPR20oeqyJJ4fqT6rIQAks5sRdi8gaJpZM4Eu_O- .

osuritz avatar Jul 25 '17 19:07 osuritz

I once wrote a directive which watches the class names of the original <md-tab> element and applies it to the actual item and dummy: md-tab-class

Maybe this helps someone.

Usage example:

<md-tabs>
	<md-tab
		ng-repeat="group in ctrl.groups"
		md-active="ctrl.activeGroup === group"
		ng-class="{
			undone: group.$undone,
			valid: group.$valid,
			invalid: !group.$valid,
			active: ctrl.activeGroup === group
		}"
		md-tab-class
	>
		<md-tab-label>{{group.title}}</md-tab-label>
	</md-tab>
</md-tabs>

oemmes avatar Jul 26 '17 06:07 oemmes

Thanks @oemmes this directive works like a charm.

solumspace avatar Feb 09 '18 18:02 solumspace

Re-opening this as it effects testability of AngularJS Material applications which is important. We would welcome a PR that resolved this.

Splaktar avatar Feb 11 '18 06:02 Splaktar

Fixed in https://github.com/angular/material/commit/aa30ada04bbd04c2e5fec99dd0b9357098d291db.

Splaktar avatar Sep 05 '18 15:09 Splaktar

@Splaktar Documentation needs update about this feature.

izerozlu avatar Sep 20 '18 09:09 izerozlu

@izerozlu docs were included in the PR. But for some reason it appears that they weren't deployed to https://material.angularjs.org/HEAD/api/directive/mdTab. I'll look into it and verify that they appear when we do the 1.1.11 release.

Splaktar avatar Sep 20 '18 18:09 Splaktar

I opened https://github.com/angular/material/issues/11451 to track this docs deployment issue.

Splaktar avatar Sep 20 '18 18:09 Splaktar

@izerozlu thanks for the heads up. The mdTab docs have been updated.

Splaktar avatar Sep 27 '18 00:09 Splaktar