Skip to content

Commit d0aafec

Browse files
committed
fix(ui-tabs): fix tabs panel layout when unmountOnExit is false
INSTUI-4994
1 parent 37120b5 commit d0aafec

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

cypress/component/Tabs.cy.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ describe('<Tabs/>', () => {
112112
cy.wrap(onChange).its('lastCall.args[1].index').should('equal', 1)
113113
})
114114

115+
it('should keep non-selected panel hidden when unmountOnExit is false', () => {
116+
cy.mount(
117+
<Tabs>
118+
<Tabs.Panel renderTitle="First Tab" unmountOnExit={false}>
119+
Tab 1 content
120+
</Tabs.Panel>
121+
<Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
122+
</Tabs>
123+
)
124+
125+
cy.get('[role="tabpanel"]').should('have.length', 2)
126+
127+
cy.get('[role="tabpanel"]').eq(0).should('not.have.css', 'display', 'none')
128+
cy.get('[role="tabpanel"]').eq(1).should('have.css', 'display', 'none')
129+
130+
cy.contains('[role="tab"]', 'Second Tab').click()
131+
cy.get('[role="tabpanel"]').eq(1).should('not.have.css', 'display', 'none')
132+
cy.get('[role="tabpanel"]').eq(0).should('have.css', 'display', 'none')
133+
})
134+
115135
it('should render a fade-out gradient when tabOverflow set to scroll and Tabs overflow', async () => {
116136
const Example = ({ width }: { width: string }) => (
117137
<div style={{ width }}>

packages/ui-tabs/src/Tabs/v2/Panel/styles.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
2828
type StyleParams = {
2929
maxHeight: TabsPanelProps['maxHeight']
3030
isSelected: TabsPanelProps['isSelected']
31-
isHidden: boolean
3231
}
3332

3433
/**
@@ -43,9 +42,11 @@ type StyleParams = {
4342
const generateStyle = (
4443
componentTheme: ReturnType<NewComponentTypes['TabsPanel']>,
4544
params: StyleParams,
46-
sharedTokens: SharedTokens
45+
sharedTokens: SharedTokens,
46+
state: { isHidden: boolean }
4747
): TabsPanelStyle => {
48-
const { maxHeight, isSelected, isHidden } = params
48+
const { maxHeight, isSelected } = params
49+
const { isHidden } = state
4950

5051
return {
5152
panel: {

0 commit comments

Comments
 (0)