Repository navigation
fix(Tabs): update overflow when the tab container resizes #12698
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { TabsContextProvider } from './TabsContext'; | |
| import { OverflowTab, HorizontalOverflowPopperProps } from './OverflowTab'; | ||
| import { Button } from '../Button'; | ||
| import { getOUIAProps, OUIAProps, canUseDOM } from '../../helpers'; | ||
| import { getResizeObserver } from '../../helpers/resizeObserver'; | ||
| import { SSRSafeIds } from '../../helpers/SSRSafeIds/SSRSafeIds'; | ||
| import { GenerateId } from '../../helpers/GenerateId/GenerateId'; | ||
| import linkAccentLength from '@patternfly/react-tokens/dist/esm/c_tabs_link_accent_length'; | ||
|
|
@@ -217,6 +218,7 @@ class Tabs extends Component<TabsProps, TabsState> { | |
| } | ||
|
|
||
| scrollTimeout: NodeJS.Timeout = null; | ||
| observer: any = () => {}; | ||
|
|
||
| static defaultProps: PickOptional<TabsProps> = { | ||
| activeKey: 0, | ||
|
|
@@ -411,15 +413,16 @@ class Tabs extends Component<TabsProps, TabsState> { | |
| }; | ||
|
|
||
| handleResize = () => { | ||
| if (!this.tabList.current) { | ||
| return; | ||
| } | ||
| this.handleScrollButtons(); | ||
| this.setAccentStyles(); | ||
| }; | ||
|
|
||
| componentDidMount() { | ||
| if (!this.props.isVertical) { | ||
| if (canUseDOM) { | ||
| window.addEventListener('resize', this.handleResize, false); | ||
| } | ||
| this.observer = getResizeObserver(this.tabList.current, this.handleResize, true); | ||
| this.direction = getLanguageDirection(this.tabList.current); | ||
| // call the handle resize function to check if scroll buttons should be shown | ||
| this.handleScrollButtons(); | ||
|
|
@@ -429,11 +432,7 @@ class Tabs extends Component<TabsProps, TabsState> { | |
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if (!this.props.isVertical) { | ||
| if (canUseDOM) { | ||
| window.removeEventListener('resize', this.handleResize, false); | ||
| } | ||
| } | ||
| this.observer(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| clearTimeout(this.scrollTimeout); | ||
| this.leftScrollButtonRef.current?.removeEventListener('transitionend', this.hideScrollButtons); | ||
| } | ||
|
|
||
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.
Script executed:
Repository: patternfly/patternfly-react
Length of output: 9779
Script executed:
Repository: patternfly/patternfly-react
Length of output: 21092
Script executed:
Repository: patternfly/patternfly-react
Length of output: 9902
Script executed:
Repository: patternfly/patternfly-react
Length of output: 5661
Script executed:
Repository: patternfly/patternfly-react
Length of output: 3167
Recalculate the accent after the overflow count changes.
handleResizemeasures the current tab before the debouncedoverflowingTabCountupdate. That update can move the active tab from the tab list intoOverflowTab, butcomponentDidUpdatedoes not recalculate the accent whenoverflowingTabCountchanges. The new resize observer makes this path reachable when only the container resizes.Suggested fix
if (isOverflowHorizontal && currentOverflowingTabCount) { this.setState({ overflowingTabCount: currentOverflowingTabCount + overflowingTabCount }); } + if (prevState.overflowingTabCount !== overflowingTabCount) { + this.setAccentStyles(); + } +