New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tabs] Fix RTL indicator #26470
[Tabs] Fix RTL indicator #26470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a reproduction on #26450?
able to reproduce but the fix makes the code more complicated. Not really sure if we want to fix this edge case or not given rtl is minor @oliviertassinari |
One improvement that I see is this case. I was trying to use May-28-2564.17-17-30.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost good to ship
@siriwatknp Yeah, we might not have worked on this problem, especially not now where we need to ship v5, but no big deal, it's not a big effort, half a day work, top. I think that we could even leave the issue count to grow to 1,000/3,000 while cleaning them up along the way.
Maybe it should start from the first tab? Something in this order: diff --git a/packages/material-ui/src/Tabs/Tabs.js b/packages/material-ui/src/Tabs/Tabs.js
index 68273478c1..81660ada37 100644
--- a/packages/material-ui/src/Tabs/Tabs.js
+++ b/packages/material-ui/src/Tabs/Tabs.js
@@ -310,6 +310,7 @@ const Tabs = React.forwardRef(function Tabs(inProps, ref) {
const getTabsMeta = () => {
const tabsNode = tabsRef.current;
let tabsMeta;
+ let firstTabsMeta;
if (tabsNode) {
const rect = tabsNode.getBoundingClientRect();
// create a new object with ClientRect class props + scrollLeft
@@ -327,44 +328,52 @@ const Tabs = React.forwardRef(function Tabs(inProps, ref) {
}
let tabMeta;
- if (tabsNode && value !== false) {
+ if (tabsNode) {
const children = tabListRef.current.children;
if (children.length > 0) {
- const tab = children[valueToIndex.get(value)];
- if (process.env.NODE_ENV !== 'production') {
- if (!tab) {
- console.error(
- [
- `Material-UI: The value provided to the Tabs component is invalid.`,
- `None of the Tabs' children match with \`${value}\`.`,
- valueToIndex.keys
- ? `You can provide one of the following values: ${Array.from(
- valueToIndex.keys(),
- ).join(', ')}.`
- : null,
- ].join('\n'),
- );
+ if (value !== false) {
+ const tab = children[valueToIndex.get(value)];
+ if (process.env.NODE_ENV !== 'production') {
+ if (!tab) {
+ console.error(
+ [
+ `Material-UI: The value provided to the Tabs component is invalid.`,
+ `None of the Tabs' children match with \`${value}\`.`,
+ valueToIndex.keys
+ ? `You can provide one of the following values: ${Array.from(
+ valueToIndex.keys(),
+ ).join(', ')}.`
+ : null,
+ ].join('\n'),
+ );
+ }
}
+ tabMeta = tab ? tab.getBoundingClientRect() : null;
+ } else {
+ const tab = children[0];
+ firstTabsMeta = tab ? tab.getBoundingClientRect() : null;
}
- tabMeta = tab ? tab.getBoundingClientRect() : null;
}
}
- return { tabsMeta, tabMeta };
+ console.log({ tabMeta, firstTabsMeta })
+ return { tabsMeta, tabMeta, firstTabsMeta };
};
const updateIndicatorState = useEventCallback(() => {
- const { tabsMeta, tabMeta } = getTabsMeta();
+ const { tabsMeta, tabMeta, firstTabsMeta } = getTabsMeta();
let startValue = 0;
- if (tabMeta && tabsMeta) {
+ const finalTabMeta = tabMeta || firstTabsMeta;
+
+ if (finalTabMeta && tabsMeta) {
if (vertical) {
- startValue = tabMeta.top - tabsMeta.top + tabsMeta.scrollTop;
+ startValue = finalTabMeta.top - tabsMeta.top + tabsMeta.scrollTop;
} else {
const correction = isRtl
? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth
: tabsMeta.scrollLeft;
- startValue = tabMeta.left - tabsMeta.left + correction;
+ startValue = finalTabMeta.left - tabsMeta.left + correction;
}
} |
I think it is easier to use CSS if the user want to have this behaviour. Ideally, I think it should grow from middle of the tab index that I hover on but it is an improvement that we can do later. We can go with only rtl fix in this PR. thanks for your suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
25dd9ba it works :)
I'm not sure that this demo is accessible (that we want to include it) https://deploy-preview-26470--material-ui.netlify.app/components/tabs/#hover-tabs, cc @eps1lon for a point of view.
Otherwise, it looks solid 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just some minor test changes that should be resolved even though they are minor.
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
A step forward 👍 |
closes #26450
From the open issue, rtl does not work well with the current implementation because it force css
left
so the indicator start from the left side which makes it weird.fix the logic by switching
start, end
based onisRtl
valueadd one more test to check indicator should have
{ right: ... }
css instead of{ left: ... }
for rtladd HoverTabs demo
fix scroll button does not show in some demos due to
min-width
change in [Tabs] Updatemin
&max
width and removeminWidth
media query #26458I have followed (at least) the PR section of the contributing guide.
Preview: https://deploy-preview-26470--material-ui.netlify.app/components/tabs/