Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@material/tab
Advanced tools
Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy. Each Tab governs the visibility of one group of content.
npm install @material/tab
<button class="mdc-tab" role="tab" aria-selected="false" tabindex="-1">
<span class="mdc-tab__content">
<span class="mdc-tab__icon material-icons" aria-hidden="true">favorite</span>
<span class="mdc-tab__text-label">Favorites</span>
</span>
<span class="mdc-tab-indicator">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
<div class="mdc-tab__focus-ring"></div>
</button>
The mdc-tab__focus-ring
element ensures that a focus indicator is displayed in high contrast mode around the active/focused tab.
@use "@material/tab/mdc-tab";
import {MDCTab} from '@material/tab';
const tab = new MDCTab(document.querySelector('.mdc-tab'));
See Importing the JS component for more information on how to import JavaScript.
NOTE: Don't forget to add the
mdc-tab-indicator--active
class to themdc-tab-indicator
subcomponent.
<button class="mdc-tab mdc-tab--active" role="tab" aria-selected="true">
<span class="mdc-tab__content">
<span class="mdc-tab__icon material-icons" aria-hidden="true">favorite</span>
<span class="mdc-tab__text-label">Favorites</span>
</span>
<span class="mdc-tab-indicator mdc-tab-indicator--active">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<span class="mdc-tab__ripple"></span>
<div class="mdc-tab__focus-ring"></div>
</button>
In the example under Basic Usage, the Tab Indicator will span the entire tab. Alternatively, the tab indicator can be
set up to span only the content of the tab if it is instead placed within the mdc-tab__content
element:
<button class="mdc-tab" role="tab" aria-selected="false" tabindex="-1">
<span class="mdc-tab__content">
<span class="mdc-tab__icon material-icons" aria-hidden="true">favorite</span>
<span class="mdc-tab__text-label">Favorites</span>
<span class="mdc-tab-indicator">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
</span>
<span class="mdc-tab__ripple"></span>
<div class="mdc-tab__focus-ring"></div>
</button>
We recommend using Material Icons from Google Fonts:
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
However, you can also use SVG, Font Awesome, or any other icon library you wish.
CSS Class | Description |
---|---|
mdc-tab | Mandatory. |
mdc-tab__content | Mandatory. Container of tab icon, text label and tab indicator. |
mdc-tab__ripple | Mandatory. Denotes the ripple surface for the tab. |
mdc-tab--active | Optional. Indicates that the tab is active. |
mdc-tab--stacked | Optional. Indicates that the tab icon and label should flow vertically instead of horizontally. |
mdc-tab--min-width | Optional. Indicates that the tab should shrink in size to be as narrow as possible without causing text to wrap. |
mdc-tab__text-label | Optional. Indicates the text label of the tab. |
mdc-tab__icon | Optional. Indicates a leading icon in the tab. |
To customize the colors of any part of the tab, use the following mixins.
Mixin | Description |
---|---|
text-label-color($color) | Customizes the color of the tab text label. |
icon-color($color) | Customizes the color of the tab icon. |
states-color($color) | Customizes the base states color, which affects hover/focus states and the press ripple. |
ink-color($color) | Customizes the text label, icon, and base states color. |
active-text-label-color($color) | Customizes the color of the active tab's text label. |
active-icon-color($color) | Customizes the color of the active tab's icon. |
active-states-color($color) | Customizes the color of the active tab's states. |
parent-positioning | Sets the positioning of the MDCTab's parent element so that MDCTab.computeDimensions() reports the same values in all browsers. |
fixed-width($width) | Sets the fixed width of the tab. The tab will never be smaller than the given width. |
horizontal-padding($padding) | Sets the horizontal padding of the tab. |
height($height) | Sets custom height to tab bar. |
text-transform($transform) | Sets tab text-transform property |
MDCTab
Properties and MethodsProperty | Value Type | Description |
---|---|---|
id | string | Value of the root tab element's id attribute. |
active | boolean (read-only) | Allows getting the active state of the tab. |
focusOnActivate | boolean (write-only) | Sets whether the tab should focus itself when activated. Defaults to true . |
Method Signature | Description |
---|---|
activate(previousIndicatorClientRect?: ClientRect) => void | Activates the indicator. previousIndicatorClientRect is an optional argument. |
deactivate() => void | Deactivates the indicator. |
focus() => void | Focuses the tab. |
computeIndicatorClientRect() => ClientRect | Returns the bounding client rect of the indicator. |
computeDimensions() => MDCTabDimensions | Returns the dimensions of the Tab. |
Event Name | Event Data Structure | Description |
---|---|---|
MDCTab:interacted | {"detail": {"tabId": string}} | Emitted when the Tab is interacted with, regardless of its active state. Used by parent components to know which Tab to activate. |
If you are using a JavaScript framework, such as React or Angular, you can create a Tab for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.
MDCTabAdapter
Method Signature | Description |
---|---|
addClass(className: string) => void | Adds a class to the root element. |
removeClass(className: string) => void | Removes a class from the root element. |
hasClass(className: string) => boolean | Returns true if the root element contains the given class. |
setAttr(attr: string, value: string) => void | Sets the given attribute on the root element to the given value. |
activateIndicator(previousIndicatorClientRect?: ClientRect) => void | Activates the tab indicator subcomponent. previousIndicatorClientRect is an optional argument. |
deactivateIndicator() => void | Deactivates the tab indicator subcomponent. |
getOffsetLeft() => number | Returns the offsetLeft value of the root element. |
getOffsetWidth() => number | Returns the offsetWidth value of the root element. |
getContentOffsetLeft() => number | Returns the offsetLeft value of the content element. |
getContentOffsetWidth() => number | Returns the offsetWidth value of the content element. |
notifyInteracted() => void | Emits the MDCTab:interacted event. |
focus() => void | Applies focus to the root element. |
MDCTabFoundation
Method Signature | Description |
---|---|
handleClick() => void | Handles the logic for the "click" event. |
isActive() => boolean | Returns whether the tab is active. |
setFocusOnActivate(focusOnActivate: boolean) => void | Sets whether the tab should focus itself when activated. |
activate(previousIndicatorClientRect?: ClientRect) => void | Activates the tab. previousIndicatorClientRect is an optional argument. |
deactivate() => void | Deactivates the tab. |
computeDimensions() => MDCTabDimensions | Returns the dimensions of the tab. |
MDCTabFoundation
Event HandlersWhen wrapping the Tab component, it is necessary to register the following event handler. For an example of this, see the MDCTab
component's initialSyncWithDOM
method.
Event | Element | Foundation Handler |
---|---|---|
click | Root element | handleClick() |
14.0.0 (2022-04-27)
unset
is unsupported in IE. (f460e23)validateTooltipWithCaretDistances
method. (3e30054)theme-styles
mixin... the value being retreived from the $theme
map and css property name was swapped. The mixin would request font-size
/font-weight
/letter-spacing
from the $theme
map (which expects size
/weight
/tracking
)... so these values would always be null
. (32b3913)attachTo
. (05db65e)showTimeout
is not set (indicating that this tooltip is about to be re-shown). (6ca8b8f)minRange
param to range sliders to request a minimum gap between the two thumbs. (8fffcb5)valueToAriaValueTextFn
and valueToValueIndicatorTextFn
functions are called for. (b6510c8)PiperOrigin-RevId: 444830518
PiperOrigin-RevId: 419837612
FAQs
The Material Components for the web tab component
The npm package @material/tab receives a total of 574,904 weekly downloads. As such, @material/tab popularity was classified as popular.
We found that @material/tab demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.