mui / mui/base-ui

[tabs] `clip-path` CSS variable

Open
#3,215 1 comment 0 reactions 0 assignees View on GitHub
component: tabs type: enhancement
Dominant language
TypeScript
Stars
10.9k
Forks
543
Avg merge
1d 20h
Merged PRs (30d)
101

Description

# Feature request

## Summary

When the tab background has an inverted color, `clip-path` is used to ensure text is legible during the indicator transition without fades.

This technique is actually an alternative to the morphing indicator element, since it relies solely on `clip-path` to create the transitioning indicator.

## Examples in other libraries

https://emilkowal.ski/ui/the-magic-of-clip-path#tabs-transition

```js
useEffect(() => {
const container = containerRef.current;

if (activeTab && container) {
const activeTabElement = activeTabElementRef.current;

if (activeTabElement) {
const { offsetLeft, offsetWidth } = activeTabElement;

const clipLeft = offsetLeft;
const clipRight = offsetLeft + offsetWidth;
container.style.clipPath =
`inset(0 ${Number(100 - (clipRight / container.offsetWidth) * 100).toFixed()}% 0 ${Number((clipLeft / container.offsetWidth) * 100).toFixed()}% round 17px)`;
}
}
}, [activeTab, activeTabElementRef, containerRef]);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.