Skip to content

Commit 3c3adf0

Browse files
committed
fix: Tab + button should be right next to the last tab
1 parent 3312da2 commit 3c3adf0

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

app/components/chart-selection-tabs.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Grow,
88
Popover,
99
Stack,
10+
tabClasses,
1011
Theme,
1112
Tooltip,
1213
Typography,
@@ -636,12 +637,19 @@ const useTabsInnerStyles = makeStyles<Theme>((theme) => ({
636637
},
637638
tab: {
638639
zIndex: 1,
640+
maxWidth: "auto",
639641
"&:first-child": {
642+
// We need to add a negative margin to the first tab so that its left margin
643+
// goes "under" the border of the tab list.
640644
marginLeft: -1,
641645
},
642-
"&:last-child": {
643-
marginRight: -1,
644-
},
646+
},
647+
// :last-child does not work when the tabs are not scrollable
648+
// MUI seems to add an empty element at the end, thus we cannot use :last-child
649+
lastTab: {
650+
// We need to add a negative margin to the last tab so that its right margin
651+
// goes "under" the border of the tab list.
652+
marginRight: -1,
645653
},
646654
tabList: {
647655
top: 1,
@@ -652,13 +660,18 @@ const useTabsInnerStyles = makeStyles<Theme>((theme) => ({
652660
position: "relative",
653661
"--bg": theme.palette.background.paper,
654662
"--cut-off-width": "1rem",
663+
664+
[`& .${tabClasses.root}`]: {
665+
maxWidth: "max-content",
666+
},
667+
655668
"&:before, &:after": {
656669
top: 1,
657670
content: '""',
658671
bottom: 1,
659672
position: "absolute",
660673
width: "var(--cut-off-width)",
661-
zIndex: 1,
674+
zIndex: 10,
662675
},
663676
"&:before": {
664677
borderBottom: 0,
@@ -738,7 +751,8 @@ const TabsInner = (props: TabsInnerProps) => {
738751
classes.tab,
739752
// We need to add the "selected" class ourselves since we are wrapping
740753
// the tabs by Draggable.
741-
i === activeTabIndex ? "Mui-selected" : ""
754+
i === activeTabIndex ? "Mui-selected" : "",
755+
i === data.length - 1 ? classes.lastTab : ""
742756
)}
743757
sx={{
744758
px: 0,
@@ -796,6 +810,7 @@ const TabsInner = (props: TabsInnerProps) => {
796810
label={<TabContent iconName="add" chartKey="" />}
797811
/>
798812
)}
813+
<Box flexGrow={1} />
799814
<Box gap="0.5rem" display="flex" flexShrink={0}>
800815
{isConfiguring(state) ? <SaveDraftButton chartId={chartId} /> : null}
801816
{editable &&

0 commit comments

Comments
 (0)