Skip to content

Commit

Permalink
Prevent bold text in selected tab from affecting layout
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga committed Dec 10, 2024
1 parent 4ff5a73 commit 7294df5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/css/src/components/tabs/tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
.ams-tabs__button {
color: var(--ams-tabs-button-color);
cursor: var(--ams-tabs-button-cursor);
display: grid;
font-family: var(--ams-tabs-button-font-family);
font-size: var(--ams-tabs-button-font-size);
font-weight: var(--ams-tabs-button-font-weight);
Expand Down Expand Up @@ -62,3 +63,17 @@
}
}
}

.ams-tabs__button-label,
.ams-tabs__button-label-hidden {
grid-area: 1 / 1;
}

// This hidden label is used to prevent a layout shift when the mega menu is opened
// and the button text becomes bold.
.ams-tabs__button-label-hidden {
font-weight: var(--ams-tabs-button-selected-font-weight);
pointer-events: none;
user-select: none;
visibility: hidden;
}
7 changes: 6 additions & 1 deletion packages/react/src/Tabs/TabsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export const TabsButton = forwardRef(
role="tab"
tabIndex={activeTab === tab ? 0 : -1}
>
{children}
<span aria-hidden="true" className="ams-tabs__button-label-hidden">
{children}
</span>
<span aria-hidden="true" className="ams-tabs__button-label">
{children}
</span>
</button>
)
},
Expand Down

0 comments on commit 7294df5

Please sign in to comment.